public function getPagesForPath($path, $uriBase = '')
    {
        $pages = [];
        $pagesSortingMap = [];
        $pagesIdentifierMap = [];
        if (!file_exists($path)) {
            throw new \InvalidArgumentException("Page path '$path' does not exist");
        }
        if (!is_readable($path)) {
            throw new \InvalidArgumentException("Page path '$path' is not readable");
        }
        if ($handle = opendir($path)) {

            $dataSuffix = '.' . ConfigurationManager::getConfiguration()->get('dataSuffix');
            $dataSuffixLength = strlen($dataSuffix);

            while (false !== ($file = readdir($handle))) {
                // Skip the current file if the first character is a dot
                if ($file[0] === '.') {
                    continue;
                }

                // Skip hidden pages
                if ($file[0] === '_') {
                    continue;
                }


                $isFolder = strpos($file, '.') === false;
                $isPage = substr($file, -$dataSuffixLength) === $dataSuffix;
                $isConfig = substr($file, -5) === '.json';

                if (!($isFolder || $isPage || $isConfig)) {
                    continue;
                }

                $relativePageIdentifier = str_replace(
                    ' ',
                    Page::URI_WHITESPACE_REPLACE,
                    substr($file, 0, strrpos($file, '.'))
                );
                $pageIdentifier = ($uriBase ? $uriBase . '/' : '') . ($relativePageIdentifier ? $relativePageIdentifier : $file);

                /** @var Page $page */
                $page = $this->findByIdentifier($pageIdentifier);
                $page->setIsDirectory($isFolder);
                $sorting = $page->getSorting();
                $sortingDescriptor = sprintf('%05d-%s', $sorting, $pageIdentifier);

                /*
                 * Build the page data merged with previous definitions
                 * Page definition is more important than the Directory definition
                 */
                $pageData = array_merge(
                    (isset($pagesIdentifierMap[$pageIdentifier]) ? $pagesIdentifierMap[$pageIdentifier] : []),
                    [
                        'id'                 => $pageIdentifier,
                        'page'               => $page,
                        'sorting'            => $sorting,
                        'sorting_descriptor' => $sortingDescriptor,
                    ]
                );

                /*
                 * If the current page is a folder get the children
                 */
                if ($isFolder) {
                    $pageData['children'] = $this->getPagesForPath(
                        $path . $file . DIRECTORY_SEPARATOR,
                        $pageIdentifier
                    );
                }

                $pagesSortingMap[$sortingDescriptor] = $pageData;
                $pagesIdentifierMap[$pageIdentifier] = $pageData;
            }
            closedir($handle);
        }

        // Add the page to the list pages
        ksort($pagesSortingMap, SORT_NUMERIC);

        $tempPages = [];
        foreach ($pagesSortingMap as $pageWithSorting) {
            $tempPages[$pageWithSorting['id']] = $pageWithSorting['page'];
        }

        $this->allPages = array_merge($this->allPages, $tempPages);

        ksort($pages, SORT_NUMERIC);

        return $pagesSortingMap;
    }
public function getPagesForPath($path, $uriBase = '')
    {
        $pages = [];
        $pagesSortingMap = [];
        $pagesIdentifierMap = [];
        if (!file_exists($path)) {
            throw new \InvalidArgumentException("Page path '$path' does not exist");
        }
        if (!is_readable($path)) {
            throw new \InvalidArgumentException("Page path '$path' is not readable");
        }
        if ($handle = opendir($path)) {

            $dataSuffix = '.' . ConfigurationManager::getConfiguration()->get('dataSuffix');
            $dataSuffixLength = strlen($dataSuffix);

            while (false !== ($file = readdir($handle))) {
                // Skip the current file if the first character is a dot
                if ($file[0] === '.') {
                    continue;
                }

                // Skip hidden pages
                if ($file[0] === '_') {
                    continue;
                }


                $isFolder = strpos($file, '.') === false;
                $isPage = substr($file, -$dataSuffixLength) === $dataSuffix;
                $isConfig = substr($file, -5) === '.json';

                if (!($isFolder || $isPage || $isConfig)) {
                    continue;
                }

                $relativePageIdentifier = str_replace(
                    ' ',
                    Page::URI_WHITESPACE_REPLACE,
                    substr($file, 0, strrpos($file, '.'))
                );
                $pageIdentifier = ($uriBase ? $uriBase . '/' : '') . ($relativePageIdentifier ? $relativePageIdentifier : $file);

                /** @var Page $page */
                $page = $this->findByIdentifier($pageIdentifier);
                $page->setIsDirectory($isFolder);
                $sorting = $page->getSorting();
                $sortingDescriptor = sprintf('%05d-%s', $sorting, $pageIdentifier);

                /*
                 * Build the page data merged with previous definitions
                 * Page definition is more important than the Directory definition
                 */
                $pageData = array_merge(
                    (isset($pagesIdentifierMap[$pageIdentifier]) ? $pagesIdentifierMap[$pageIdentifier] : []),
                    [
                        'id'                 => $pageIdentifier,
                        'page'               => $page,
                        'sorting'            => $sorting,
                        'sorting_descriptor' => $sortingDescriptor,
                    ]
                );

                /*
                 * If the current page is a folder get the children
                 */
                if ($isFolder) {
                    $pageData['children'] = $this->getPagesForPath(
                        $path . $file . DIRECTORY_SEPARATOR,
                        $pageIdentifier
                    );
                }

                $pagesSortingMap[$sortingDescriptor] = $pageData;
                $pagesIdentifierMap[$pageIdentifier] = $pageData;
            }
            closedir($handle);
        }

        // Add the page to the list pages
        ksort($pagesSortingMap, SORT_NUMERIC);

        $tempPages = [];
        foreach ($pagesSortingMap as $pageWithSorting) {
            $tempPages[$pageWithSorting['id']] = $pageWithSorting['page'];
        }

        $this->allPages = array_merge($this->allPages, $tempPages);

        ksort($pages, SORT_NUMERIC);

        return $pagesSortingMap;
    }
