@@ -22,146 +22,146 @@ |
||
22 | 22 | */ |
23 | 23 | abstract class Ingenerator_View_Layout extends View_Model |
24 | 24 | { |
25 | - // The name of the template model to use |
|
26 | - public $template = 'Global'; |
|
27 | - |
|
28 | - // Whether to render the view within the template or not, null for auto |
|
29 | - protected $_use_template = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * Sets a new template to use for this view model. By default template names |
|
33 | - * become View_Template_$template classes. |
|
34 | - * |
|
35 | - * @param string $template |
|
36 | - */ |
|
37 | - public function set_template($template) |
|
38 | - { |
|
39 | - $this->template = $template; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Returns the View_Model representing the template layout (instantiating it |
|
44 | - * if it has not previously been created). |
|
45 | - * |
|
46 | - * @return View_Model |
|
47 | - */ |
|
48 | - public function var_page() |
|
49 | - { |
|
50 | - if ( is_string($this->template)) |
|
51 | - { |
|
52 | - $class = 'View_Template_'.$this->template; |
|
53 | - if ( ! class_exists($class)) |
|
54 | - { |
|
55 | - $class = 'View'; |
|
56 | - } |
|
57 | - $this->template = new $class(); |
|
58 | - } |
|
59 | - return $this->template; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Hook called just before the body content is rendered, as a useful extension |
|
64 | - * point for transforming any data or setting variables on the page template. |
|
65 | - * |
|
66 | - * class View_Index extends View_Layout |
|
67 | - * { |
|
68 | - * public function pre_render() |
|
69 | - * { |
|
70 | - * $page = $this->var_page(); |
|
71 | - * $page->title = 'Index'; |
|
72 | - * } |
|
73 | - * } |
|
74 | - */ |
|
75 | - public function pre_render() |
|
76 | - { |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Hook called just after the body content is rendered, as a useful extension |
|
81 | - * point for transforming any data or setting variables on the page template. |
|
82 | - * |
|
83 | - * @see View_Layout::pre_render() |
|
84 | - */ |
|
85 | - public function post_render() |
|
86 | - { |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Renders the body content (calling [View_Layout::pre_render()] and |
|
92 | - * [View_Layout::post_render()] in the process). |
|
93 | - * |
|
94 | - * If required, the body content will then be passed to the template view |
|
95 | - * for rendering within the page layout and the fully templated page returned. |
|
96 | - * Otherwise, the body fragment is returned alone and the page template is |
|
97 | - * never rendered. |
|
98 | - * |
|
99 | - * @param string $file If wishing to generate a view to a file |
|
100 | - * @return string The formatted view content |
|
101 | - */ |
|
102 | - public function render($file = null) |
|
103 | - { |
|
104 | - $this->pre_render(); |
|
105 | - |
|
106 | - // Generate the body content |
|
107 | - $body = parent::render($file); |
|
108 | - |
|
109 | - $this->post_render(); |
|
110 | - |
|
111 | - // Render the template if required |
|
112 | - if ($this->use_template()) |
|
113 | - { |
|
114 | - $template = $this->var_page(); |
|
115 | - $template->set('var_body', $body); |
|
116 | - return $template->render(); |
|
117 | - } |
|
118 | - |
|
119 | - return $body; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Setter/Getter for the use_template setting determining whether or not to |
|
124 | - * render the page template or just the body fragment. |
|
125 | - * |
|
126 | - * By default, $this-_use_template is null, meaning the class should determine |
|
127 | - * automatically based on whether the request is an AJAX request. |
|
128 | - * |
|
129 | - * If manually set true or false, the class will respect this value. |
|
130 | - * |
|
131 | - * @uses Request::is_ajax |
|
132 | - * @uses Request::current() |
|
133 | - * |
|
134 | - * @param boolean $use_template |
|
135 | - * @return boolean If called as getter |
|
136 | - * @return View_Layout If called as setter |
|
137 | - */ |
|
138 | - public function use_template($use_template = null) |
|
139 | - { |
|
140 | - // If we're being called as a setter |
|
141 | - if ($use_template !== null) |
|
142 | - { |
|
143 | - $this->_use_template = $use_template; |
|
144 | - return $this; |
|
145 | - } |
|
146 | - |
|
147 | - // If an explicit value was set |
|
148 | - if ($this->_use_template !== null) |
|
149 | - { |
|
150 | - return $this->_use_template; |
|
151 | - } |
|
152 | - |
|
153 | - // Guess based on is_ajax |
|
154 | - if (Request::current()) |
|
155 | - { |
|
156 | - if (Request::current()->is_ajax()) |
|
157 | - { |
|
158 | - return false; |
|
159 | - } |
|
160 | - else |
|
161 | - { |
|
162 | - return true; |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
25 | + // The name of the template model to use |
|
26 | + public $template = 'Global'; |
|
27 | + |
|
28 | + // Whether to render the view within the template or not, null for auto |
|
29 | + protected $_use_template = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * Sets a new template to use for this view model. By default template names |
|
33 | + * become View_Template_$template classes. |
|
34 | + * |
|
35 | + * @param string $template |
|
36 | + */ |
|
37 | + public function set_template($template) |
|
38 | + { |
|
39 | + $this->template = $template; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Returns the View_Model representing the template layout (instantiating it |
|
44 | + * if it has not previously been created). |
|
45 | + * |
|
46 | + * @return View_Model |
|
47 | + */ |
|
48 | + public function var_page() |
|
49 | + { |
|
50 | + if ( is_string($this->template)) |
|
51 | + { |
|
52 | + $class = 'View_Template_'.$this->template; |
|
53 | + if ( ! class_exists($class)) |
|
54 | + { |
|
55 | + $class = 'View'; |
|
56 | + } |
|
57 | + $this->template = new $class(); |
|
58 | + } |
|
59 | + return $this->template; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Hook called just before the body content is rendered, as a useful extension |
|
64 | + * point for transforming any data or setting variables on the page template. |
|
65 | + * |
|
66 | + * class View_Index extends View_Layout |
|
67 | + * { |
|
68 | + * public function pre_render() |
|
69 | + * { |
|
70 | + * $page = $this->var_page(); |
|
71 | + * $page->title = 'Index'; |
|
72 | + * } |
|
73 | + * } |
|
74 | + */ |
|
75 | + public function pre_render() |
|
76 | + { |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Hook called just after the body content is rendered, as a useful extension |
|
81 | + * point for transforming any data or setting variables on the page template. |
|
82 | + * |
|
83 | + * @see View_Layout::pre_render() |
|
84 | + */ |
|
85 | + public function post_render() |
|
86 | + { |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Renders the body content (calling [View_Layout::pre_render()] and |
|
92 | + * [View_Layout::post_render()] in the process). |
|
93 | + * |
|
94 | + * If required, the body content will then be passed to the template view |
|
95 | + * for rendering within the page layout and the fully templated page returned. |
|
96 | + * Otherwise, the body fragment is returned alone and the page template is |
|
97 | + * never rendered. |
|
98 | + * |
|
99 | + * @param string $file If wishing to generate a view to a file |
|
100 | + * @return string The formatted view content |
|
101 | + */ |
|
102 | + public function render($file = null) |
|
103 | + { |
|
104 | + $this->pre_render(); |
|
105 | + |
|
106 | + // Generate the body content |
|
107 | + $body = parent::render($file); |
|
108 | + |
|
109 | + $this->post_render(); |
|
110 | + |
|
111 | + // Render the template if required |
|
112 | + if ($this->use_template()) |
|
113 | + { |
|
114 | + $template = $this->var_page(); |
|
115 | + $template->set('var_body', $body); |
|
116 | + return $template->render(); |
|
117 | + } |
|
118 | + |
|
119 | + return $body; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Setter/Getter for the use_template setting determining whether or not to |
|
124 | + * render the page template or just the body fragment. |
|
125 | + * |
|
126 | + * By default, $this-_use_template is null, meaning the class should determine |
|
127 | + * automatically based on whether the request is an AJAX request. |
|
128 | + * |
|
129 | + * If manually set true or false, the class will respect this value. |
|
130 | + * |
|
131 | + * @uses Request::is_ajax |
|
132 | + * @uses Request::current() |
|
133 | + * |
|
134 | + * @param boolean $use_template |
|
135 | + * @return boolean If called as getter |
|
136 | + * @return View_Layout If called as setter |
|
137 | + */ |
|
138 | + public function use_template($use_template = null) |
|
139 | + { |
|
140 | + // If we're being called as a setter |
|
141 | + if ($use_template !== null) |
|
142 | + { |
|
143 | + $this->_use_template = $use_template; |
|
144 | + return $this; |
|
145 | + } |
|
146 | + |
|
147 | + // If an explicit value was set |
|
148 | + if ($this->_use_template !== null) |
|
149 | + { |
|
150 | + return $this->_use_template; |
|
151 | + } |
|
152 | + |
|
153 | + // Guess based on is_ajax |
|
154 | + if (Request::current()) |
|
155 | + { |
|
156 | + if (Request::current()->is_ajax()) |
|
157 | + { |
|
158 | + return false; |
|
159 | + } |
|
160 | + else |
|
161 | + { |
|
162 | + return true; |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | 167 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | */ |
48 | 48 | public function var_page() |
49 | 49 | { |
50 | - if ( is_string($this->template)) |
|
50 | + if (is_string($this->template)) |
|
51 | 51 | { |
52 | 52 | $class = 'View_Template_'.$this->template; |
53 | 53 | if ( ! class_exists($class)) |
@@ -156,8 +156,7 @@ |
||
156 | 156 | if (Request::current()->is_ajax()) |
157 | 157 | { |
158 | 158 | return false; |
159 | - } |
|
160 | - else |
|
159 | + } else |
|
161 | 160 | { |
162 | 161 | return true; |
163 | 162 | } |
@@ -16,5 +16,5 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class Ingenerator_View_Template_Global extends View_Model |
18 | 18 | { |
19 | - public $var_title = 'Page title'; |
|
19 | + public $var_title = 'Page title'; |
|
20 | 20 | } |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Acts as an object wrapper for output with embedded PHP, called "views". |
|
4 | - * Variables can be assigned with the view object and referenced locally within |
|
5 | - * the view. |
|
6 | - * |
|
7 | - * @package Kohana |
|
8 | - * @category Base |
|
9 | - * @author Kohana Team |
|
10 | - * @copyright (c) 2008-2010 Kohana Team |
|
11 | - * @license http://kohanaphp.com/license |
|
12 | - */ |
|
3 | + * Acts as an object wrapper for output with embedded PHP, called "views". |
|
4 | + * Variables can be assigned with the view object and referenced locally within |
|
5 | + * the view. |
|
6 | + * |
|
7 | + * @package Kohana |
|
8 | + * @category Base |
|
9 | + * @author Kohana Team |
|
10 | + * @copyright (c) 2008-2010 Kohana Team |
|
11 | + * @license http://kohanaphp.com/license |
|
12 | + */ |
|
13 | 13 | class Kohana_View_Model { |
14 | 14 | |
15 | 15 | // View filename |
@@ -245,7 +245,7 @@ |
||
245 | 245 | */ |
246 | 246 | public function bind($key, & $value) |
247 | 247 | { |
248 | - $this->{$key} =& $value; |
|
248 | + $this->{$key} = & $value; |
|
249 | 249 | |
250 | 250 | return $this; |
251 | 251 | } |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | public static function factory($file = NULL, array $data = NULL) |
29 | 29 | { |
30 | 30 | // Return a raw view object if no template is specified. |
31 | - if ($file === FALSE) |
|
32 | - return new View(FALSE, $data); |
|
31 | + if ($file === FALSE) { |
|
32 | + return new View(FALSE, $data); |
|
33 | + } |
|
33 | 34 | |
34 | 35 | $class = 'View_'.strtr($file, '/', '_'); |
35 | 36 | |
@@ -63,8 +64,7 @@ discard block |
||
63 | 64 | try |
64 | 65 | { |
65 | 66 | include 'kohana.view://'.$kohana_view_filename; |
66 | - } |
|
67 | - catch (Exception $e) |
|
67 | + } catch (Exception $e) |
|
68 | 68 | { |
69 | 69 | // Delete the output buffer |
70 | 70 | ob_end_clean(); |
@@ -126,12 +126,10 @@ discard block |
||
126 | 126 | if (method_exists($this, $key)) |
127 | 127 | { |
128 | 128 | return $this->$key(); |
129 | - } |
|
130 | - elseif (property_exists($this, $key)) |
|
129 | + } elseif (property_exists($this, $key)) |
|
131 | 130 | { |
132 | 131 | return $this->$key; |
133 | - } |
|
134 | - else |
|
132 | + } else |
|
135 | 133 | { |
136 | 134 | throw new Kohana_Exception('View variable is not set: :var', [':var' => $key]); |
137 | 135 | } |
@@ -163,8 +161,7 @@ discard block |
||
163 | 161 | try |
164 | 162 | { |
165 | 163 | return $this->render(); |
166 | - } |
|
167 | - catch (Exception $e) |
|
164 | + } catch (Exception $e) |
|
168 | 165 | { |
169 | 166 | // Display the exception message |
170 | 167 | Kohana_Exception::handler($e); |
@@ -221,8 +218,7 @@ discard block |
||
221 | 218 | { |
222 | 219 | $this->{$name} = $value; |
223 | 220 | } |
224 | - } |
|
225 | - else |
|
221 | + } else |
|
226 | 222 | { |
227 | 223 | $this->{$key} = $value; |
228 | 224 | } |
@@ -179,7 +179,7 @@ |
||
179 | 179 | * $view->set_filename($file); |
180 | 180 | * |
181 | 181 | * @param string view filename |
182 | - * @return View |
|
182 | + * @return Kohana_View_Model |
|
183 | 183 | * @throws Kohana_View_Exception |
184 | 184 | */ |
185 | 185 | public function set_filename($file) |
@@ -1,23 +1,23 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Zend Framework |
|
4 | - * |
|
5 | - * LICENSE |
|
6 | - * |
|
7 | - * This source file is subject to the new BSD license that is bundled |
|
8 | - * with this package in the file LICENSE.txt. |
|
9 | - * It is also available through the world-wide-web at this URL: |
|
10 | - * http://framework.zend.com/license/new-bsd |
|
11 | - * If you did not receive a copy of the license and are unable to |
|
12 | - * obtain it through the world-wide-web, please send an email |
|
13 | - * to [email protected] so we can send you a copy immediately. |
|
14 | - * |
|
15 | - * @category Zend |
|
16 | - * @package Zend_View |
|
17 | - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 | - * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 | - * @version $Id$ |
|
20 | - */ |
|
3 | + * Zend Framework |
|
4 | + * |
|
5 | + * LICENSE |
|
6 | + * |
|
7 | + * This source file is subject to the new BSD license that is bundled |
|
8 | + * with this package in the file LICENSE.txt. |
|
9 | + * It is also available through the world-wide-web at this URL: |
|
10 | + * http://framework.zend.com/license/new-bsd |
|
11 | + * If you did not receive a copy of the license and are unable to |
|
12 | + * obtain it through the world-wide-web, please send an email |
|
13 | + * to [email protected] so we can send you a copy immediately. |
|
14 | + * |
|
15 | + * @category Zend |
|
16 | + * @package Zend_View |
|
17 | + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 | + * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 | + * @version $Id$ |
|
20 | + */ |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Stream wrapper to convert markup of mostly-PHP templates into PHP prior to |
@@ -115,31 +115,31 @@ discard block |
||
115 | 115 | */ |
116 | 116 | protected function _escape_val($matches) |
117 | 117 | { |
118 | - // Start by trimming the echoed string |
|
119 | - $code = trim($matches[2]); |
|
120 | - |
|
121 | - // Then map all variables within the codeblock to the view class |
|
122 | - $code = preg_replace('/\$(?!tmp_|this->)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)/', |
|
123 | - '$this->var_$1', $code); |
|
124 | - |
|
125 | - // If this block is not the special <?= block return |
|
126 | - if ($matches[1] !== '=') |
|
127 | - { |
|
128 | - return '<?php '. $code . '?>'; |
|
129 | - } |
|
130 | - |
|
131 | - // Remove trailing ; characters |
|
132 | - $var = trim($code, ';'); |
|
133 | - |
|
134 | - if (substr($var, 0, 1) != $this->_raw_output_char) |
|
135 | - { |
|
136 | - return '<?php echo '.$this->_encode_method.'('.$var.'); ?>'; |
|
137 | - } |
|
138 | - else |
|
139 | - { |
|
140 | - // Remove the "turn off escape" character |
|
141 | - return '<?php echo '.substr($var, strlen($this->_raw_output_char), strlen($var)-1).'; ?>'; |
|
142 | - } |
|
118 | + // Start by trimming the echoed string |
|
119 | + $code = trim($matches[2]); |
|
120 | + |
|
121 | + // Then map all variables within the codeblock to the view class |
|
122 | + $code = preg_replace('/\$(?!tmp_|this->)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)/', |
|
123 | + '$this->var_$1', $code); |
|
124 | + |
|
125 | + // If this block is not the special <?= block return |
|
126 | + if ($matches[1] !== '=') |
|
127 | + { |
|
128 | + return '<?php '. $code . '?>'; |
|
129 | + } |
|
130 | + |
|
131 | + // Remove trailing ; characters |
|
132 | + $var = trim($code, ';'); |
|
133 | + |
|
134 | + if (substr($var, 0, 1) != $this->_raw_output_char) |
|
135 | + { |
|
136 | + return '<?php echo '.$this->_encode_method.'('.$var.'); ?>'; |
|
137 | + } |
|
138 | + else |
|
139 | + { |
|
140 | + // Remove the "turn off escape" character |
|
141 | + return '<?php echo '.substr($var, strlen($this->_raw_output_char), strlen($var)-1).'; ?>'; |
|
142 | + } |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | // If this block is not the special <?= block return |
126 | 126 | if ($matches[1] !== '=') |
127 | 127 | { |
128 | - return '<?php '. $code . '?>'; |
|
128 | + return '<?php '.$code.'?>'; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | // Remove trailing ; characters |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | else |
139 | 139 | { |
140 | 140 | // Remove the "turn off escape" character |
141 | - return '<?php echo '.substr($var, strlen($this->_raw_output_char), strlen($var)-1).'; ?>'; |
|
141 | + return '<?php echo '.substr($var, strlen($this->_raw_output_char), strlen($var) - 1).'; ?>'; |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 |
@@ -134,8 +134,7 @@ discard block |
||
134 | 134 | if (substr($var, 0, 1) != $this->_raw_output_char) |
135 | 135 | { |
136 | 136 | return '<?php echo '.$this->_encode_method.'('.$var.'); ?>'; |
137 | - } |
|
138 | - else |
|
137 | + } else |
|
139 | 138 | { |
140 | 139 | // Remove the "turn off escape" character |
141 | 140 | return '<?php echo '.substr($var, strlen($this->_raw_output_char), strlen($var)-1).'; ?>'; |
@@ -198,8 +197,7 @@ discard block |
||
198 | 197 | { |
199 | 198 | $this->_pos = $offset; |
200 | 199 | return true; |
201 | - } |
|
202 | - else |
|
200 | + } else |
|
203 | 201 | { |
204 | 202 | return false; |
205 | 203 | } |
@@ -210,8 +208,7 @@ discard block |
||
210 | 208 | { |
211 | 209 | $this->_pos += $offset; |
212 | 210 | return true; |
213 | - } |
|
214 | - else |
|
211 | + } else |
|
215 | 212 | { |
216 | 213 | return false; |
217 | 214 | } |
@@ -222,8 +219,7 @@ discard block |
||
222 | 219 | { |
223 | 220 | $this->_pos = strlen($this->_data) + $offset; |
224 | 221 | return true; |
225 | - } |
|
226 | - else |
|
222 | + } else |
|
227 | 223 | { |
228 | 224 | return false; |
229 | 225 | } |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Basic global template view, rendered by the View_Template_Global class. |
|
4 | - * |
|
5 | - * @see View_Template_Global |
|
6 | - * @var string $title Page title |
|
7 | - * @var string $body Page body HTML |
|
8 | - */ |
|
3 | + * Basic global template view, rendered by the View_Template_Global class. |
|
4 | + * |
|
5 | + * @see View_Template_Global |
|
6 | + * @var string $title Page title |
|
7 | + * @var string $body Page body HTML |
|
8 | + */ |
|
9 | 9 | ?> |
10 | 10 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
11 | 11 | <html> |
@@ -10,9 +10,9 @@ |
||
10 | 10 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
11 | 11 | <html> |
12 | 12 | <head> |
13 | - <title><?=$title;?></title> |
|
13 | + <title><?=$title; ?></title> |
|
14 | 14 | </head> |
15 | 15 | <body> |
16 | - <?=$body;?> |
|
16 | + <?=$body; ?> |
|
17 | 17 | </body> |
18 | 18 | </html> |
@@ -16,8 +16,8 @@ |
||
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 | } |
@@ -1,9 +1,9 @@ |
||
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 |
@@ -18,61 +18,61 @@ |
||
18 | 18 | class ViewTemplateSelector |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @param ViewModel $view |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getTemplateName(ViewModel $view) |
|
27 | - { |
|
28 | - if ($view instanceof TemplateSpecifyingViewModel) { |
|
29 | - return $this->validateSpecifiedTemplateName($view); |
|
30 | - } else { |
|
31 | - return $this->calculateTemplateFromClassName($view); |
|
32 | - } |
|
33 | - } |
|
21 | + /** |
|
22 | + * @param ViewModel $view |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getTemplateName(ViewModel $view) |
|
27 | + { |
|
28 | + if ($view instanceof TemplateSpecifyingViewModel) { |
|
29 | + return $this->validateSpecifiedTemplateName($view); |
|
30 | + } else { |
|
31 | + return $this->calculateTemplateFromClassName($view); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param TemplateSpecifyingViewModel $view |
|
37 | - * |
|
38 | - * @return mixed |
|
39 | - * @throws \UnexpectedValueException if no template is provided |
|
40 | - */ |
|
41 | - protected function validateSpecifiedTemplateName(TemplateSpecifyingViewModel $view) |
|
42 | - { |
|
43 | - $template = $view->getTemplateName(); |
|
44 | - $view_class = get_class($view); |
|
45 | - if ( ! $template) { |
|
46 | - throw new \UnexpectedValueException( |
|
47 | - "$view_class::getTemplateName() must return a template name, empty value returned" |
|
48 | - ); |
|
49 | - } |
|
35 | + /** |
|
36 | + * @param TemplateSpecifyingViewModel $view |
|
37 | + * |
|
38 | + * @return mixed |
|
39 | + * @throws \UnexpectedValueException if no template is provided |
|
40 | + */ |
|
41 | + protected function validateSpecifiedTemplateName(TemplateSpecifyingViewModel $view) |
|
42 | + { |
|
43 | + $template = $view->getTemplateName(); |
|
44 | + $view_class = get_class($view); |
|
45 | + if ( ! $template) { |
|
46 | + throw new \UnexpectedValueException( |
|
47 | + "$view_class::getTemplateName() must return a template name, empty value returned" |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | |
51 | - if ( ! is_string($template)) { |
|
52 | - $type = is_object($template) ? get_class($template) : gettype($template); |
|
53 | - throw new \UnexpectedValueException( |
|
54 | - "$view_class::getTemplateName() must return a string template name, $type value returned" |
|
55 | - ); |
|
56 | - } |
|
51 | + if ( ! is_string($template)) { |
|
52 | + $type = is_object($template) ? get_class($template) : gettype($template); |
|
53 | + throw new \UnexpectedValueException( |
|
54 | + "$view_class::getTemplateName() must return a string template name, $type value returned" |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - return $template; |
|
59 | - } |
|
58 | + return $template; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param ViewModel $view |
|
63 | - * |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - protected function calculateTemplateFromClassName(ViewModel $view) |
|
67 | - { |
|
68 | - $template = preg_replace('/\\\\|_/', '/', get_class($view)); |
|
69 | - $template = preg_replace('/([a-z])([A-Z])/', '\1_\2', $template); |
|
70 | - $template = strtolower($template); |
|
71 | - if (substr($template, 0, 5) === 'view/') { |
|
72 | - $template = substr($template, 5); |
|
73 | - } |
|
61 | + /** |
|
62 | + * @param ViewModel $view |
|
63 | + * |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + protected function calculateTemplateFromClassName(ViewModel $view) |
|
67 | + { |
|
68 | + $template = preg_replace('/\\\\|_/', '/', get_class($view)); |
|
69 | + $template = preg_replace('/([a-z])([A-Z])/', '\1_\2', $template); |
|
70 | + $template = strtolower($template); |
|
71 | + if (substr($template, 0, 5) === 'view/') { |
|
72 | + $template = substr($template, 5); |
|
73 | + } |
|
74 | 74 | |
75 | - return $template; |
|
76 | - } |
|
75 | + return $template; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | } |
@@ -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 | ); |