Skip to content

Commit

Permalink
Fetch pages one time if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
BafS committed Mar 10, 2016
1 parent fc53d53 commit d21d18b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Parvula/Core/Model/Mapper/PagesFlatFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PagesFlatFiles extends Pages
*/
private $folderDefaultFile = '/index';

private $arePagesFetched = false;

/**
* Constructor
*
Expand All @@ -41,7 +43,7 @@ function __construct(PageRendererInterface $pageRenderer, $folder, $fileExtensio

$this->folder = $folder;
$this->fileExtension = '.' . ltrim($fileExtension, '.');
$this->fetchPages();
$this->arePagesFetched = false;
}

/**
Expand All @@ -53,6 +55,7 @@ function __construct(PageRendererInterface $pageRenderer, $folder, $fileExtensio
* @return Page|bool Return the selected page if exists, false if not
*/
public function read($pageUID, $parse = true, $eval = false) {
$this->fetchPages();
$pageUID = trim($pageUID, '/');

// If page was already loaded, return page
Expand Down Expand Up @@ -328,6 +331,11 @@ public function all($path = '') {
* @return array Array of all Page
*/
private function fetchPages() {
if ($this->arePagesFetched) {
return;
}

$this->arePagesFetched = true;
$_pages = [];
$_pagesChildren = [];

Expand Down

0 comments on commit d21d18b

Please sign in to comment.