Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * {@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();
 }