@@ -14,126 +14,126 @@ |
||
| 14 | 14 | class TwigRenderer extends AbstractRenderer |
| 15 | 15 | { |
| 16 | 16 | protected $loader; |
| 17 | - protected $environment; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * __construct function. |
|
| 21 | - * |
|
| 22 | - * @access public |
|
| 23 | - * @param mixed $path |
|
| 24 | - * @param array $options (default: []) |
|
| 25 | - */ |
|
| 26 | - public function __construct($path, array $options = []) |
|
| 27 | - { |
|
| 17 | + protected $environment; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * __construct function. |
|
| 21 | + * |
|
| 22 | + * @access public |
|
| 23 | + * @param mixed $path |
|
| 24 | + * @param array $options (default: []) |
|
| 25 | + */ |
|
| 26 | + public function __construct($path, array $options = []) |
|
| 27 | + { |
|
| 28 | 28 | $this->loader = $this->createLoader(is_array($path) ? $path : [$path]); |
| 29 | 29 | $this->environment = new \Twig_Environment($this->loader, $options); |
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * addExtension function. |
|
| 34 | - * |
|
| 35 | - * @access public |
|
| 36 | - * @param \Twig_ExtensionInterface $extension |
|
| 37 | - * @return $this |
|
| 38 | - */ |
|
| 39 | - public function addExtension(\Twig_ExtensionInterface $extension) |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * addExtension function. |
|
| 34 | + * |
|
| 35 | + * @access public |
|
| 36 | + * @param \Twig_ExtensionInterface $extension |
|
| 37 | + * @return $this |
|
| 38 | + */ |
|
| 39 | + public function addExtension(\Twig_ExtensionInterface $extension) |
|
| 40 | 40 | { |
| 41 | 41 | $this->environment->addExtension($extension); |
| 42 | 42 | |
| 43 | - return $this; |
|
| 43 | + return $this; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * addFilter function. |
|
| 48 | - * |
|
| 49 | - * @access public |
|
| 50 | - * @param \Twig_Filter $filter |
|
| 51 | - * @return $this |
|
| 52 | - */ |
|
| 53 | - public function addFilter(\Twig_Filter $filter) |
|
| 46 | + /** |
|
| 47 | + * addFilter function. |
|
| 48 | + * |
|
| 49 | + * @access public |
|
| 50 | + * @param \Twig_Filter $filter |
|
| 51 | + * @return $this |
|
| 52 | + */ |
|
| 53 | + public function addFilter(\Twig_Filter $filter) |
|
| 54 | 54 | { |
| 55 | 55 | $this->environment->addFilter($filter); |
| 56 | 56 | |
| 57 | - return $this; |
|
| 57 | + return $this; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - /** |
|
| 60 | + /** |
|
| 61 | 61 | * {@inheritdoc} |
| 62 | 62 | */ |
| 63 | - protected function template($template) |
|
| 64 | - { |
|
| 65 | - return $this->environment->load($template); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Twig renderBlock function. |
|
| 70 | - * |
|
| 71 | - * @access public |
|
| 72 | - * @param mixed $template |
|
| 73 | - * @param mixed $block_name |
|
| 74 | - * @param mixed $data (default: []) |
|
| 75 | - * @return string rendered block |
|
| 76 | - */ |
|
| 77 | - public function renderBlock($template, $block_name, $data = []) |
|
| 78 | - { |
|
| 79 | - return $this->template($template)->renderBlock($block_name, $this->merge_data($data)); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 63 | + protected function template($template) |
|
| 64 | + { |
|
| 65 | + return $this->environment->load($template); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Twig renderBlock function. |
|
| 70 | + * |
|
| 71 | + * @access public |
|
| 72 | + * @param mixed $template |
|
| 73 | + * @param mixed $block_name |
|
| 74 | + * @param mixed $data (default: []) |
|
| 75 | + * @return string rendered block |
|
| 76 | + */ |
|
| 77 | + public function renderBlock($template, $block_name, $data = []) |
|
| 78 | + { |
|
| 79 | + return $this->template($template)->renderBlock($block_name, $this->merge_data($data)); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | 83 | * {@inheritdoc} |
| 84 | 84 | */ |
| 85 | - public function render(ResponseInterface $response, $template, $data = []) |
|
| 86 | - { |
|
| 87 | - $response->getBody()->write($this->template($template)->render($this->merge_data($data))); |
|
| 85 | + public function render(ResponseInterface $response, $template, $data = []) |
|
| 86 | + { |
|
| 87 | + $response->getBody()->write($this->template($template)->render($this->merge_data($data))); |
|
| 88 | 88 | |
| 89 | 89 | return $response; |
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * getLoader function. |
|
| 94 | - * |
|
| 95 | - * @access public |
|
| 96 | - * @return Twig_Loader_Filesystem |
|
| 97 | - */ |
|
| 98 | - public function getLoader() |
|
| 99 | - { |
|
| 100 | - return $this->loader; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * getEnvironment function. |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @return Twig_Environment |
|
| 108 | - */ |
|
| 109 | - public function getEnvironment() |
|
| 110 | - { |
|
| 111 | - return $this->environment; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * createLoader function. |
|
| 116 | - * |
|
| 117 | - * @access protected |
|
| 118 | - * @param array $paths |
|
| 119 | - * @return Twig_Loader_Filesystem |
|
| 120 | - */ |
|
| 121 | - protected function createLoader(array $paths) |
|
| 122 | - { |
|
| 123 | - $loader = new \Twig_Loader_Filesystem(); |
|
| 124 | - |
|
| 125 | - foreach ($paths as $namespace => $path) |
|
| 126 | - { |
|
| 127 | - if (is_string($namespace)) |
|
| 128 | - { |
|
| 129 | - $loader->setPaths($path, $namespace); |
|
| 130 | - continue; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $loader->addPath($path); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $loader; |
|
| 137 | - } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * getLoader function. |
|
| 94 | + * |
|
| 95 | + * @access public |
|
| 96 | + * @return Twig_Loader_Filesystem |
|
| 97 | + */ |
|
| 98 | + public function getLoader() |
|
| 99 | + { |
|
| 100 | + return $this->loader; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * getEnvironment function. |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @return Twig_Environment |
|
| 108 | + */ |
|
| 109 | + public function getEnvironment() |
|
| 110 | + { |
|
| 111 | + return $this->environment; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * createLoader function. |
|
| 116 | + * |
|
| 117 | + * @access protected |
|
| 118 | + * @param array $paths |
|
| 119 | + * @return Twig_Loader_Filesystem |
|
| 120 | + */ |
|
| 121 | + protected function createLoader(array $paths) |
|
| 122 | + { |
|
| 123 | + $loader = new \Twig_Loader_Filesystem(); |
|
| 124 | + |
|
| 125 | + foreach ($paths as $namespace => $path) |
|
| 126 | + { |
|
| 127 | + if (is_string($namespace)) |
|
| 128 | + { |
|
| 129 | + $loader->setPaths($path, $namespace); |
|
| 130 | + continue; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $loader->addPath($path); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $loader; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return $this |
| 38 | 38 | */ |
| 39 | 39 | public function addExtension(\Twig_ExtensionInterface $extension) |
| 40 | - { |
|
| 40 | + { |
|
| 41 | 41 | $this->environment->addExtension($extension); |
| 42 | 42 | |
| 43 | 43 | return $this; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return $this |
| 52 | 52 | */ |
| 53 | 53 | public function addFilter(\Twig_Filter $filter) |
| 54 | - { |
|
| 54 | + { |
|
| 55 | 55 | $this->environment->addFilter($filter); |
| 56 | 56 | |
| 57 | 57 | return $this; |
@@ -12,28 +12,28 @@ discard block |
||
| 12 | 12 | abstract class AbstractRenderer implements \ArrayAccess |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - protected $offset = []; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * template function. |
|
| 19 | - * |
|
| 20 | - * @access protected |
|
| 21 | - * @abstract |
|
| 22 | - * @param mixed $template |
|
| 23 | - */ |
|
| 24 | - abstract protected function template($template); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * render function. |
|
| 28 | - * |
|
| 29 | - * @access public |
|
| 30 | - * @abstract |
|
| 31 | - * @param ResponseInterface $response |
|
| 32 | - * @param mixed $template |
|
| 33 | - * @param mixed $data (default: []) |
|
| 34 | - * @return ResponseInterface |
|
| 35 | - */ |
|
| 36 | - abstract public function render(ResponseInterface $response, $template, $data = []); |
|
| 15 | + protected $offset = []; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * template function. |
|
| 19 | + * |
|
| 20 | + * @access protected |
|
| 21 | + * @abstract |
|
| 22 | + * @param mixed $template |
|
| 23 | + */ |
|
| 24 | + abstract protected function template($template); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * render function. |
|
| 28 | + * |
|
| 29 | + * @access public |
|
| 30 | + * @abstract |
|
| 31 | + * @param ResponseInterface $response |
|
| 32 | + * @param mixed $template |
|
| 33 | + * @param mixed $data (default: []) |
|
| 34 | + * @return ResponseInterface |
|
| 35 | + */ |
|
| 36 | + abstract public function render(ResponseInterface $response, $template, $data = []); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * merge_data function. |
@@ -43,29 +43,29 @@ discard block |
||
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | 45 | protected function merge_data($data) |
| 46 | - { |
|
| 47 | - return array_merge($this->offset, $data); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * loadConfig function. |
|
| 52 | - * |
|
| 53 | - * @access public |
|
| 54 | - * @param array $offset |
|
| 55 | - * @return $this |
|
| 56 | - */ |
|
| 57 | - public function loadConfig(array $offset) |
|
| 58 | - { |
|
| 59 | - $this->offset = $this->merge_data($offset); |
|
| 60 | - |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * ArrayAccess Implementations |
|
| 66 | - */ |
|
| 67 | - |
|
| 68 | - /** |
|
| 46 | + { |
|
| 47 | + return array_merge($this->offset, $data); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * loadConfig function. |
|
| 52 | + * |
|
| 53 | + * @access public |
|
| 54 | + * @param array $offset |
|
| 55 | + * @return $this |
|
| 56 | + */ |
|
| 57 | + public function loadConfig(array $offset) |
|
| 58 | + { |
|
| 59 | + $this->offset = $this->merge_data($offset); |
|
| 60 | + |
|
| 61 | + return $this; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * ArrayAccess Implementations |
|
| 66 | + */ |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | 69 | * {@inheritdoc} |
| 70 | 70 | */ |
| 71 | 71 | public function offsetExists($key) |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | 45 | protected function merge_data($data) |
| 46 | - { |
|
| 46 | + { |
|
| 47 | 47 | return array_merge($this->offset, $data); |
| 48 | 48 | } |
| 49 | 49 | |