@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Configuration for the koharness module testing environment. |
|
4 | - * |
|
5 | - * @author Andrew Coulton <[email protected]> |
|
6 | - * @copyright 2013 inGenerator Ltd |
|
7 | - * @link https://github.com/ingenerator/koharness |
|
8 | - */ |
|
3 | + * Configuration for the koharness module testing environment. |
|
4 | + * |
|
5 | + * @author Andrew Coulton <[email protected]> |
|
6 | + * @copyright 2013 inGenerator Ltd |
|
7 | + * @link https://github.com/ingenerator/koharness |
|
8 | + */ |
|
9 | 9 | return array( |
10 | 10 | 'modules' => array( |
11 | - 'kohana-view' => __DIR__, |
|
11 | + 'kohana-view' => __DIR__, |
|
12 | 12 | ) |
13 | 13 | ); |
@@ -31,86 +31,86 @@ |
||
31 | 31 | class TemplateCompiler |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected $options = [ |
|
38 | - 'raw_output_prefix' => '!', |
|
39 | - 'escape_method' => 'HTML::chars', |
|
40 | - ]; |
|
34 | + /** |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected $options = [ |
|
38 | + 'raw_output_prefix' => '!', |
|
39 | + 'escape_method' => 'HTML::chars', |
|
40 | + ]; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param array $options |
|
44 | - */ |
|
45 | - public function __construct(array $options = []) |
|
46 | - { |
|
47 | - $this->options = array_merge($this->options, $options); |
|
48 | - } |
|
42 | + /** |
|
43 | + * @param array $options |
|
44 | + */ |
|
45 | + public function __construct(array $options = []) |
|
46 | + { |
|
47 | + $this->options = array_merge($this->options, $options); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Compile a string containing a PHP template, automatically escaping variables that are echoed in PHP short tags, |
|
52 | - * and return the compiled PHP string. |
|
53 | - * |
|
54 | - * @param string $source |
|
55 | - * |
|
56 | - * @return string |
|
57 | - * @throws \InvalidArgumentException if the template is empty or invalid |
|
58 | - */ |
|
59 | - public function compile($source) |
|
60 | - { |
|
61 | - if ( ! $source) { |
|
62 | - throw new \InvalidArgumentException('Cannot compile empty template'); |
|
63 | - } |
|
50 | + /** |
|
51 | + * Compile a string containing a PHP template, automatically escaping variables that are echoed in PHP short tags, |
|
52 | + * and return the compiled PHP string. |
|
53 | + * |
|
54 | + * @param string $source |
|
55 | + * |
|
56 | + * @return string |
|
57 | + * @throws \InvalidArgumentException if the template is empty or invalid |
|
58 | + */ |
|
59 | + public function compile($source) |
|
60 | + { |
|
61 | + if ( ! $source) { |
|
62 | + throw new \InvalidArgumentException('Cannot compile empty template'); |
|
63 | + } |
|
64 | 64 | |
65 | - return preg_replace_callback('/<\?=(.+?)(;|\?>)/s', [$this, 'compilePhpShortTag'], $source); |
|
66 | - } |
|
65 | + return preg_replace_callback('/<\?=(.+?)(;|\?>)/s', [$this, 'compilePhpShortTag'], $source); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string[] $matches |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - protected function compilePhpShortTag($matches) |
|
74 | - { |
|
75 | - $var = trim($matches[1]); |
|
76 | - $terminator = $matches[2]; |
|
77 | - $escape_method = $this->options['escape_method']; |
|
78 | - $raw_output_prefix = $this->options['raw_output_prefix']; |
|
68 | + /** |
|
69 | + * @param string[] $matches |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + protected function compilePhpShortTag($matches) |
|
74 | + { |
|
75 | + $var = trim($matches[1]); |
|
76 | + $terminator = $matches[2]; |
|
77 | + $escape_method = $this->options['escape_method']; |
|
78 | + $raw_output_prefix = $this->options['raw_output_prefix']; |
|
79 | 79 | |
80 | - if ($this->startsWith($var, $raw_output_prefix)) { |
|
81 | - // Remove prefix and echo unescaped |
|
82 | - $compiled = '<?='.trim(substr($var, strlen($raw_output_prefix))).';'; |
|
83 | - } elseif ($this->startsWith($var, '//')) { |
|
84 | - // Echo an empty string to prevent the comment causing a parse error |
|
85 | - $compiled = "<?='';$var;"; |
|
80 | + if ($this->startsWith($var, $raw_output_prefix)) { |
|
81 | + // Remove prefix and echo unescaped |
|
82 | + $compiled = '<?='.trim(substr($var, strlen($raw_output_prefix))).';'; |
|
83 | + } elseif ($this->startsWith($var, '//')) { |
|
84 | + // Echo an empty string to prevent the comment causing a parse error |
|
85 | + $compiled = "<?='';$var;"; |
|
86 | 86 | |
87 | - } elseif ($this->startsWith($var, $escape_method)) { |
|
88 | - // Try to help user to avoid accidental double-escaping |
|
89 | - throw new \InvalidArgumentException( |
|
90 | - "Invalid implicit double-escape in template - remove $escape_method from {$matches[0]} or mark as raw" |
|
91 | - ); |
|
87 | + } elseif ($this->startsWith($var, $escape_method)) { |
|
88 | + // Try to help user to avoid accidental double-escaping |
|
89 | + throw new \InvalidArgumentException( |
|
90 | + "Invalid implicit double-escape in template - remove $escape_method from {$matches[0]} or mark as raw" |
|
91 | + ); |
|
92 | 92 | |
93 | - } else { |
|
94 | - // Escape the value before echoing |
|
95 | - $compiled = "<?={$escape_method}($var);"; |
|
96 | - } |
|
93 | + } else { |
|
94 | + // Escape the value before echoing |
|
95 | + $compiled = "<?={$escape_method}($var);"; |
|
96 | + } |
|
97 | 97 | |
98 | - if ($terminator === '?>') { |
|
99 | - $compiled .= '?>'; |
|
100 | - } |
|
98 | + if ($terminator === '?>') { |
|
99 | + $compiled .= '?>'; |
|
100 | + } |
|
101 | 101 | |
102 | - return $compiled; |
|
103 | - } |
|
102 | + return $compiled; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @param string $string |
|
107 | - * @param string $prefix |
|
108 | - * |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - protected function startsWith($string, $prefix) |
|
112 | - { |
|
113 | - return (strncmp($string, $prefix, strlen($prefix)) === 0); |
|
114 | - } |
|
105 | + /** |
|
106 | + * @param string $string |
|
107 | + * @param string $prefix |
|
108 | + * |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + protected function startsWith($string, $prefix) |
|
112 | + { |
|
113 | + return (strncmp($string, $prefix, strlen($prefix)) === 0); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -17,11 +17,11 @@ |
||
17 | 17 | interface TemplateManager |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @param string $template_name Name of the template to use (can include path separators) |
|
22 | - * |
|
23 | - * @return string Path to the compiled template file |
|
24 | - */ |
|
25 | - public function getPath($template_name); |
|
20 | + /** |
|
21 | + * @param string $template_name Name of the template to use (can include path separators) |
|
22 | + * |
|
23 | + * @return string Path to the compiled template file |
|
24 | + */ |
|
25 | + public function getPath($template_name); |
|
26 | 26 | |
27 | 27 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | class CFSWrapper |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @see \Kohana::find_file |
|
20 | - */ |
|
21 | - public function find_file($dir, $file) |
|
22 | - { |
|
23 | - return \Kohana::find_file($dir, $file, NULL, FALSE); |
|
24 | - } |
|
18 | + /** |
|
19 | + * @see \Kohana::find_file |
|
20 | + */ |
|
21 | + public function find_file($dir, $file) |
|
22 | + { |
|
23 | + return \Kohana::find_file($dir, $file, NULL, FALSE); |
|
24 | + } |
|
25 | 25 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Andrew Coulton <[email protected]> |
|
4 | - * @copyright 2015 inGenerator Ltd |
|
5 | - * @license http://kohanaframework.org/license |
|
6 | - */ |
|
3 | + * @author Andrew Coulton <[email protected]> |
|
4 | + * @copyright 2015 inGenerator Ltd |
|
5 | + * @license http://kohanaframework.org/license |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | namespace Ingenerator\KohanaView; |
9 | 9 | |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | interface TemplateSpecifyingViewModel |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function getTemplateName(); |
|
19 | + /** |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function getTemplateName(); |
|
23 | 23 | } |
@@ -17,11 +17,11 @@ |
||
17 | 17 | interface Renderer |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @param ViewModel $view |
|
22 | - * |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function render(ViewModel $view); |
|
20 | + /** |
|
21 | + * @param ViewModel $view |
|
22 | + * |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function render(ViewModel $view); |
|
26 | 26 | |
27 | 27 | } |
@@ -22,72 +22,72 @@ |
||
22 | 22 | class HTMLRenderer implements Renderer |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var TemplateManager |
|
27 | - */ |
|
28 | - protected $template_manager; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var ViewTemplateSelector |
|
32 | - */ |
|
33 | - protected $template_selector; |
|
34 | - |
|
35 | - public function __construct(ViewTemplateSelector $template_selector, TemplateManager $template_manager) |
|
36 | - { |
|
37 | - $this->template_selector = $template_selector; |
|
38 | - $this->template_manager = $template_manager; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * {@inheritdoc} |
|
44 | - */ |
|
45 | - public function render(ViewModel $view) |
|
46 | - { |
|
47 | - $template_path = $this->getTemplatePath($view); |
|
48 | - |
|
49 | - ob_start(); |
|
50 | - try { |
|
51 | - $this->includeWithAnonymousScope($view, $template_path); |
|
52 | - } finally { |
|
53 | - $output = ob_get_clean(); |
|
54 | - } |
|
55 | - |
|
56 | - return $output; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param ViewModel $view |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function getTemplatePath(ViewModel $view) |
|
65 | - { |
|
66 | - $template_name = $this->template_selector->getTemplateName($view); |
|
67 | - $template = $this->template_manager->getPath($template_name); |
|
68 | - |
|
69 | - return $template; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param ViewModel $view |
|
74 | - * @param string $template_path |
|
75 | - */ |
|
76 | - protected function includeWithAnonymousScope(ViewModel $view, $template_path) |
|
77 | - { |
|
78 | - /** @noinspection PhpUnusedParameterInspection */ |
|
79 | - /** @noinspection PhpDocSignatureInspection */ |
|
80 | - $bound_capture = function (ViewModel $view, Renderer $renderer, $template) { |
|
81 | - /** @noinspection PhpIncludeInspection */ |
|
82 | - return include $template; |
|
83 | - }; |
|
84 | - $anon_capture = $bound_capture->bindTo(NULL); |
|
85 | - |
|
86 | - // A user's own error handler may throw an exception here if the include fails - which we will bubble as-is. |
|
87 | - // If they have not configured an error handler, we need to throw an exception of our own. |
|
88 | - if ($anon_capture($view, $this, $template_path) === FALSE) { |
|
89 | - throw new \UnexpectedValueException('Failed to include template '.$template_path); |
|
90 | - } |
|
91 | - } |
|
25 | + /** |
|
26 | + * @var TemplateManager |
|
27 | + */ |
|
28 | + protected $template_manager; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var ViewTemplateSelector |
|
32 | + */ |
|
33 | + protected $template_selector; |
|
34 | + |
|
35 | + public function __construct(ViewTemplateSelector $template_selector, TemplateManager $template_manager) |
|
36 | + { |
|
37 | + $this->template_selector = $template_selector; |
|
38 | + $this->template_manager = $template_manager; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * {@inheritdoc} |
|
44 | + */ |
|
45 | + public function render(ViewModel $view) |
|
46 | + { |
|
47 | + $template_path = $this->getTemplatePath($view); |
|
48 | + |
|
49 | + ob_start(); |
|
50 | + try { |
|
51 | + $this->includeWithAnonymousScope($view, $template_path); |
|
52 | + } finally { |
|
53 | + $output = ob_get_clean(); |
|
54 | + } |
|
55 | + |
|
56 | + return $output; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param ViewModel $view |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function getTemplatePath(ViewModel $view) |
|
65 | + { |
|
66 | + $template_name = $this->template_selector->getTemplateName($view); |
|
67 | + $template = $this->template_manager->getPath($template_name); |
|
68 | + |
|
69 | + return $template; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param ViewModel $view |
|
74 | + * @param string $template_path |
|
75 | + */ |
|
76 | + protected function includeWithAnonymousScope(ViewModel $view, $template_path) |
|
77 | + { |
|
78 | + /** @noinspection PhpUnusedParameterInspection */ |
|
79 | + /** @noinspection PhpDocSignatureInspection */ |
|
80 | + $bound_capture = function (ViewModel $view, Renderer $renderer, $template) { |
|
81 | + /** @noinspection PhpIncludeInspection */ |
|
82 | + return include $template; |
|
83 | + }; |
|
84 | + $anon_capture = $bound_capture->bindTo(NULL); |
|
85 | + |
|
86 | + // A user's own error handler may throw an exception here if the include fails - which we will bubble as-is. |
|
87 | + // If they have not configured an error handler, we need to throw an exception of our own. |
|
88 | + if ($anon_capture($view, $this, $template_path) === FALSE) { |
|
89 | + throw new \UnexpectedValueException('Failed to include template '.$template_path); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -77,11 +77,11 @@ |
||
77 | 77 | { |
78 | 78 | /** @noinspection PhpUnusedParameterInspection */ |
79 | 79 | /** @noinspection PhpDocSignatureInspection */ |
80 | - $bound_capture = function (ViewModel $view, Renderer $renderer, $template) { |
|
80 | + $bound_capture = function(ViewModel $view, Renderer $renderer, $template) { |
|
81 | 81 | /** @noinspection PhpIncludeInspection */ |
82 | 82 | return include $template; |
83 | 83 | }; |
84 | - $anon_capture = $bound_capture->bindTo(NULL); |
|
84 | + $anon_capture = $bound_capture->bindTo(NULL); |
|
85 | 85 | |
86 | 86 | // A user's own error handler may throw an exception here if the include fails - which we will bubble as-is. |
87 | 87 | // If they have not configured an error handler, we need to throw an exception of our own. |
@@ -21,10 +21,10 @@ |
||
21 | 21 | interface PageContentView extends ViewModel |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * The page layout that this content view will be rendered into |
|
26 | - * |
|
27 | - * @return PageLayoutView |
|
28 | - */ |
|
29 | - public function var_page(); |
|
24 | + /** |
|
25 | + * The page layout that this content view will be rendered into |
|
26 | + * |
|
27 | + * @return PageLayoutView |
|
28 | + */ |
|
29 | + public function var_page(); |
|
30 | 30 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Andrew Coulton <[email protected]> |
|
4 | - * @copyright 2015 inGenerator Ltd |
|
5 | - * @license http://kohanaframework.org/license |
|
6 | - */ |
|
3 | + * @author Andrew Coulton <[email protected]> |
|
4 | + * @copyright 2015 inGenerator Ltd |
|
5 | + * @license http://kohanaframework.org/license |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | namespace Ingenerator\KohanaView\ViewModel\PageLayout; |
9 | 9 | |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | abstract class AbstractPageContentView extends AbstractViewModel implements PageContentView |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var PageLayoutView |
|
32 | - */ |
|
33 | - protected $page_view; |
|
34 | - |
|
35 | - public function __construct(PageLayoutView $page) |
|
36 | - { |
|
37 | - $this->page_view = $page; |
|
38 | - parent::__construct(); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return PageLayoutView |
|
43 | - */ |
|
44 | - public function var_page() |
|
45 | - { |
|
46 | - return $this->page_view; |
|
47 | - } |
|
30 | + /** |
|
31 | + * @var PageLayoutView |
|
32 | + */ |
|
33 | + protected $page_view; |
|
34 | + |
|
35 | + public function __construct(PageLayoutView $page) |
|
36 | + { |
|
37 | + $this->page_view = $page; |
|
38 | + parent::__construct(); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return PageLayoutView |
|
43 | + */ |
|
44 | + public function var_page() |
|
45 | + { |
|
46 | + return $this->page_view; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |