예제 #1
0
파일: Engine.php 프로젝트: fixin/fixin
 /**
  * Render children
  *
  * @return array
  */
 protected function renderChildren(ViewInterface $view) : array
 {
     $data = [];
     $dataByObject = new \SplObjectStorage();
     foreach ($view->getChildren() as $name => $child) {
         $data[$name] = $dataByObject[$child] ?? ($dataByObject[$child] = $child->render());
     }
     // Test name collision
     $variables = $view->getVariables();
     if ($names = array_intersect_key($data, $variables)) {
         throw new KeyCollisionException(sprintf(static::EXCEPTION_NAME_COLLISION, implode("', '", array_keys($names))));
     }
     return $data;
 }
예제 #2
0
파일: PhpEngine.php 프로젝트: fixin/fixin
 /**
  * {@inheritDoc}
  * @see \Fixin\View\Engine\EngineInterface::render($view)
  */
 public function render(ViewInterface $view)
 {
     // Template
     $filename = $view->getResolvedTemplate();
     if (is_null($filename)) {
         return static::NO_TEMPLATE;
     }
     // Data
     $data = $this->renderChildren($view) + $view->getVariables();
     // Include
     try {
         ob_start();
         EncapsulatedInclude::include(clone $this->assistant, $filename, $data);
     } catch (\Throwable $t) {
         ob_end_clean();
         throw $t;
     }
     return ob_get_clean();
 }