@@ -179,7 +179,7 @@ discard block |
||
| 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) |
@@ -260,6 +260,7 @@ discard block |
||
| 260 | 260 | * overwritten by the local variable. |
| 261 | 261 | * |
| 262 | 262 | * @param string view filename |
| 263 | + * @param string $file |
|
| 263 | 264 | * @return string |
| 264 | 265 | * @throws Kohana_View_Exception |
| 265 | 266 | * @uses View::capture |
@@ -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 | } |
@@ -12,272 +12,272 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Kohana_View_Model { |
| 14 | 14 | |
| 15 | - // View filename |
|
| 16 | - protected $_file; |
|
| 15 | + // View filename |
|
| 16 | + protected $_file; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns a new raw View object. If you do not define the "file" parameter, |
|
| 20 | - * you must call [View::set_filename]. |
|
| 21 | - * |
|
| 22 | - * $view = View::factory($file); |
|
| 23 | - * |
|
| 24 | - * @param string view filename |
|
| 25 | - * @param array array of values |
|
| 26 | - * @return View |
|
| 27 | - */ |
|
| 28 | - public static function factory($file = NULL, array $data = NULL) |
|
| 29 | - { |
|
| 30 | - // Return a raw view object if no template is specified. |
|
| 31 | - if ($file === FALSE) |
|
| 32 | - return new View(FALSE, $data); |
|
| 18 | + /** |
|
| 19 | + * Returns a new raw View object. If you do not define the "file" parameter, |
|
| 20 | + * you must call [View::set_filename]. |
|
| 21 | + * |
|
| 22 | + * $view = View::factory($file); |
|
| 23 | + * |
|
| 24 | + * @param string view filename |
|
| 25 | + * @param array array of values |
|
| 26 | + * @return View |
|
| 27 | + */ |
|
| 28 | + public static function factory($file = NULL, array $data = NULL) |
|
| 29 | + { |
|
| 30 | + // Return a raw view object if no template is specified. |
|
| 31 | + if ($file === FALSE) |
|
| 32 | + return new View(FALSE, $data); |
|
| 33 | 33 | |
| 34 | - $class = 'View_'.strtr($file, '/', '_'); |
|
| 34 | + $class = 'View_'.strtr($file, '/', '_'); |
|
| 35 | 35 | |
| 36 | - if ( ! class_exists($class)) |
|
| 37 | - { |
|
| 38 | - $class = 'View'; |
|
| 39 | - } |
|
| 36 | + if ( ! class_exists($class)) |
|
| 37 | + { |
|
| 38 | + $class = 'View'; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return new $class($file, $data); |
|
| 42 | - } |
|
| 41 | + return new $class($file, $data); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Captures the output that is generated when a view is included. |
|
| 46 | - * The view data will be extracted to make local variables. |
|
| 47 | - * |
|
| 48 | - * $output = $this->capture($file); |
|
| 49 | - * |
|
| 50 | - * @param string filename |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - protected function capture($kohana_view_filename) |
|
| 54 | - { |
|
| 55 | - if ( ! in_array('kohana.view', stream_get_wrappers())) |
|
| 56 | - { |
|
| 57 | - stream_wrapper_register('kohana.view', 'View_Stream_Wrapper'); |
|
| 58 | - } |
|
| 44 | + /** |
|
| 45 | + * Captures the output that is generated when a view is included. |
|
| 46 | + * The view data will be extracted to make local variables. |
|
| 47 | + * |
|
| 48 | + * $output = $this->capture($file); |
|
| 49 | + * |
|
| 50 | + * @param string filename |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + protected function capture($kohana_view_filename) |
|
| 54 | + { |
|
| 55 | + if ( ! in_array('kohana.view', stream_get_wrappers())) |
|
| 56 | + { |
|
| 57 | + stream_wrapper_register('kohana.view', 'View_Stream_Wrapper'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - // Capture the view output |
|
| 61 | - ob_start(); |
|
| 60 | + // Capture the view output |
|
| 61 | + ob_start(); |
|
| 62 | 62 | |
| 63 | - try |
|
| 64 | - { |
|
| 65 | - include 'kohana.view://'.$kohana_view_filename; |
|
| 66 | - } |
|
| 67 | - catch (Exception $e) |
|
| 68 | - { |
|
| 69 | - // Delete the output buffer |
|
| 70 | - ob_end_clean(); |
|
| 63 | + try |
|
| 64 | + { |
|
| 65 | + include 'kohana.view://'.$kohana_view_filename; |
|
| 66 | + } |
|
| 67 | + catch (Exception $e) |
|
| 68 | + { |
|
| 69 | + // Delete the output buffer |
|
| 70 | + ob_end_clean(); |
|
| 71 | 71 | |
| 72 | - // Re-throw the exception |
|
| 73 | - throw $e; |
|
| 74 | - } |
|
| 72 | + // Re-throw the exception |
|
| 73 | + throw $e; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Get the captured output and close the buffer |
|
| 77 | - return ob_get_clean(); |
|
| 78 | - } |
|
| 76 | + // Get the captured output and close the buffer |
|
| 77 | + return ob_get_clean(); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Sets the initial view filename and local data. Views should almost |
|
| 82 | - * always only be created using [View::factory]. |
|
| 83 | - * |
|
| 84 | - * $view = new View($file); |
|
| 85 | - * |
|
| 86 | - * @param string view filename |
|
| 87 | - * @param array array of values |
|
| 88 | - * @return void |
|
| 89 | - * @uses View::set_filename |
|
| 90 | - */ |
|
| 91 | - public function __construct($file = NULL, array $data = NULL) |
|
| 92 | - { |
|
| 93 | - if ($file === NULL) |
|
| 94 | - { |
|
| 95 | - $foo = explode('_', get_class($this)); |
|
| 96 | - array_shift($foo); |
|
| 97 | - $file = strtolower(implode('/', $foo)); |
|
| 98 | - } |
|
| 80 | + /** |
|
| 81 | + * Sets the initial view filename and local data. Views should almost |
|
| 82 | + * always only be created using [View::factory]. |
|
| 83 | + * |
|
| 84 | + * $view = new View($file); |
|
| 85 | + * |
|
| 86 | + * @param string view filename |
|
| 87 | + * @param array array of values |
|
| 88 | + * @return void |
|
| 89 | + * @uses View::set_filename |
|
| 90 | + */ |
|
| 91 | + public function __construct($file = NULL, array $data = NULL) |
|
| 92 | + { |
|
| 93 | + if ($file === NULL) |
|
| 94 | + { |
|
| 95 | + $foo = explode('_', get_class($this)); |
|
| 96 | + array_shift($foo); |
|
| 97 | + $file = strtolower(implode('/', $foo)); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - if ($file !== FALSE) |
|
| 101 | - { |
|
| 102 | - $this->set_filename($file); |
|
| 103 | - } |
|
| 100 | + if ($file !== FALSE) |
|
| 101 | + { |
|
| 102 | + $this->set_filename($file); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - if ($data !== NULL) |
|
| 106 | - { |
|
| 107 | - // Add the values to the current data |
|
| 108 | - $this->set($data); |
|
| 109 | - } |
|
| 110 | - } |
|
| 105 | + if ($data !== NULL) |
|
| 106 | + { |
|
| 107 | + // Add the values to the current data |
|
| 108 | + $this->set($data); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Magic method, searches for the given variable and returns its value. |
|
| 114 | - * Local variables will be returned before global variables. |
|
| 115 | - * |
|
| 116 | - * $value = $view->foo; |
|
| 117 | - * |
|
| 118 | - * [!!] If the variable has not yet been set, an exception will be thrown. |
|
| 119 | - * |
|
| 120 | - * @param string variable name |
|
| 121 | - * @return mixed |
|
| 122 | - * @throws Kohana_Exception |
|
| 123 | - */ |
|
| 124 | - public function __get($key) |
|
| 125 | - { |
|
| 126 | - if (method_exists($this, $key)) |
|
| 127 | - { |
|
| 128 | - return $this->$key(); |
|
| 129 | - } |
|
| 130 | - elseif (property_exists($this, $key)) |
|
| 131 | - { |
|
| 132 | - return $this->$key; |
|
| 133 | - } |
|
| 134 | - else |
|
| 135 | - { |
|
| 136 | - throw new Kohana_Exception('View variable is not set: :var', |
|
| 137 | - array(':var' => $key)); |
|
| 138 | - } |
|
| 139 | - } |
|
| 112 | + /** |
|
| 113 | + * Magic method, searches for the given variable and returns its value. |
|
| 114 | + * Local variables will be returned before global variables. |
|
| 115 | + * |
|
| 116 | + * $value = $view->foo; |
|
| 117 | + * |
|
| 118 | + * [!!] If the variable has not yet been set, an exception will be thrown. |
|
| 119 | + * |
|
| 120 | + * @param string variable name |
|
| 121 | + * @return mixed |
|
| 122 | + * @throws Kohana_Exception |
|
| 123 | + */ |
|
| 124 | + public function __get($key) |
|
| 125 | + { |
|
| 126 | + if (method_exists($this, $key)) |
|
| 127 | + { |
|
| 128 | + return $this->$key(); |
|
| 129 | + } |
|
| 130 | + elseif (property_exists($this, $key)) |
|
| 131 | + { |
|
| 132 | + return $this->$key; |
|
| 133 | + } |
|
| 134 | + else |
|
| 135 | + { |
|
| 136 | + throw new Kohana_Exception('View variable is not set: :var', |
|
| 137 | + array(':var' => $key)); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Magic method, calls [View::set] with the same parameters. |
|
| 143 | - * |
|
| 144 | - * $view->foo = 'something'; |
|
| 145 | - * |
|
| 146 | - * @param string variable name |
|
| 147 | - * @param mixed value |
|
| 148 | - * @return void |
|
| 149 | - */ |
|
| 150 | - public function __set($key, $value) |
|
| 151 | - { |
|
| 152 | - $this->set($key, $value); |
|
| 153 | - } |
|
| 141 | + /** |
|
| 142 | + * Magic method, calls [View::set] with the same parameters. |
|
| 143 | + * |
|
| 144 | + * $view->foo = 'something'; |
|
| 145 | + * |
|
| 146 | + * @param string variable name |
|
| 147 | + * @param mixed value |
|
| 148 | + * @return void |
|
| 149 | + */ |
|
| 150 | + public function __set($key, $value) |
|
| 151 | + { |
|
| 152 | + $this->set($key, $value); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Magic method, returns the output of [View::render]. |
|
| 158 | - * |
|
| 159 | - * @return string |
|
| 160 | - * @uses View::render |
|
| 161 | - */ |
|
| 162 | - public function __toString() |
|
| 163 | - { |
|
| 164 | - try |
|
| 165 | - { |
|
| 166 | - return $this->render(); |
|
| 167 | - } |
|
| 168 | - catch (Exception $e) |
|
| 169 | - { |
|
| 170 | - // Display the exception message |
|
| 171 | - Kohana_Exception::handler($e); |
|
| 156 | + /** |
|
| 157 | + * Magic method, returns the output of [View::render]. |
|
| 158 | + * |
|
| 159 | + * @return string |
|
| 160 | + * @uses View::render |
|
| 161 | + */ |
|
| 162 | + public function __toString() |
|
| 163 | + { |
|
| 164 | + try |
|
| 165 | + { |
|
| 166 | + return $this->render(); |
|
| 167 | + } |
|
| 168 | + catch (Exception $e) |
|
| 169 | + { |
|
| 170 | + // Display the exception message |
|
| 171 | + Kohana_Exception::handler($e); |
|
| 172 | 172 | |
| 173 | - return ''; |
|
| 174 | - } |
|
| 175 | - } |
|
| 173 | + return ''; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Sets the view filename. |
|
| 179 | - * |
|
| 180 | - * $view->set_filename($file); |
|
| 181 | - * |
|
| 182 | - * @param string view filename |
|
| 183 | - * @return View |
|
| 184 | - * @throws Kohana_View_Exception |
|
| 185 | - */ |
|
| 186 | - public function set_filename($file) |
|
| 187 | - { |
|
| 188 | - if (($path = Kohana::find_file('views', $file)) === FALSE) |
|
| 189 | - { |
|
| 190 | - throw new Kohana_View_Exception('The requested view :file could not be found', array( |
|
| 191 | - ':file' => $file, |
|
| 192 | - )); |
|
| 193 | - } |
|
| 177 | + /** |
|
| 178 | + * Sets the view filename. |
|
| 179 | + * |
|
| 180 | + * $view->set_filename($file); |
|
| 181 | + * |
|
| 182 | + * @param string view filename |
|
| 183 | + * @return View |
|
| 184 | + * @throws Kohana_View_Exception |
|
| 185 | + */ |
|
| 186 | + public function set_filename($file) |
|
| 187 | + { |
|
| 188 | + if (($path = Kohana::find_file('views', $file)) === FALSE) |
|
| 189 | + { |
|
| 190 | + throw new Kohana_View_Exception('The requested view :file could not be found', array( |
|
| 191 | + ':file' => $file, |
|
| 192 | + )); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - // Store the file path locally |
|
| 196 | - $this->_file = $path; |
|
| 195 | + // Store the file path locally |
|
| 196 | + $this->_file = $path; |
|
| 197 | 197 | |
| 198 | - return $this; |
|
| 199 | - } |
|
| 198 | + return $this; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Assigns a variable by name. Assigned values will be available as a |
|
| 203 | - * variable within the view file: |
|
| 204 | - * |
|
| 205 | - * // This value can be accessed as $foo within the view |
|
| 206 | - * $view->set('foo', 'my value'); |
|
| 207 | - * |
|
| 208 | - * You can also use an array to set several values at once: |
|
| 209 | - * |
|
| 210 | - * // Create the values $food and $beverage in the view |
|
| 211 | - * $view->set(array('food' => 'bread', 'beverage' => 'water')); |
|
| 212 | - * |
|
| 213 | - * @param string variable name or an array of variables |
|
| 214 | - * @param mixed value |
|
| 215 | - * @return $this |
|
| 216 | - */ |
|
| 217 | - public function set($key, $value = NULL) |
|
| 218 | - { |
|
| 219 | - if (is_array($key)) |
|
| 220 | - { |
|
| 221 | - foreach ($key as $name => $value) |
|
| 222 | - { |
|
| 223 | - $this->{$name} = $value; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - else |
|
| 227 | - { |
|
| 228 | - $this->{$key} = $value; |
|
| 229 | - } |
|
| 201 | + /** |
|
| 202 | + * Assigns a variable by name. Assigned values will be available as a |
|
| 203 | + * variable within the view file: |
|
| 204 | + * |
|
| 205 | + * // This value can be accessed as $foo within the view |
|
| 206 | + * $view->set('foo', 'my value'); |
|
| 207 | + * |
|
| 208 | + * You can also use an array to set several values at once: |
|
| 209 | + * |
|
| 210 | + * // Create the values $food and $beverage in the view |
|
| 211 | + * $view->set(array('food' => 'bread', 'beverage' => 'water')); |
|
| 212 | + * |
|
| 213 | + * @param string variable name or an array of variables |
|
| 214 | + * @param mixed value |
|
| 215 | + * @return $this |
|
| 216 | + */ |
|
| 217 | + public function set($key, $value = NULL) |
|
| 218 | + { |
|
| 219 | + if (is_array($key)) |
|
| 220 | + { |
|
| 221 | + foreach ($key as $name => $value) |
|
| 222 | + { |
|
| 223 | + $this->{$name} = $value; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + else |
|
| 227 | + { |
|
| 228 | + $this->{$key} = $value; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - return $this; |
|
| 232 | - } |
|
| 231 | + return $this; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Assigns a value by reference. The benefit of binding is that values can |
|
| 236 | - * be altered without re-setting them. It is also possible to bind variables |
|
| 237 | - * before they have values. Assigned values will be available as a |
|
| 238 | - * variable within the view file: |
|
| 239 | - * |
|
| 240 | - * // This reference can be accessed as $ref within the view |
|
| 241 | - * $view->bind('ref', $bar); |
|
| 242 | - * |
|
| 243 | - * @param string variable name |
|
| 244 | - * @param mixed referenced variable |
|
| 245 | - * @return $this |
|
| 246 | - */ |
|
| 247 | - public function bind($key, & $value) |
|
| 248 | - { |
|
| 249 | - $this->{$key} =& $value; |
|
| 234 | + /** |
|
| 235 | + * Assigns a value by reference. The benefit of binding is that values can |
|
| 236 | + * be altered without re-setting them. It is also possible to bind variables |
|
| 237 | + * before they have values. Assigned values will be available as a |
|
| 238 | + * variable within the view file: |
|
| 239 | + * |
|
| 240 | + * // This reference can be accessed as $ref within the view |
|
| 241 | + * $view->bind('ref', $bar); |
|
| 242 | + * |
|
| 243 | + * @param string variable name |
|
| 244 | + * @param mixed referenced variable |
|
| 245 | + * @return $this |
|
| 246 | + */ |
|
| 247 | + public function bind($key, & $value) |
|
| 248 | + { |
|
| 249 | + $this->{$key} =& $value; |
|
| 250 | 250 | |
| 251 | - return $this; |
|
| 252 | - } |
|
| 251 | + return $this; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Renders the view object to a string. Global and local data are merged |
|
| 256 | - * and extracted to create local variables within the view file. |
|
| 257 | - * |
|
| 258 | - * $output = View::render(); |
|
| 259 | - * |
|
| 260 | - * [!!] Global variables with the same key name as local variables will be |
|
| 261 | - * overwritten by the local variable. |
|
| 262 | - * |
|
| 263 | - * @param string view filename |
|
| 264 | - * @return string |
|
| 265 | - * @throws Kohana_View_Exception |
|
| 266 | - * @uses View::capture |
|
| 267 | - */ |
|
| 268 | - public function render($file = NULL) |
|
| 269 | - { |
|
| 270 | - if ($file !== NULL) |
|
| 271 | - { |
|
| 272 | - $this->set_filename($file); |
|
| 273 | - } |
|
| 254 | + /** |
|
| 255 | + * Renders the view object to a string. Global and local data are merged |
|
| 256 | + * and extracted to create local variables within the view file. |
|
| 257 | + * |
|
| 258 | + * $output = View::render(); |
|
| 259 | + * |
|
| 260 | + * [!!] Global variables with the same key name as local variables will be |
|
| 261 | + * overwritten by the local variable. |
|
| 262 | + * |
|
| 263 | + * @param string view filename |
|
| 264 | + * @return string |
|
| 265 | + * @throws Kohana_View_Exception |
|
| 266 | + * @uses View::capture |
|
| 267 | + */ |
|
| 268 | + public function render($file = NULL) |
|
| 269 | + { |
|
| 270 | + if ($file !== NULL) |
|
| 271 | + { |
|
| 272 | + $this->set_filename($file); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - if (empty($this->_file)) |
|
| 276 | - { |
|
| 277 | - throw new Kohana_View_Exception('You must set the file to use within your view before rendering'); |
|
| 278 | - } |
|
| 275 | + if (empty($this->_file)) |
|
| 276 | + { |
|
| 277 | + throw new Kohana_View_Exception('You must set the file to use within your view before rendering'); |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - // Combine local and global data and capture the output |
|
| 281 | - return $this->capture($this->_file); |
|
| 282 | - } |
|
| 280 | + // Combine local and global data and capture the output |
|
| 281 | + return $this->capture($this->_file); |
|
| 282 | + } |
|
| 283 | 283 | } // End View |
| 284 | 284 | \ No newline at end of file |
@@ -10,7 +10,8 @@ discard block |
||
| 10 | 10 | * @copyright (c) 2008-2010 Kohana Team |
| 11 | 11 | * @license http://kohanaphp.com/license |
| 12 | 12 | */ |
| 13 | -class Kohana_View_Model { |
|
| 13 | +class Kohana_View_Model |
|
| 14 | +{ |
|
| 14 | 15 | |
| 15 | 16 | // View filename |
| 16 | 17 | protected $_file; |
@@ -28,13 +29,13 @@ discard block |
||
| 28 | 29 | public static function factory($file = NULL, array $data = NULL) |
| 29 | 30 | { |
| 30 | 31 | // Return a raw view object if no template is specified. |
| 31 | - if ($file === FALSE) |
|
| 32 | - return new View(FALSE, $data); |
|
| 32 | + if ($file === FALSE) { |
|
| 33 | + return new View(FALSE, $data); |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | $class = 'View_'.strtr($file, '/', '_'); |
| 35 | 37 | |
| 36 | - if ( ! class_exists($class)) |
|
| 37 | - { |
|
| 38 | + if ( ! class_exists($class)) { |
|
| 38 | 39 | $class = 'View'; |
| 39 | 40 | } |
| 40 | 41 | |
@@ -52,20 +53,16 @@ discard block |
||
| 52 | 53 | */ |
| 53 | 54 | protected function capture($kohana_view_filename) |
| 54 | 55 | { |
| 55 | - if ( ! in_array('kohana.view', stream_get_wrappers())) |
|
| 56 | - { |
|
| 56 | + if ( ! in_array('kohana.view', stream_get_wrappers())) { |
|
| 57 | 57 | stream_wrapper_register('kohana.view', 'View_Stream_Wrapper'); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // Capture the view output |
| 61 | 61 | ob_start(); |
| 62 | 62 | |
| 63 | - try |
|
| 64 | - { |
|
| 63 | + try { |
|
| 65 | 64 | include 'kohana.view://'.$kohana_view_filename; |
| 66 | - } |
|
| 67 | - catch (Exception $e) |
|
| 68 | - { |
|
| 65 | + } catch (Exception $e) { |
|
| 69 | 66 | // Delete the output buffer |
| 70 | 67 | ob_end_clean(); |
| 71 | 68 | |
@@ -90,20 +87,17 @@ discard block |
||
| 90 | 87 | */ |
| 91 | 88 | public function __construct($file = NULL, array $data = NULL) |
| 92 | 89 | { |
| 93 | - if ($file === NULL) |
|
| 94 | - { |
|
| 90 | + if ($file === NULL) { |
|
| 95 | 91 | $foo = explode('_', get_class($this)); |
| 96 | 92 | array_shift($foo); |
| 97 | 93 | $file = strtolower(implode('/', $foo)); |
| 98 | 94 | } |
| 99 | 95 | |
| 100 | - if ($file !== FALSE) |
|
| 101 | - { |
|
| 96 | + if ($file !== FALSE) { |
|
| 102 | 97 | $this->set_filename($file); |
| 103 | 98 | } |
| 104 | 99 | |
| 105 | - if ($data !== NULL) |
|
| 106 | - { |
|
| 100 | + if ($data !== NULL) { |
|
| 107 | 101 | // Add the values to the current data |
| 108 | 102 | $this->set($data); |
| 109 | 103 | } |
@@ -123,16 +117,11 @@ discard block |
||
| 123 | 117 | */ |
| 124 | 118 | public function __get($key) |
| 125 | 119 | { |
| 126 | - if (method_exists($this, $key)) |
|
| 127 | - { |
|
| 120 | + if (method_exists($this, $key)) { |
|
| 128 | 121 | return $this->$key(); |
| 129 | - } |
|
| 130 | - elseif (property_exists($this, $key)) |
|
| 131 | - { |
|
| 122 | + } elseif (property_exists($this, $key)) { |
|
| 132 | 123 | return $this->$key; |
| 133 | - } |
|
| 134 | - else |
|
| 135 | - { |
|
| 124 | + } else { |
|
| 136 | 125 | throw new Kohana_Exception('View variable is not set: :var', |
| 137 | 126 | array(':var' => $key)); |
| 138 | 127 | } |
@@ -161,12 +150,9 @@ discard block |
||
| 161 | 150 | */ |
| 162 | 151 | public function __toString() |
| 163 | 152 | { |
| 164 | - try |
|
| 165 | - { |
|
| 153 | + try { |
|
| 166 | 154 | return $this->render(); |
| 167 | - } |
|
| 168 | - catch (Exception $e) |
|
| 169 | - { |
|
| 155 | + } catch (Exception $e) { |
|
| 170 | 156 | // Display the exception message |
| 171 | 157 | Kohana_Exception::handler($e); |
| 172 | 158 | |
@@ -185,8 +171,7 @@ discard block |
||
| 185 | 171 | */ |
| 186 | 172 | public function set_filename($file) |
| 187 | 173 | { |
| 188 | - if (($path = Kohana::find_file('views', $file)) === FALSE) |
|
| 189 | - { |
|
| 174 | + if (($path = Kohana::find_file('views', $file)) === FALSE) { |
|
| 190 | 175 | throw new Kohana_View_Exception('The requested view :file could not be found', array( |
| 191 | 176 | ':file' => $file, |
| 192 | 177 | )); |
@@ -216,15 +201,11 @@ discard block |
||
| 216 | 201 | */ |
| 217 | 202 | public function set($key, $value = NULL) |
| 218 | 203 | { |
| 219 | - if (is_array($key)) |
|
| 220 | - { |
|
| 221 | - foreach ($key as $name => $value) |
|
| 222 | - { |
|
| 204 | + if (is_array($key)) { |
|
| 205 | + foreach ($key as $name => $value) { |
|
| 223 | 206 | $this->{$name} = $value; |
| 224 | 207 | } |
| 225 | - } |
|
| 226 | - else |
|
| 227 | - { |
|
| 208 | + } else { |
|
| 228 | 209 | $this->{$key} = $value; |
| 229 | 210 | } |
| 230 | 211 | |
@@ -267,13 +248,11 @@ discard block |
||
| 267 | 248 | */ |
| 268 | 249 | public function render($file = NULL) |
| 269 | 250 | { |
| 270 | - if ($file !== NULL) |
|
| 271 | - { |
|
| 251 | + if ($file !== NULL) { |
|
| 272 | 252 | $this->set_filename($file); |
| 273 | 253 | } |
| 274 | 254 | |
| 275 | - if (empty($this->_file)) |
|
| 276 | - { |
|
| 255 | + if (empty($this->_file)) { |
|
| 277 | 256 | throw new Kohana_View_Exception('You must set the file to use within your view before rendering'); |
| 278 | 257 | } |
| 279 | 258 | |
@@ -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)) |
@@ -47,11 +47,9 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function var_page() |
| 49 | 49 | { |
| 50 | - if ( is_string($this->template)) |
|
| 51 | - { |
|
| 50 | + if ( is_string($this->template)) { |
|
| 52 | 51 | $class = 'View_Template_'.$this->template; |
| 53 | - if ( ! class_exists($class)) |
|
| 54 | - { |
|
| 52 | + if ( ! class_exists($class)) { |
|
| 55 | 53 | $class = 'View'; |
| 56 | 54 | } |
| 57 | 55 | $this->template = new $class(); |
@@ -109,8 +107,7 @@ discard block |
||
| 109 | 107 | $this->post_render(); |
| 110 | 108 | |
| 111 | 109 | // Render the template if required |
| 112 | - if ($this->use_template()) |
|
| 113 | - { |
|
| 110 | + if ($this->use_template()) { |
|
| 114 | 111 | $template = $this->var_page(); |
| 115 | 112 | $template->set('var_body', $body); |
| 116 | 113 | return $template->render(); |
@@ -138,27 +135,21 @@ discard block |
||
| 138 | 135 | public function use_template($use_template = null) |
| 139 | 136 | { |
| 140 | 137 | // If we're being called as a setter |
| 141 | - if ($use_template !== null) |
|
| 142 | - { |
|
| 138 | + if ($use_template !== null) { |
|
| 143 | 139 | $this->_use_template = $use_template; |
| 144 | 140 | return $this; |
| 145 | 141 | } |
| 146 | 142 | |
| 147 | 143 | // If an explicit value was set |
| 148 | - if ($this->_use_template !== null) |
|
| 149 | - { |
|
| 144 | + if ($this->_use_template !== null) { |
|
| 150 | 145 | return $this->_use_template; |
| 151 | 146 | } |
| 152 | 147 | |
| 153 | 148 | // Guess based on is_ajax |
| 154 | - if (Request::current()) |
|
| 155 | - { |
|
| 156 | - if (Request::current()->is_ajax()) |
|
| 157 | - { |
|
| 149 | + if (Request::current()) { |
|
| 150 | + if (Request::current()->is_ajax()) { |
|
| 158 | 151 | return false; |
| 159 | - } |
|
| 160 | - else |
|
| 161 | - { |
|
| 152 | + } else { |
|
| 162 | 153 | return true; |
| 163 | 154 | } |
| 164 | 155 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | public $template = 'Global'; |
| 27 | 27 | |
| 28 | 28 | // Whether to render the view within the template or not, null for auto |
| 29 | - protected $_use_template = null; |
|
| 29 | + protected $_use_template = NULL; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Sets a new template to use for this view model. By default template names |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @param string $file If wishing to generate a view to a file |
| 100 | 100 | * @return string The formatted view content |
| 101 | 101 | */ |
| 102 | - public function render($file = null) |
|
| 102 | + public function render($file = NULL) |
|
| 103 | 103 | { |
| 104 | 104 | $this->pre_render(); |
| 105 | 105 | |
@@ -135,17 +135,17 @@ discard block |
||
| 135 | 135 | * @return boolean If called as getter |
| 136 | 136 | * @return View_Layout If called as setter |
| 137 | 137 | */ |
| 138 | - public function use_template($use_template = null) |
|
| 138 | + public function use_template($use_template = NULL) |
|
| 139 | 139 | { |
| 140 | 140 | // If we're being called as a setter |
| 141 | - if ($use_template !== null) |
|
| 141 | + if ($use_template !== NULL) |
|
| 142 | 142 | { |
| 143 | 143 | $this->_use_template = $use_template; |
| 144 | 144 | return $this; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // If an explicit value was set |
| 148 | - if ($this->_use_template !== null) |
|
| 148 | + if ($this->_use_template !== NULL) |
|
| 149 | 149 | { |
| 150 | 150 | return $this->_use_template; |
| 151 | 151 | } |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | { |
| 156 | 156 | if (Request::current()->is_ajax()) |
| 157 | 157 | { |
| 158 | - return false; |
|
| 158 | + return FALSE; |
|
| 159 | 159 | } |
| 160 | 160 | else |
| 161 | 161 | { |
| 162 | - return true; |
|
| 162 | + return TRUE; |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -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 | |
@@ -39,85 +39,85 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | class Kohana_View_Stream_Wrapper |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * Current stream position. |
|
| 44 | - * |
|
| 45 | - * @var int |
|
| 46 | - */ |
|
| 47 | - protected $_pos = 0; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Data for streaming. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - protected $_data; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Stream stats. |
|
| 58 | - * |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - protected $_stat; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Raw output character. Prepend this on any echo variables to |
|
| 65 | - * turn off auto encoding of the output |
|
| 66 | - */ |
|
| 67 | - protected $_raw_output_char = '!'; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The encoding method to use on view output. Only use the method name |
|
| 71 | - */ |
|
| 72 | - protected $_encode_method = 'HTML::chars'; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Opens the script file and converts markup. |
|
| 76 | - */ |
|
| 77 | - public function stream_open($path, $mode, $options, &$opened_path) |
|
| 78 | - { |
|
| 79 | - // get the view script source |
|
| 80 | - $path = str_replace('kohana.view://', '', $path); |
|
| 81 | - $this->_data = file_get_contents($path); |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * If reading the file failed, update our local stat store |
|
| 85 | - * to reflect the real stat of the file, then return on failure |
|
| 86 | - */ |
|
| 87 | - if ($this->_data === false) |
|
| 88 | - { |
|
| 89 | - $this->_stat = stat($path); |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 42 | + /** |
|
| 43 | + * Current stream position. |
|
| 44 | + * |
|
| 45 | + * @var int |
|
| 46 | + */ |
|
| 47 | + protected $_pos = 0; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Data for streaming. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + protected $_data; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Stream stats. |
|
| 58 | + * |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + protected $_stat; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Raw output character. Prepend this on any echo variables to |
|
| 65 | + * turn off auto encoding of the output |
|
| 66 | + */ |
|
| 67 | + protected $_raw_output_char = '!'; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The encoding method to use on view output. Only use the method name |
|
| 71 | + */ |
|
| 72 | + protected $_encode_method = 'HTML::chars'; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Opens the script file and converts markup. |
|
| 76 | + */ |
|
| 77 | + public function stream_open($path, $mode, $options, &$opened_path) |
|
| 78 | + { |
|
| 79 | + // get the view script source |
|
| 80 | + $path = str_replace('kohana.view://', '', $path); |
|
| 81 | + $this->_data = file_get_contents($path); |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * If reading the file failed, update our local stat store |
|
| 85 | + * to reflect the real stat of the file, then return on failure |
|
| 86 | + */ |
|
| 87 | + if ($this->_data === false) |
|
| 88 | + { |
|
| 89 | + $this->_stat = stat($path); |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Escape all variables and convert <?= ?> to long-form <?php echo ?> |
|
| 95 | - * |
|
| 96 | - */ |
|
| 97 | - $regex = '/<\?(\=|php)?(.+?)\?>/s'; |
|
| 98 | - $this->_data = preg_replace_callback($regex, array($this, '_escape_val'), $this->_data); |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * file_get_contents() won't update PHP's stat cache, so we grab a stat |
|
| 102 | - * of the file to prevent additional reads should the script be |
|
| 103 | - * requested again, which will make include() happy. |
|
| 104 | - */ |
|
| 105 | - $this->_stat = stat($path); |
|
| 106 | - |
|
| 107 | - // PHP7.4 requires that we return the accurate value for the filesize, otherwise it does not read the full string |
|
| 93 | + /** |
|
| 94 | + * Escape all variables and convert <?= ?> to long-form <?php echo ?> |
|
| 95 | + * |
|
| 96 | + */ |
|
| 97 | + $regex = '/<\?(\=|php)?(.+?)\?>/s'; |
|
| 98 | + $this->_data = preg_replace_callback($regex, array($this, '_escape_val'), $this->_data); |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * file_get_contents() won't update PHP's stat cache, so we grab a stat |
|
| 102 | + * of the file to prevent additional reads should the script be |
|
| 103 | + * requested again, which will make include() happy. |
|
| 104 | + */ |
|
| 105 | + $this->_stat = stat($path); |
|
| 106 | + |
|
| 107 | + // PHP7.4 requires that we return the accurate value for the filesize, otherwise it does not read the full string |
|
| 108 | 108 | // and then causes a cryptic "unexpected end of file" error |
| 109 | 109 | $this->_stat['size'] = strlen($this->_data); |
| 110 | - return true; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Escapes a variable from template matching |
|
| 115 | - * |
|
| 116 | - * @param array matches |
|
| 117 | - * @return string |
|
| 118 | - */ |
|
| 119 | - protected function _escape_val($matches) |
|
| 120 | - { |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Escapes a variable from template matching |
|
| 115 | + * |
|
| 116 | + * @param array matches |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 119 | + protected function _escape_val($matches) |
|
| 120 | + { |
|
| 121 | 121 | // Start by trimming the echoed string |
| 122 | 122 | $code = trim($matches[2]); |
| 123 | 123 | |
@@ -143,101 +143,101 @@ discard block |
||
| 143 | 143 | // Remove the "turn off escape" character |
| 144 | 144 | return '<?php echo '.substr($var, strlen($this->_raw_output_char), strlen($var)-1).'; ?>'; |
| 145 | 145 | } |
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Included so that __FILE__ returns the appropriate info |
|
| 150 | - * |
|
| 151 | - * @return array |
|
| 152 | - */ |
|
| 153 | - public function url_stat() |
|
| 154 | - { |
|
| 155 | - return $this->_stat; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Reads from the stream. |
|
| 160 | - */ |
|
| 161 | - public function stream_read($count) |
|
| 162 | - { |
|
| 163 | - $ret = substr($this->_data, $this->_pos, $count); |
|
| 164 | - $this->_pos += strlen($ret); |
|
| 165 | - return $ret; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Tells the current position in the stream. |
|
| 170 | - */ |
|
| 171 | - public function stream_tell() |
|
| 172 | - { |
|
| 173 | - return $this->_pos; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Tells if we are at the end of the stream. |
|
| 178 | - */ |
|
| 179 | - public function stream_eof() |
|
| 180 | - { |
|
| 181 | - return $this->_pos >= strlen($this->_data); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Stream statistics. |
|
| 186 | - */ |
|
| 187 | - public function stream_stat() |
|
| 188 | - { |
|
| 189 | - return $this->_stat; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Seek to a specific point in the stream. |
|
| 194 | - */ |
|
| 195 | - public function stream_seek($offset, $whence) |
|
| 196 | - { |
|
| 197 | - switch ($whence) |
|
| 198 | - { |
|
| 199 | - case SEEK_SET: |
|
| 200 | - if ($offset < strlen($this->_data) && $offset >= 0) |
|
| 201 | - { |
|
| 202 | - $this->_pos = $offset; |
|
| 203 | - return true; |
|
| 204 | - } |
|
| 205 | - else |
|
| 206 | - { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - break; |
|
| 210 | - |
|
| 211 | - case SEEK_CUR: |
|
| 212 | - if ($offset >= 0) |
|
| 213 | - { |
|
| 214 | - $this->_pos += $offset; |
|
| 215 | - return true; |
|
| 216 | - } |
|
| 217 | - else |
|
| 218 | - { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - break; |
|
| 222 | - |
|
| 223 | - case SEEK_END: |
|
| 224 | - if (strlen($this->_data) + $offset >= 0) |
|
| 225 | - { |
|
| 226 | - $this->_pos = strlen($this->_data) + $offset; |
|
| 227 | - return true; |
|
| 228 | - } |
|
| 229 | - else |
|
| 230 | - { |
|
| 231 | - return false; |
|
| 232 | - } |
|
| 233 | - break; |
|
| 234 | - |
|
| 235 | - default: |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - public function stream_set_option($option, $arg1, $arg2) |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Included so that __FILE__ returns the appropriate info |
|
| 150 | + * |
|
| 151 | + * @return array |
|
| 152 | + */ |
|
| 153 | + public function url_stat() |
|
| 154 | + { |
|
| 155 | + return $this->_stat; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Reads from the stream. |
|
| 160 | + */ |
|
| 161 | + public function stream_read($count) |
|
| 162 | + { |
|
| 163 | + $ret = substr($this->_data, $this->_pos, $count); |
|
| 164 | + $this->_pos += strlen($ret); |
|
| 165 | + return $ret; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Tells the current position in the stream. |
|
| 170 | + */ |
|
| 171 | + public function stream_tell() |
|
| 172 | + { |
|
| 173 | + return $this->_pos; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Tells if we are at the end of the stream. |
|
| 178 | + */ |
|
| 179 | + public function stream_eof() |
|
| 180 | + { |
|
| 181 | + return $this->_pos >= strlen($this->_data); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Stream statistics. |
|
| 186 | + */ |
|
| 187 | + public function stream_stat() |
|
| 188 | + { |
|
| 189 | + return $this->_stat; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Seek to a specific point in the stream. |
|
| 194 | + */ |
|
| 195 | + public function stream_seek($offset, $whence) |
|
| 196 | + { |
|
| 197 | + switch ($whence) |
|
| 198 | + { |
|
| 199 | + case SEEK_SET: |
|
| 200 | + if ($offset < strlen($this->_data) && $offset >= 0) |
|
| 201 | + { |
|
| 202 | + $this->_pos = $offset; |
|
| 203 | + return true; |
|
| 204 | + } |
|
| 205 | + else |
|
| 206 | + { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + break; |
|
| 210 | + |
|
| 211 | + case SEEK_CUR: |
|
| 212 | + if ($offset >= 0) |
|
| 213 | + { |
|
| 214 | + $this->_pos += $offset; |
|
| 215 | + return true; |
|
| 216 | + } |
|
| 217 | + else |
|
| 218 | + { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + break; |
|
| 222 | + |
|
| 223 | + case SEEK_END: |
|
| 224 | + if (strlen($this->_data) + $offset >= 0) |
|
| 225 | + { |
|
| 226 | + $this->_pos = strlen($this->_data) + $offset; |
|
| 227 | + return true; |
|
| 228 | + } |
|
| 229 | + else |
|
| 230 | + { |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 233 | + break; |
|
| 234 | + |
|
| 235 | + default: |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + public function stream_set_option($option, $arg1, $arg2) |
|
| 241 | 241 | { |
| 242 | 242 | // PHP7.4 requires this be implemented, but we can return FALSE that we don't support any of the options |
| 243 | 243 | // (blocking mode, buffering, etc) |
@@ -84,8 +84,7 @@ discard block |
||
| 84 | 84 | * If reading the file failed, update our local stat store |
| 85 | 85 | * to reflect the real stat of the file, then return on failure |
| 86 | 86 | */ |
| 87 | - if ($this->_data === false) |
|
| 88 | - { |
|
| 87 | + if ($this->_data === false) { |
|
| 89 | 88 | $this->_stat = stat($path); |
| 90 | 89 | return false; |
| 91 | 90 | } |
@@ -126,20 +125,16 @@ discard block |
||
| 126 | 125 | '$this->var_$1', $code); |
| 127 | 126 | |
| 128 | 127 | // If this block is not the special <?= block return |
| 129 | - if ($matches[1] !== '=') |
|
| 130 | - { |
|
| 128 | + if ($matches[1] !== '=') { |
|
| 131 | 129 | return '<?php '. $code . '?>'; |
| 132 | 130 | } |
| 133 | 131 | |
| 134 | 132 | // Remove trailing ; characters |
| 135 | 133 | $var = trim($code, ';'); |
| 136 | 134 | |
| 137 | - if (substr($var, 0, 1) != $this->_raw_output_char) |
|
| 138 | - { |
|
| 135 | + if (substr($var, 0, 1) != $this->_raw_output_char) { |
|
| 139 | 136 | return '<?php echo '.$this->_encode_method.'('.$var.'); ?>'; |
| 140 | - } |
|
| 141 | - else |
|
| 142 | - { |
|
| 137 | + } else { |
|
| 143 | 138 | // Remove the "turn off escape" character |
| 144 | 139 | return '<?php echo '.substr($var, strlen($this->_raw_output_char), strlen($var)-1).'; ?>'; |
| 145 | 140 | } |
@@ -194,40 +189,30 @@ discard block |
||
| 194 | 189 | */ |
| 195 | 190 | public function stream_seek($offset, $whence) |
| 196 | 191 | { |
| 197 | - switch ($whence) |
|
| 198 | - { |
|
| 192 | + switch ($whence) { |
|
| 199 | 193 | case SEEK_SET: |
| 200 | - if ($offset < strlen($this->_data) && $offset >= 0) |
|
| 201 | - { |
|
| 194 | + if ($offset < strlen($this->_data) && $offset >= 0) { |
|
| 202 | 195 | $this->_pos = $offset; |
| 203 | 196 | return true; |
| 204 | - } |
|
| 205 | - else |
|
| 206 | - { |
|
| 197 | + } else { |
|
| 207 | 198 | return false; |
| 208 | 199 | } |
| 209 | 200 | break; |
| 210 | 201 | |
| 211 | 202 | case SEEK_CUR: |
| 212 | - if ($offset >= 0) |
|
| 213 | - { |
|
| 203 | + if ($offset >= 0) { |
|
| 214 | 204 | $this->_pos += $offset; |
| 215 | 205 | return true; |
| 216 | - } |
|
| 217 | - else |
|
| 218 | - { |
|
| 206 | + } else { |
|
| 219 | 207 | return false; |
| 220 | 208 | } |
| 221 | 209 | break; |
| 222 | 210 | |
| 223 | 211 | case SEEK_END: |
| 224 | - if (strlen($this->_data) + $offset >= 0) |
|
| 225 | - { |
|
| 212 | + if (strlen($this->_data) + $offset >= 0) { |
|
| 226 | 213 | $this->_pos = strlen($this->_data) + $offset; |
| 227 | 214 | return true; |
| 228 | - } |
|
| 229 | - else |
|
| 230 | - { |
|
| 215 | + } else { |
|
| 231 | 216 | return false; |
| 232 | 217 | } |
| 233 | 218 | break; |
@@ -238,7 +223,7 @@ discard block |
||
| 238 | 223 | } |
| 239 | 224 | |
| 240 | 225 | public function stream_set_option($option, $arg1, $arg2) |
| 241 | - { |
|
| 226 | + { |
|
| 242 | 227 | // PHP7.4 requires this be implemented, but we can return FALSE that we don't support any of the options |
| 243 | 228 | // (blocking mode, buffering, etc) |
| 244 | 229 | return FALSE; |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | * If reading the file failed, update our local stat store |
| 85 | 85 | * to reflect the real stat of the file, then return on failure |
| 86 | 86 | */ |
| 87 | - if ($this->_data === false) |
|
| 87 | + if ($this->_data === FALSE) |
|
| 88 | 88 | { |
| 89 | 89 | $this->_stat = stat($path); |
| 90 | - return false; |
|
| 90 | + return FALSE; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | // PHP7.4 requires that we return the accurate value for the filesize, otherwise it does not read the full string |
| 108 | 108 | // and then causes a cryptic "unexpected end of file" error |
| 109 | 109 | $this->_stat['size'] = strlen($this->_data); |
| 110 | - return true; |
|
| 110 | + return TRUE; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | if ($offset < strlen($this->_data) && $offset >= 0) |
| 201 | 201 | { |
| 202 | 202 | $this->_pos = $offset; |
| 203 | - return true; |
|
| 203 | + return TRUE; |
|
| 204 | 204 | } |
| 205 | 205 | else |
| 206 | 206 | { |
| 207 | - return false; |
|
| 207 | + return FALSE; |
|
| 208 | 208 | } |
| 209 | 209 | break; |
| 210 | 210 | |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | if ($offset >= 0) |
| 213 | 213 | { |
| 214 | 214 | $this->_pos += $offset; |
| 215 | - return true; |
|
| 215 | + return TRUE; |
|
| 216 | 216 | } |
| 217 | 217 | else |
| 218 | 218 | { |
| 219 | - return false; |
|
| 219 | + return FALSE; |
|
| 220 | 220 | } |
| 221 | 221 | break; |
| 222 | 222 | |
@@ -224,16 +224,16 @@ discard block |
||
| 224 | 224 | if (strlen($this->_data) + $offset >= 0) |
| 225 | 225 | { |
| 226 | 226 | $this->_pos = strlen($this->_data) + $offset; |
| 227 | - return true; |
|
| 227 | + return TRUE; |
|
| 228 | 228 | } |
| 229 | 229 | else |
| 230 | 230 | { |
| 231 | - return false; |
|
| 231 | + return FALSE; |
|
| 232 | 232 | } |
| 233 | 233 | break; |
| 234 | 234 | |
| 235 | 235 | default: |
| 236 | - return false; |
|
| 236 | + return FALSE; |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
@@ -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> |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | * @link https://github.com/ingenerator/koharness |
| 8 | 8 | */ |
| 9 | 9 | return array( |
| 10 | - 'modules' => array( |
|
| 10 | + 'modules' => array( |
|
| 11 | 11 | 'kohana-view' => __DIR__, |
| 12 | - ) |
|
| 12 | + ) |
|
| 13 | 13 | ); |
@@ -14,4 +14,4 @@ |
||
| 14 | 14 | * The ViewFactory creates view classes, to allow stubbing of views for testing and easier extension in applications. |
| 15 | 15 | * |
| 16 | 16 | */ |
| 17 | -class ViewFactory extends Ingenerator\ViewFactory{} |
|
| 18 | 17 | \ No newline at end of file |
| 18 | +class ViewFactory extends Ingenerator\ViewFactory {} |
|
| 19 | 19 | \ No newline at end of file |
@@ -14,4 +14,6 @@ |
||
| 14 | 14 | * The ViewFactory creates view classes, to allow stubbing of views for testing and easier extension in applications. |
| 15 | 15 | * |
| 16 | 16 | */ |
| 17 | -class ViewFactory extends Ingenerator\ViewFactory{} |
|
| 18 | 17 | \ No newline at end of file |
| 18 | +class ViewFactory extends Ingenerator\ViewFactory |
|
| 19 | +{ |
|
| 20 | +} |
|
| 19 | 21 | \ No newline at end of file |
@@ -1,3 +1,5 @@ |
||
| 1 | 1 | <?php defined('SYSPATH') or die('No direct script access.'); |
| 2 | 2 | |
| 3 | -class View_Stream_Wrapper extends Kohana_View_Stream_Wrapper {} |
|
| 3 | +class View_Stream_Wrapper extends Kohana_View_Stream_Wrapper |
|
| 4 | +{ |
|
| 5 | +} |
|
@@ -1,3 +1,5 @@ |
||
| 1 | 1 | <?php defined('SYSPATH') or die('No direct script access.'); |
| 2 | 2 | |
| 3 | -class View_Model extends Kohana_View_Model {} |
|
| 3 | +class View_Model extends Kohana_View_Model |
|
| 4 | +{ |
|
| 5 | +} |
|
@@ -18,42 +18,42 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class ViewFactory { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Create and return a view of the specified type |
|
| 23 | - * |
|
| 24 | - * @param string $class name of the view class to create |
|
| 25 | - * @param array $data array of data to pass to the view |
|
| 26 | - * |
|
| 27 | - * @return \View |
|
| 28 | - * @throws \View_Exception if the class is not defined |
|
| 29 | - */ |
|
| 30 | - public function create($class, $data = array()) |
|
| 31 | - { |
|
| 32 | - // Check the view class exists |
|
| 33 | - if ( ! class_exists($class)) |
|
| 34 | - { |
|
| 35 | - throw new \View_Exception("View class $class does not exist"); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // Temporary fix to map template names for namespaced classes |
|
| 39 | - //@todo: Refactor the existing factory methods and classes to support namespaces |
|
| 40 | - if ('\\View\\' === substr($class, 0, 6)) |
|
| 41 | - { |
|
| 42 | - // Strip the \View\ prefix |
|
| 43 | - $template = substr($class, 6); |
|
| 44 | - |
|
| 45 | - // Exchange namespace separators for directory separators |
|
| 46 | - $template = str_replace('\\', DIRECTORY_SEPARATOR, $template); |
|
| 47 | - |
|
| 48 | - // Lowercase the View file name |
|
| 49 | - $template = strtolower($template); |
|
| 50 | - } |
|
| 51 | - else |
|
| 52 | - { |
|
| 53 | - $template = NULL; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return new $class($template, $data); |
|
| 57 | - } |
|
| 21 | + /** |
|
| 22 | + * Create and return a view of the specified type |
|
| 23 | + * |
|
| 24 | + * @param string $class name of the view class to create |
|
| 25 | + * @param array $data array of data to pass to the view |
|
| 26 | + * |
|
| 27 | + * @return \View |
|
| 28 | + * @throws \View_Exception if the class is not defined |
|
| 29 | + */ |
|
| 30 | + public function create($class, $data = array()) |
|
| 31 | + { |
|
| 32 | + // Check the view class exists |
|
| 33 | + if ( ! class_exists($class)) |
|
| 34 | + { |
|
| 35 | + throw new \View_Exception("View class $class does not exist"); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // Temporary fix to map template names for namespaced classes |
|
| 39 | + //@todo: Refactor the existing factory methods and classes to support namespaces |
|
| 40 | + if ('\\View\\' === substr($class, 0, 6)) |
|
| 41 | + { |
|
| 42 | + // Strip the \View\ prefix |
|
| 43 | + $template = substr($class, 6); |
|
| 44 | + |
|
| 45 | + // Exchange namespace separators for directory separators |
|
| 46 | + $template = str_replace('\\', DIRECTORY_SEPARATOR, $template); |
|
| 47 | + |
|
| 48 | + // Lowercase the View file name |
|
| 49 | + $template = strtolower($template); |
|
| 50 | + } |
|
| 51 | + else |
|
| 52 | + { |
|
| 53 | + $template = NULL; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return new $class($template, $data); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -16,7 +16,8 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @package Ingenerator |
| 18 | 18 | */ |
| 19 | -class ViewFactory { |
|
| 19 | +class ViewFactory |
|
| 20 | +{ |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Create and return a view of the specified type |
@@ -30,15 +31,13 @@ discard block |
||
| 30 | 31 | public function create($class, $data = array()) |
| 31 | 32 | { |
| 32 | 33 | // Check the view class exists |
| 33 | - if ( ! class_exists($class)) |
|
| 34 | - { |
|
| 34 | + if ( ! class_exists($class)) { |
|
| 35 | 35 | throw new \View_Exception("View class $class does not exist"); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Temporary fix to map template names for namespaced classes |
| 39 | 39 | //@todo: Refactor the existing factory methods and classes to support namespaces |
| 40 | - if ('\\View\\' === substr($class, 0, 6)) |
|
| 41 | - { |
|
| 40 | + if ('\\View\\' === substr($class, 0, 6)) { |
|
| 42 | 41 | // Strip the \View\ prefix |
| 43 | 42 | $template = substr($class, 6); |
| 44 | 43 | |
@@ -47,9 +46,7 @@ discard block |
||
| 47 | 46 | |
| 48 | 47 | // Lowercase the View file name |
| 49 | 48 | $template = strtolower($template); |
| 50 | - } |
|
| 51 | - else |
|
| 52 | - { |
|
| 49 | + } else { |
|
| 53 | 50 | $template = NULL; |
| 54 | 51 | } |
| 55 | 52 | |