public function getPagesForPath ( $ path , $ uriBase = '' ) { $ pages = [ ] ; $ pagesSortingMap = [ ] ; $ pagesIdentifierMap = [ ] ; if ( ! file_exists ( $ path ) ) { throw new \ InvalidArgumentException ( "Page path '$path' does not exist" ) ; } if ( ! is_readable ( $ path ) ) { throw new \ InvalidArgumentException ( "Page path '$path' is not readable" ) ; } if ( $ handle = opendir ( $ path ) ) { $ dataSuffix = '.' . ConfigurationManager :: getConfiguration ( ) -> get ( 'dataSuffix' ) ; $ dataSuffixLength = strlen ( $ dataSuffix ) ; while ( false !== ( $ file = readdir ( $ handle ) ) ) { // Skip the current file if the first character is a dot if ( $ file [ 0 ] === '.' ) { continue ; } // Skip hidden pages if ( $ file [ 0 ] === '_' ) { continue ; } $ isFolder = strpos ( $ file , '.' ) === false ; $ isPage = substr ( $ file , - $ dataSuffixLength ) === $ dataSuffix ; $ isConfig = substr ( $ file , - 5 ) === '.json' ; if ( ! ( $ isFolder || $ isPage || $ isConfig ) ) { continue ; } $ relativePageIdentifier = str_replace ( ' ' , Page :: URI_WHITESPACE_REPLACE , substr ( $ file , 0 , strrpos ( $ file , '.' ) ) ) ; $ pageIdentifier = ( $ uriBase ? $ uriBase . '/' : '' ) . ( $ relativePageIdentifier ? $ relativePageIdentifier : $ file ) ; /** @var Page $page */ $ page = $ this -> findByIdentifier ( $ pageIdentifier ) ; $ page -> setIsDirectory ( $ isFolder ) ; $ sorting = $ page -> getSorting ( ) ; $ sortingDescriptor = sprintf ( '%05d-%s' , $ sorting , $ pageIdentifier ) ; /*
                 * Build the page data merged with previous definitions
                 * Page definition is more important than the Directory definition
                 */ $ pageData = array_merge ( ( isset ( $ pagesIdentifierMap [ $ pageIdentifier ] ) ? $ pagesIdentifierMap [ $ pageIdentifier ] : [ ] ) , [ 'id' => $ pageIdentifier , 'page' => $ page , 'sorting' => $ sorting , 'sorting_descriptor' => $ sortingDescriptor , ] ) ; /*
                 * If the current page is a folder get the children
                 */ if ( $ isFolder ) { $ pageData [ 'children' ] = $ this -> getPagesForPath ( $ path . $ file . DIRECTORY_SEPARATOR , $ pageIdentifier ) ; } $ pagesSortingMap [ $ sortingDescriptor ] = $ pageData ; $ pagesIdentifierMap [ $ pageIdentifier ] = $ pageData ; } closedir ( $ handle ) ; } // Add the page to the list pages ksort ( $ pagesSortingMap , SORT_NUMERIC ) ; $ tempPages = [ ] ; foreach ( $ pagesSortingMap as $ pageWithSorting ) { $ tempPages [ $ pageWithSorting [ 'id' ] ] = $ pageWithSorting [ 'page' ] ; } $ this -> allPages = array_merge ( $ this -> allPages , $ tempPages ) ; ksort ( $ pages , SORT_NUMERIC ) ; return $ pagesSortingMap ; }
Returns all available pages for the given path

@param string $path
@param string $uriBase
@return array
Returns all available pages for the given path