3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\View\Renderer
;
12 use Zend\Filter\FilterChain
;
13 use Zend\View\Model\ModelInterface
;
14 use Zend\View\Resolver\ResolverInterface
;
17 * Abstract class for Zend_View to help enforce private constructs.
19 * Note: all private variables in this class are prefixed with "__". This is to
20 * mark them as part of the internal implementation, and thus prevent conflict
21 * with variables injected into the renderer.
23 class ConsoleRenderer
implements RendererInterface
, TreeRendererInterface
28 protected $__filterChain;
34 * @todo handle passing helper manager, options
35 * @todo handle passing filter chain, options
36 * @todo handle passing variables object, options
37 * @todo handle passing resolver object, options
38 * @param array $config Configuration key-value pairs.
40 public function __construct($config = array())
45 public function setResolver(ResolverInterface
$resolver)
51 * Return the template engine object
53 * Returns the object instance, as it is its own template engine
57 public function getEngine()
63 * Allow custom object initialization when extending Zend_View_Abstract or
66 * Triggered by {@link __construct() the constructor} as its final action.
70 public function init()
77 * @param FilterChain $filters
78 * @return ConsoleRenderer
80 public function setFilterChain(FilterChain
$filters)
82 $this->__filterChain
= $filters;
87 * Retrieve filter chain for post-filtering script content
91 public function getFilterChain()
93 if (null === $this->__filterChain
) {
94 $this->setFilterChain(new FilterChain());
96 return $this->__filterChain
;
100 * Recursively processes all ViewModels and returns output.
102 * @param string|ModelInterface $model A ViewModel instance.
103 * @param null|array|\Traversable $values Values to use when rendering. If none
104 * provided, uses those in the composed
105 * variables container.
106 * @return string Console output.
108 public function render($model, $values = null)
110 if (!$model instanceof ModelInterface
) {
115 $options = $model->getOptions();
116 foreach ($options as $setting => $value) {
117 $method = 'set' . $setting;
118 if (method_exists($this, $method)) {
119 $this->$method($value);
121 unset($method, $setting, $value);
125 $values = $model->getVariables();
127 if (isset($values['result'])) {
128 // filter and append the result
129 $result .= $this->getFilterChain()->filter($values['result']);
132 if ($model->hasChildren()) {
133 // recursively render all children
134 foreach ($model->getChildren() as $child) {
135 $result .= $this->render($child, $values);
143 * @see Zend\View\Renderer\TreeRendererInterface
146 public function canRenderTrees()