/** * Generates file for the result view * * @param Block $block * @return string * @throws \Exception */ protected function generateResultViewFile(Block $block) { $filePath = $this->getGeneratedViewsDir() . $block->getRoute() . '.blade.php'; $fileDirPath = dirname($filePath); // Create directory if it does not exist if (!is_dir($fileDirPath)) { mkdir($fileDirPath, 0755, true); } try { $fileHandle = fopen($filePath, 'w+'); fwrite($fileHandle, $this->content); fclose($fileHandle); return $filePath; } catch (\Exception $e) { throw new \Exception(sprintf('Cannot create view file. Make sure %s dir is writable', $this->getGeneratedViewsDir())); } }
/** * Goes recursively trough blocks and attempts to dispatch * the specified route * * @param \Plugins\Cms\Model\Block $block * @param string $route * @return bool */ protected function routeDispatch(Block $block, $route) { if (!$this->getDispatchedBlock()) { if ($block->getRoute() == $route) { // TODO: check if block is routable $this->setDispatchedBlock($block); $this->isProcessed = true; return true; } elseif (count($block->getChildren()->getBlocks()) > 0) { // Go trough child blocks /** @var Block $childBlock */ foreach ($block->getChildren()->getBlocks() as $childBlock) { $this->routeDispatch($childBlock, $route); if ($this->getDispatchedBlock()) { break; } } } } return true; }
public function getPostInfo(Block $post) { $customPostParameters = $post->getParams(); return ['author' => '', 'date' => '', 'title' => $customPostParameters['title'], 'url' => $post->getRoute()]; }