Xhgui_Controller   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 4 1
A templateVars() 0 4 1
A render() 0 16 1
1
<?php
2
3
use Slim\Slim;
4
5
abstract class Xhgui_Controller
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $_templateVars = array();
11
12
    /**
13
     * @var string|null
14
     */
15
    protected $_template = null;
16
17
    /**
18
     * @var Slim
19
     */
20
    protected $app;
21
22
    public function __construct(Slim $app)
23
    {
24
        $this->app = $app;
25
    }
26
27
    public function set($vars)
28
    {
29
        $this->_templateVars = array_merge($this->_templateVars, $vars);
30
    }
31
32
    public function templateVars()
33
    {
34
        return $this->_templateVars;
35
    }
36
37
    public function render()
38
    {
39
        // We want to render the specified Twig template to the output buffer.
40
        // The simplest way to do that is Slim::render, but that is not allowed
41
        // in middleware, because it uses Slim\View::display which prints
42
        // directly to the native PHP output buffer.
43
        // Doing that is problematic, because the HTTP headers set via $app->response()
44
        // must be output first, which won't happen until after the middleware
45
        // is completed. Output of headers and body is done by the Slim::run entry point.
46
47
        // The below is copied from Slim::render (slim/[email protected]).
48
        // Modified to use View::fetch + Response::write, instead of View::display.
49
        $this->app->view->appendData($this->_templateVars);
50
        $body = $this->app->view->fetch($this->_template);
51
        $this->app->response->write($body);
52
    }
53
54
}
55