Esempio n. 1
0
 /**
  * Recursively processes all ViewModels and returns output.
  *
  * @param  string|Model            $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 Model) {
         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;
 }