Todaymade\Daux\Tree\Directory::getFirstPage PHP Метод

getFirstPage() публичный Метод

public getFirstPage ( ) : Todaymade\Daux\Tree\Content | null
Результат Todaymade\Daux\Tree\Content | null
    public function getFirstPage()
    {
        if ($this->first_page) {
            return $this->first_page;
        }
        // First we try to find a real page
        foreach ($this->getEntries() as $node) {
            if ($node instanceof Content) {
                if ($this instanceof Root && $this->getIndexPage() == $node) {
                    // The homepage should not count as first page
                    continue;
                }
                $this->setFirstPage($node);
                return $node;
            }
        }
        // If we can't find one we check in the sub-directories
        foreach ($this->getEntries() as $node) {
            if ($node instanceof self && ($page = $node->getFirstPage())) {
                $this->setFirstPage($page);
                return $page;
            }
        }
        return null;
    }

Usage Example

Пример #1
0
 /**
  * Recursively generate the documentation
  *
  * @param Directory $tree
  * @param string $output_dir
  * @param \Todaymade\Daux\Config $params
  * @param OutputInterface $output
  * @param int $width
  * @param bool $index_pages
  * @param string $base_url
  * @throws \Exception
  */
 private function generateRecursive(Directory $tree, $output_dir, $params, $output, $width, $index_pages, $base_url = '')
 {
     DauxHelper::rebaseConfiguration($params, $base_url);
     if ($base_url !== '' && empty($params['entry_page'])) {
         $params['entry_page'] = $tree->getFirstPage();
     }
     foreach ($tree->getEntries() as $key => $node) {
         if ($node instanceof Directory) {
             $new_output_dir = $output_dir . DIRECTORY_SEPARATOR . $key;
             mkdir($new_output_dir);
             $this->generateRecursive($node, $new_output_dir, $params, $output, $width, $index_pages, '../' . $base_url);
             // Rebase configuration again as $params is a shared object
             DauxHelper::rebaseConfiguration($params, $base_url);
         } else {
             $this->runAction('- ' . $node->getUrl(), $output, $width, function () use($node, $output_dir, $key, $params, $index_pages) {
                 if ($node instanceof Raw) {
                     copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key);
                     return;
                 }
                 $generated = $this->generateOne($node, $params);
                 file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent());
                 if ($index_pages) {
                     $this->indexed_pages[] = ['title' => $node->getTitle(), 'text' => utf8_encode($this->strip_html_tags($generated->getPureContent())), 'tags' => '', 'url' => $node->getUrl()];
                 }
             });
         }
     }
 }
All Usage Examples Of Todaymade\Daux\Tree\Directory::getFirstPage