コード例 #1
0
ファイル: Filesystem.php プロジェクト: Zifius/Balcon
 /**
  * Collects child blocks of the parent block
  *
  * @param BlocksCollection $collection
  * @param $path
  * @param Block|null $parent
  */
 protected function collectBlocks(BlocksCollection $collection, $path, Block $parent = null)
 {
     $pageContents = new \DirectoryIterator($path);
     $block = new Block();
     $block->setParent($parent);
     $block->setChildren(new BlocksCollection());
     $block->setPath($path);
     foreach ($pageContents as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         if ($fileInfo->isDir()) {
             $this->collectBlocks($block->getChildren(), $fileInfo->getPath() . '/' . $fileInfo->getFilename(), $block);
         }
         if ($fileInfo->getExtension() == 'md') {
             // TODO: check if all names will be compatible with URLs
             $filename = $fileInfo->getFilename();
             $parentDirName = basename(dirname($path . '/' . $filename));
             $block->setFilename($filename);
             /* Extract lead sort order order numbers from the directories names */
             $blockNameParts = explode('.', $parentDirName, 2);
             $blockName = count($blockNameParts) > 1 ? $blockNameParts[1] : $blockNameParts[0];
             $block->setName($blockName);
         }
     }
     $collection->addBlock($block);
 }