1 | <?php |
||
16 | class TwigViewEncoder extends AbstractEncoder |
||
17 | { |
||
18 | |||
19 | // the template to encode |
||
20 | private $template; |
||
21 | |||
22 | // the twig view environment |
||
23 | private $viewEnvironment; |
||
24 | |||
25 | /** |
||
26 | * Constructor for the encoder. |
||
27 | * @param array $viewConfig The view configuration. |
||
28 | * @param string $template The name of the default template to render |
||
29 | */ |
||
30 | 8 | public function __construct($viewConfig, $template) |
|
31 | { |
||
32 | 8 | if (!isset($viewConfig[ControllerHandler::KEY_VIEWS_PATH])) { |
|
33 | 1 | throw new InternalErrorException( |
|
34 | 1 | 'View environment missing views path.' |
|
35 | ); |
||
36 | } |
||
37 | 7 | $loader = new Twig_Loader_Filesystem( |
|
38 | 7 | $viewConfig[ControllerHandler::KEY_VIEWS_PATH] |
|
39 | ); |
||
40 | 7 | $this->viewEnvironment = new Twig_Environment($loader, $viewConfig); |
|
41 | 7 | $this->template = $template; |
|
42 | 7 | } |
|
43 | |||
44 | /** |
||
45 | * Returns the Twig view environment. |
||
46 | * @return Twig_Environment The configured twig environment. |
||
47 | */ |
||
48 | 1 | public function getViewEnvironment() |
|
52 | |||
53 | /** |
||
54 | * @param AbstractResponse $response The response to be encoded. |
||
55 | * @return string Returns the response encoded as a string. |
||
56 | */ |
||
57 | 6 | public function encode(AbstractResponse $response) |
|
70 | |||
71 | /** |
||
72 | * Renders an abitrary view with arbitrary parameters. |
||
73 | * @param string $template The template to render. |
||
74 | * @param array $variables The variables to use. |
||
75 | * @return string Returns the rendered template as a string. |
||
76 | */ |
||
77 | 1 | public function renderView($template, $variables) |
|
85 | } |
||
86 |