Exemplo n.º 1
0
 /**
  * Add a child model
  *
  * @param  ModelInterface $child
  * @param  null|string $captureTo Optional; if specified, the "capture to" value to set on the child
  * @param  null|bool $append Optional; if specified, append to child  with the same capture
  * @return ViewModel
  */
 public function addChild(ModelInterface $child, $captureTo = null, $append = null)
 {
     $this->children[] = $child;
     if (null !== $captureTo) {
         $child->setCaptureTo($captureTo);
     }
     if (null !== $append) {
         $child->setAppend($append);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Populate the view model returned by the AcceptableViewModelSelector from the result
  *
  * If the result is a ViewModel, we "re-cast" it by copying over all
  * values/settings/etc from the original.
  *
  * If the result is an array, we pass those values as the view model variables.
  *
  * @param  array|ViewModel $result
  * @param  ViewModelInterface $viewModel
  * @param  MvcEvent $e
  */
 protected function populateViewModel($result, ViewModelInterface $viewModel, MvcEvent $e)
 {
     if ($result instanceof ViewModel) {
         // "Re-cast" content-negotiation view models to the view model type
         // selected by the AcceptableViewModelSelector
         $viewModel->setVariables($result->getVariables());
         $viewModel->setTemplate($result->getTemplate());
         $viewModel->setOptions($result->getOptions());
         $viewModel->setCaptureTo($result->captureTo());
         $viewModel->setTerminal($result->terminate());
         $viewModel->setAppend($result->isAppend());
         if ($result->hasChildren()) {
             foreach ($result->getChildren() as $child) {
                 $viewModel->addChild($child);
             }
         }
         $e->setResult($viewModel);
         return;
     }
     // At this point, the result is an array; use it to populate the view
     // model variables
     $viewModel->setVariables($result);
     $e->setResult($viewModel);
 }