summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/web/src/Compat/ViewRenderer.php
blob: 48ddcc37e25b2782c6af103877e8b117d536b5f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

namespace ipl\Web\Compat;

use Zend_Controller_Action_Helper_ViewRenderer as Zf1ViewRenderer;
use Zend_Controller_Action_HelperBroker as Zf1HelperBroker;

class ViewRenderer extends Zf1ViewRenderer
{
    /**
     * Inject the view renderer
     */
    public static function inject()
    {
        /** @var \Zend_Controller_Action_Helper_ViewRenderer $viewRenderer */
        $viewRenderer = Zf1HelperBroker::getStaticHelper('ViewRenderer');

        $inject = new static();

        foreach (get_object_vars($viewRenderer) as $property => $value) {
            if ($property === '_inflector') {
                continue;
            }

            $inject->$property = $value;
        }

        Zf1HelperBroker::removeHelper('ViewRenderer');
        Zf1HelperBroker::addHelper($inject);
    }

    public function getName()
    {
        return 'ViewRenderer';
    }

    /**
     * Render the view w/o using a view script
     *
     * {@inheritdoc}
     */
    public function render($action = null, $name = null, $noController = null)
    {
        $view = $this->view;

        if ($view->document->isEmpty() || $this->getRequest()->getParam('error_handler') !== null) {
            parent::render($action, $name, $noController);

            return;
        }

        if ($name === null) {
            $name = $this->getResponseSegment();
        }

        $this->getResponse()->appendBody($view->document->render(), $name);

        $this->setNoRender();
    }
}