/**
  * @param ModelInterface $viewModel
  * @param callable $addToViewFromModel
  */
 protected function addChildrenToView(ModelInterface $viewModel, $addToViewFromModel)
 {
     if ($viewModel->hasChildren()) {
         foreach ($viewModel->getChildren() as $child) {
             $addToViewFromModel($child);
             $this->addChildrenToView($child, $addToViewFromModel);
         }
     }
 }
Пример #2
0
 /**
  *
  * @param ModelInterface $model
  */
 protected function renderChildren(ModelInterface $model)
 {
     foreach ($model->getChildren() as $child) {
         $result = $this->render($child);
         $capture = $child->captureTo();
         if (!empty($capture)) {
             if ($child->isAppend()) {
                 $oldResult = $model->{$capture};
                 $model->setVariable($capture, $oldResult . $result);
             } else {
                 $model->setVariable($capture, $result);
             }
         }
     }
 }
Пример #3
0
 /**
  * @inheritDoc
  */
 public function add($blockId, ModelInterface $block)
 {
     $block->setOption('block_id', $blockId);
     if ($block->hasChildren()) {
         foreach ($block->getChildren() as $childBlock) {
             $childBlockId = $this->determineAnonymousBlockId($childBlock);
             $childBlock->setCaptureTo($blockId . LayoutInterface::CAPTURE_TO_DELIMITER . $childBlock->captureTo());
             $this->add($childBlockId, $childBlock);
         }
         if ($block instanceof ClearableModelInterface) {
             $block->clearChildren();
         }
     }
     $this->blocks[$blockId] = $block;
     return $this;
 }
 /**
  * Recursively search a view model and it's children for the given templateName
  *
  * @param  \Zend\View\Model\ModelInterface $viewModel
  * @param  string    $templateName
  * @return boolean
  */
 protected function searchTemplates($viewModel, $templateName)
 {
     if ($viewModel->getTemplate($templateName) == $templateName) {
         return true;
     }
     foreach ($viewModel->getChildren() as $child) {
         return $this->searchTemplates($child, $templateName);
     }
     return false;
 }
Пример #5
0
 /**
  * Recursively processes all ViewModels and returns output.
  *
  * @param  string|ModelInterface   $model        A ViewModel instance.
  * @param  null|array|\Traversable $values       Values to use when rendering. If none
  *                                               provided, uses those in the composed
  *                                               variables container.
  * @return string Console output.
  */
 public function render($model, $values = null)
 {
     if (!$model instanceof ModelInterface) {
         return '';
     }
     $result = '';
     $options = $model->getOptions();
     foreach ($options as $setting => $value) {
         $method = 'set' . $setting;
         if (method_exists($this, $method)) {
             $this->{$method}($value);
         }
         unset($method, $setting, $value);
     }
     unset($options);
     $values = $model->getVariables();
     if (isset($values['result'])) {
         // filter and append the result
         $result .= $this->getFilterChain()->filter($values['result']);
     }
     if ($model->hasChildren()) {
         // recursively render all children
         foreach ($model->getChildren() as $child) {
             $result .= $this->render($child, $values);
         }
     }
     return $result;
 }
Пример #6
0
 /**
  * Recursively processes all ViewModels and returns output.
  *
  * @param string|ModelInterface $model A ViewModel instance.
  * @param null|array|\Traversable $values Values to use when rendering. If
  *     none provided, uses those in the composed variables container.
  * @return string Console output.
  */
 public function render($model, $values = null)
 {
     $result = '';
     if (!$model instanceof ModelInterface) {
         // View model is required by this renderer
         return $result;
     }
     // If option keys match setters, pass values to those methods.
     foreach ($model->getOptions() as $setting => $value) {
         $method = 'set' . $setting;
         if (method_exists($this, $method)) {
             $this->{$method}($value);
         }
     }
     // Render children first
     if ($model->hasChildren()) {
         // recursively render all children
         foreach ($model->getChildren() as $child) {
             $result .= $this->render($child, $values);
         }
     }
     // Render the result, if present.
     $values = $model->getVariables();
     if (isset($values['result']) && !isset($this->filterChain)) {
         // append the result verbatim
         $result .= $values['result'];
     }
     if (isset($values['result']) && isset($this->filterChain)) {
         // filter and append the result
         $result .= $this->getFilterChain()->filter($values['result']);
     }
     return $result;
 }