@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * Load a module file |
102 | 102 | * |
103 | - * @param $file |
|
103 | + * @param string $file |
|
104 | 104 | * @param $path |
105 | 105 | * @param string $type |
106 | 106 | * @param bool $result |
@@ -333,8 +333,8 @@ discard block |
||
333 | 333 | /** |
334 | 334 | * Returns the path to the module and it's specified folder. |
335 | 335 | * |
336 | - * @param $module string The name of the module (must match the folder name) |
|
337 | - * @param $folder string The folder name to search for. (Optional) |
|
336 | + * @param string $module string The name of the module (must match the folder name) |
|
337 | + * @param string $folder string The folder name to search for. (Optional) |
|
338 | 338 | * |
339 | 339 | * @return string The path, relative to the front controller, or false if the folder was not found |
340 | 340 | */ |
@@ -37,20 +37,20 @@ discard block |
||
37 | 37 | * available within the Router class, before get_instance() is available we'll have to |
38 | 38 | * live with it for now. |
39 | 39 | */ |
40 | -include APPPATH . 'config/config.php'; |
|
40 | +include APPPATH.'config/config.php'; |
|
41 | 41 | |
42 | -if ( isset( $config ) ) |
|
42 | +if (isset($config)) |
|
43 | 43 | { |
44 | - if ( is_array( $config['modules_locations'] ) ) |
|
44 | + if (is_array($config['modules_locations'])) |
|
45 | 45 | { |
46 | 46 | Modules::$locations = $config['modules_locations']; |
47 | 47 | } |
48 | 48 | else |
49 | 49 | { |
50 | - Modules::$locations = array( APPPATH . 'modules/' => '../modules/' ); |
|
50 | + Modules::$locations = array(APPPATH.'modules/' => '../modules/'); |
|
51 | 51 | } |
52 | 52 | |
53 | - unset( $config ); |
|
53 | + unset($config); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | |
@@ -107,17 +107,17 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return bool |
109 | 109 | */ |
110 | - public static function load_file( $file, $path, $type = 'other', $result = TRUE ) |
|
110 | + public static function load_file($file, $path, $type = 'other', $result = TRUE) |
|
111 | 111 | { |
112 | 112 | |
113 | - $file = str_replace( '.php', '', $file ); |
|
114 | - $location = $path . $file . '.php'; |
|
113 | + $file = str_replace('.php', '', $file); |
|
114 | + $location = $path.$file.'.php'; |
|
115 | 115 | |
116 | - if ( $type === 'other' ) |
|
116 | + if ($type === 'other') |
|
117 | 117 | { |
118 | - if ( class_exists( $file, FALSE ) ) |
|
118 | + if (class_exists($file, FALSE)) |
|
119 | 119 | { |
120 | - log_message( 'debug', "File already loaded: {$location}" ); |
|
120 | + log_message('debug', "File already loaded: {$location}"); |
|
121 | 121 | |
122 | 122 | return $result; |
123 | 123 | } |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | /* load config or language array */ |
130 | 130 | include $location; |
131 | 131 | |
132 | - if ( ! isset( $$type ) OR ! is_array( $$type ) ) |
|
132 | + if ( ! isset($$type) OR ! is_array($$type)) |
|
133 | 133 | { |
134 | - show_error( "{$location} does not contain a valid {$type} array" ); |
|
134 | + show_error("{$location} does not contain a valid {$type} array"); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | $result = $$type; |
138 | 138 | } |
139 | - log_message( 'debug', "File loaded: {$location}" ); |
|
139 | + log_message('debug', "File loaded: {$location}"); |
|
140 | 140 | |
141 | 141 | return $result; |
142 | 142 | } |
@@ -156,64 +156,64 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return array [ {full_path_to_file}, {file} ] or FALSE |
158 | 158 | */ |
159 | - public static function find( $file, $module, $base ) |
|
159 | + public static function find($file, $module, $base) |
|
160 | 160 | { |
161 | - if (! is_string($module) || ! is_string($file) || ! is_string($base)) |
|
161 | + if ( ! is_string($module) || ! is_string($file) || ! is_string($base)) |
|
162 | 162 | { |
163 | 163 | throw new \InvalidArgumentException('Argument must be a string for Modules::find()'); |
164 | 164 | } |
165 | 165 | |
166 | 166 | // Find the actual file name. It will always be the last element. |
167 | - $segments = explode( '/', $file ); |
|
168 | - $file = array_pop( $segments ); |
|
169 | - $file_ext = ( pathinfo( $file, PATHINFO_EXTENSION ) ) ? $file : $file . '.php'; |
|
167 | + $segments = explode('/', $file); |
|
168 | + $file = array_pop($segments); |
|
169 | + $file_ext = (pathinfo($file, PATHINFO_EXTENSION)) ? $file : $file.'.php'; |
|
170 | 170 | |
171 | 171 | // Put the pieces back to get the path. |
172 | - $path = implode( '/', $segments ) . '/'; |
|
173 | - $base = rtrim( $base, '/' ) . '/'; |
|
172 | + $path = implode('/', $segments).'/'; |
|
173 | + $base = rtrim($base, '/').'/'; |
|
174 | 174 | |
175 | 175 | // Look in any possible module locations based on the string segments. |
176 | 176 | $modules = array(); |
177 | - if ( ! empty( $module ) ) |
|
177 | + if ( ! empty($module)) |
|
178 | 178 | { |
179 | - $modules[ $module ] = $path; |
|
179 | + $modules[$module] = $path; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Collect the modules from the segments |
183 | - if ( ! empty( $segments ) ) |
|
183 | + if ( ! empty($segments)) |
|
184 | 184 | { |
185 | - $modules[ array_shift( $segments ) ] = ltrim( implode( '/', $segments ) . '/', '/' ); |
|
185 | + $modules[array_shift($segments)] = ltrim(implode('/', $segments).'/', '/'); |
|
186 | 186 | } |
187 | 187 | |
188 | - foreach ( self::$locations as $location ) |
|
188 | + foreach (self::$locations as $location) |
|
189 | 189 | { |
190 | 190 | |
191 | - foreach ( $modules as $module => $subpath ) |
|
191 | + foreach ($modules as $module => $subpath) |
|
192 | 192 | { |
193 | 193 | // Combine the elements to make an actual path to the file |
194 | - $fullpath = str_replace( '//', '/', "{$location}{$module}/{$base}{$subpath}" ); |
|
194 | + $fullpath = str_replace('//', '/', "{$location}{$module}/{$base}{$subpath}"); |
|
195 | 195 | |
196 | 196 | // If it starts with a '/' assume it's a full path already |
197 | - if ( substr( $path, 0, 1 ) == '/' && strlen( $path ) > 1 ) |
|
197 | + if (substr($path, 0, 1) == '/' && strlen($path) > 1) |
|
198 | 198 | { |
199 | 199 | $fullpath = $path; |
200 | 200 | } |
201 | 201 | |
202 | 202 | // Libraries are a special consideration since they are |
203 | 203 | // frequently ucfirst. |
204 | - if ( $base == 'libraries/' AND is_file( $fullpath . ucfirst( $file_ext ) ) ) |
|
204 | + if ($base == 'libraries/' AND is_file($fullpath.ucfirst($file_ext))) |
|
205 | 205 | { |
206 | - return array( $fullpath, ucfirst( $file ) ); |
|
206 | + return array($fullpath, ucfirst($file)); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( is_file( $fullpath . $file_ext ) ) |
|
209 | + if (is_file($fullpath.$file_ext)) |
|
210 | 210 | { |
211 | - return array( $fullpath, $file ); |
|
211 | + return array($fullpath, $file); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - return array( FALSE, $file ); |
|
216 | + return array(FALSE, $file); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | //-------------------------------------------------------------------- |
@@ -225,33 +225,33 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public static function listModules() |
227 | 227 | { |
228 | - if ( ! function_exists( 'directory_map' ) ) |
|
228 | + if ( ! function_exists('directory_map')) |
|
229 | 229 | { |
230 | - require BASEPATH . 'helpers/directory_helper.php'; |
|
230 | + require BASEPATH.'helpers/directory_helper.php'; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | $map = array(); |
234 | 234 | |
235 | - foreach ( self::$locations as $folder ) |
|
235 | + foreach (self::$locations as $folder) |
|
236 | 236 | { |
237 | 237 | |
238 | - $dirs = directory_map( $folder, 1 ); |
|
239 | - if ( ! is_array( $dirs ) ) |
|
238 | + $dirs = directory_map($folder, 1); |
|
239 | + if ( ! is_array($dirs)) |
|
240 | 240 | { |
241 | 241 | $dirs = array(); |
242 | 242 | } |
243 | 243 | |
244 | - $map = array_merge( $map, $dirs ); |
|
244 | + $map = array_merge($map, $dirs); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | // Clean out any html or php files |
248 | - if ( $count = count( $map ) ) |
|
248 | + if ($count = count($map)) |
|
249 | 249 | { |
250 | - for ( $i = 0; $i < $count; $i ++ ) |
|
250 | + for ($i = 0; $i < $count; $i++) |
|
251 | 251 | { |
252 | - if ( strpos( $map[ $i ], '.html' ) !== FALSE || strpos( $map[ $i ], '.php' ) !== FALSE ) |
|
252 | + if (strpos($map[$i], '.html') !== FALSE || strpos($map[$i], '.php') !== FALSE) |
|
253 | 253 | { |
254 | - unset( $map[ $i ] ); |
|
254 | + unset($map[$i]); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | } |
@@ -278,17 +278,17 @@ discard block |
||
278 | 278 | * |
279 | 279 | * @return boolean |
280 | 280 | */ |
281 | - public static function controllerExists($controller, $module ) |
|
281 | + public static function controllerExists($controller, $module) |
|
282 | 282 | { |
283 | - if (! is_string($module) || ! is_string($controller)) |
|
283 | + if ( ! is_string($module) || ! is_string($controller)) |
|
284 | 284 | { |
285 | 285 | throw new \InvalidArgumentException('Argument must be a string for Modules::controllerExists()'); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Look in all module paths |
289 | - foreach ( self::$locations as $folder ) |
|
289 | + foreach (self::$locations as $folder) |
|
290 | 290 | { |
291 | - if ( is_file( "{$folder}{$module}/controllers/{$controller}.php" ) ) |
|
291 | + if (is_file("{$folder}{$module}/controllers/{$controller}.php")) |
|
292 | 292 | { |
293 | 293 | return TRUE; |
294 | 294 | } |
@@ -308,18 +308,18 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @return string The full path to the file, or false if the file was not found |
310 | 310 | */ |
311 | - public static function filePath( $module, $folder, $file ) |
|
311 | + public static function filePath($module, $folder, $file) |
|
312 | 312 | { |
313 | - if (! is_string($module) || ! is_string($folder) || ! is_string($file)) |
|
313 | + if ( ! is_string($module) || ! is_string($folder) || ! is_string($file)) |
|
314 | 314 | { |
315 | 315 | throw new \InvalidArgumentException('Argument must be a string for Modules::filePath()'); |
316 | 316 | } |
317 | 317 | |
318 | - foreach ( self::$locations as $location ) |
|
318 | + foreach (self::$locations as $location) |
|
319 | 319 | { |
320 | 320 | $test_file = "{$location}{$module}/{$folder}/{$file}"; |
321 | 321 | |
322 | - if ( is_file( $test_file ) ) |
|
322 | + if (is_file($test_file)) |
|
323 | 323 | { |
324 | 324 | return $test_file; |
325 | 325 | } |
@@ -338,23 +338,23 @@ discard block |
||
338 | 338 | * |
339 | 339 | * @return string The path, relative to the front controller, or false if the folder was not found |
340 | 340 | */ |
341 | - public static function path( $module, $folder = null ) |
|
341 | + public static function path($module, $folder = null) |
|
342 | 342 | { |
343 | - if (! is_string($module) || (! is_string($folder) && !is_null($folder) ) ) |
|
343 | + if ( ! is_string($module) || ( ! is_string($folder) && ! is_null($folder))) |
|
344 | 344 | { |
345 | 345 | throw new \InvalidArgumentException('Argument must be a string for Modules::path()'); |
346 | 346 | } |
347 | 347 | |
348 | - foreach ( self::$locations as $module_folder ) |
|
348 | + foreach (self::$locations as $module_folder) |
|
349 | 349 | { |
350 | - if ( is_dir( $module_folder . $module ) ) |
|
350 | + if (is_dir($module_folder.$module)) |
|
351 | 351 | { |
352 | - if ( ! empty( $folder ) && is_dir( "{$module_folder}{$module}/{$folder}" ) ) |
|
352 | + if ( ! empty($folder) && is_dir("{$module_folder}{$module}/{$folder}")) |
|
353 | 353 | { |
354 | 354 | return "{$module_folder}{$module}/{$folder}/"; |
355 | 355 | } |
356 | 356 | |
357 | - return $module_folder . $module . '/'; |
|
357 | + return $module_folder.$module.'/'; |
|
358 | 358 | } |
359 | 359 | } |
360 | 360 | |
@@ -372,58 +372,58 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @return array An associative array, like: array('module_name' => array('folder' => array('file1', 'file2'))) |
374 | 374 | */ |
375 | - public static function files( $module_name = NULL, $module_folder = NULL ) |
|
375 | + public static function files($module_name = NULL, $module_folder = NULL) |
|
376 | 376 | { |
377 | - if ( ! function_exists( 'directory_map' ) ) |
|
377 | + if ( ! function_exists('directory_map')) |
|
378 | 378 | { |
379 | - require BASEPATH . 'helpers/directory_helper.php'; |
|
379 | + require BASEPATH.'helpers/directory_helper.php'; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | $files = array(); |
383 | 383 | |
384 | - foreach ( self::$locations as $path ) |
|
384 | + foreach (self::$locations as $path) |
|
385 | 385 | { |
386 | 386 | |
387 | 387 | // Only map the whole modules directory if $module_name isn't passed |
388 | - if ( empty( $module_name ) ) |
|
388 | + if (empty($module_name)) |
|
389 | 389 | { |
390 | - $modules = directory_map( $path ); |
|
390 | + $modules = directory_map($path); |
|
391 | 391 | } |
392 | 392 | // Only map the $module_name directory if it exists |
393 | - elseif ( is_dir( $path . $module_name ) ) |
|
393 | + elseif (is_dir($path.$module_name)) |
|
394 | 394 | { |
395 | - $path = $path . $module_name; |
|
396 | - $modules[ $module_name ] = directory_map( $path ); |
|
395 | + $path = $path.$module_name; |
|
396 | + $modules[$module_name] = directory_map($path); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | // If the element is not an array, it's a file, so ignore it. |
400 | 400 | // Otherwise it is assumed to be a module. |
401 | - if ( empty( $modules ) || ! is_array( $modules ) ) |
|
401 | + if (empty($modules) || ! is_array($modules)) |
|
402 | 402 | { |
403 | 403 | continue; |
404 | 404 | } |
405 | 405 | |
406 | - foreach ( $modules as $mod_name => $values ) |
|
406 | + foreach ($modules as $mod_name => $values) |
|
407 | 407 | { |
408 | - if ( is_array( $values ) ) |
|
408 | + if (is_array($values)) |
|
409 | 409 | { |
410 | 410 | // Add just the specified folder for this module |
411 | - if ( ! empty( $module_folder ) && isset( $values[ $module_folder .'/' ] ) && count( $values[ $module_folder .'/' ] ) ) |
|
411 | + if ( ! empty($module_folder) && isset($values[$module_folder.'/']) && count($values[$module_folder.'/'])) |
|
412 | 412 | { |
413 | - $files[ $mod_name ] = array( |
|
414 | - $module_folder .'/' => $values[ $module_folder .'/' ], |
|
413 | + $files[$mod_name] = array( |
|
414 | + $module_folder.'/' => $values[$module_folder.'/'], |
|
415 | 415 | ); |
416 | 416 | } |
417 | 417 | // Add the entire module |
418 | - elseif ( empty( $module_folder ) ) |
|
418 | + elseif (empty($module_folder)) |
|
419 | 419 | { |
420 | - $files[ $mod_name ] = $values; |
|
420 | + $files[$mod_name] = $values; |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
425 | 425 | |
426 | - return count( $files ) ? $files : null; |
|
426 | + return count($files) ? $files : null; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | //-------------------------------------------------------------------- |
@@ -436,37 +436,37 @@ discard block |
||
436 | 436 | * |
437 | 437 | * @return array |
438 | 438 | */ |
439 | - public static function parse_routes( $module, $uri ) |
|
439 | + public static function parse_routes($module, $uri) |
|
440 | 440 | { |
441 | 441 | |
442 | 442 | /* load the route file */ |
443 | - if ( ! isset( self::$routes[ $module ] ) ) |
|
443 | + if ( ! isset(self::$routes[$module])) |
|
444 | 444 | { |
445 | - if ( list( $path ) = self::find( 'routes', $module, 'config/' ) AND $path ) |
|
445 | + if (list($path) = self::find('routes', $module, 'config/') AND $path) |
|
446 | 446 | { |
447 | - self::$routes[ $module ] = self::load_file( 'routes', $path, 'route' ); |
|
447 | + self::$routes[$module] = self::load_file('routes', $path, 'route'); |
|
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | - if ( ! isset( self::$routes[ $module ] ) ) |
|
451 | + if ( ! isset(self::$routes[$module])) |
|
452 | 452 | { |
453 | 453 | return; |
454 | 454 | } |
455 | 455 | |
456 | 456 | /* parse module routes */ |
457 | - foreach ( self::$routes[ $module ] as $key => $val ) |
|
457 | + foreach (self::$routes[$module] as $key => $val) |
|
458 | 458 | { |
459 | 459 | |
460 | - $key = str_replace( array( ':any', ':num' ), array( '.+', '[0-9]+' ), $key ); |
|
460 | + $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); |
|
461 | 461 | |
462 | - if ( preg_match( '#^' . $key . '$#', $uri ) ) |
|
462 | + if (preg_match('#^'.$key.'$#', $uri)) |
|
463 | 463 | { |
464 | - if ( strpos( $val, '$' ) !== FALSE AND strpos( $key, '(' ) !== FALSE ) |
|
464 | + if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) |
|
465 | 465 | { |
466 | - $val = preg_replace( '#^' . $key . '$#', $val, $uri ); |
|
466 | + $val = preg_replace('#^'.$key.'$#', $val, $uri); |
|
467 | 467 | } |
468 | 468 | |
469 | - return explode( '/', $module . '/' . $val ); |
|
469 | + return explode('/', $module.'/'.$val); |
|
470 | 470 | } |
471 | 471 | } |
472 | 472 | } |
@@ -482,17 +482,17 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @param $class |
484 | 484 | */ |
485 | - public static function autoload( $class ) |
|
485 | + public static function autoload($class) |
|
486 | 486 | { |
487 | 487 | |
488 | 488 | /* don't autoload CI_ prefixed classes or those using the config subclass_prefix */ |
489 | - if ( strstr( $class, 'CI_' ) OR strstr( $class, config_item( 'subclass_prefix' ) ) ) |
|
489 | + if (strstr($class, 'CI_') OR strstr($class, config_item('subclass_prefix'))) |
|
490 | 490 | { |
491 | 491 | return; |
492 | 492 | } |
493 | 493 | |
494 | 494 | /* autoload core classes */ |
495 | - if ( is_file( $location = APPPATH . 'core/' . $class . '.php' ) ) |
|
495 | + if (is_file($location = APPPATH.'core/'.$class.'.php')) |
|
496 | 496 | { |
497 | 497 | include_once $location; |
498 | 498 | |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | } |
501 | 501 | |
502 | 502 | /* autoload library classes */ |
503 | - if ( is_file( $location = APPPATH . 'libraries/' . $class . '.php' ) ) |
|
503 | + if (is_file($location = APPPATH.'libraries/'.$class.'.php')) |
|
504 | 504 | { |
505 | 505 | include_once $location; |
506 | 506 |
@@ -44,8 +44,7 @@ discard block |
||
44 | 44 | if ( is_array( $config['modules_locations'] ) ) |
45 | 45 | { |
46 | 46 | Modules::$locations = $config['modules_locations']; |
47 | - } |
|
48 | - else |
|
47 | + } else |
|
49 | 48 | { |
50 | 49 | Modules::$locations = array( APPPATH . 'modules/' => '../modules/' ); |
51 | 50 | } |
@@ -122,8 +121,7 @@ discard block |
||
122 | 121 | return $result; |
123 | 122 | } |
124 | 123 | include_once $location; |
125 | - } |
|
126 | - else |
|
124 | + } else |
|
127 | 125 | { |
128 | 126 | |
129 | 127 | /* load config or language array */ |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * // Returns http://mysite.com/news |
195 | 195 | * site_url( Route::named('blog') ); |
196 | 196 | * |
197 | - * @param [type] $name [description] |
|
198 | - * @return [type] [description] |
|
197 | + * @param string $name [description] |
|
198 | + * @return string [description] |
|
199 | 199 | */ |
200 | 200 | public static function named($name) |
201 | 201 | { |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | /** |
280 | 280 | * Specifies a route that is only available to GET requests. |
281 | 281 | * |
282 | - * @param $from |
|
283 | - * @param $to |
|
282 | + * @param string $from |
|
283 | + * @param string $to |
|
284 | 284 | * @param array $options |
285 | 285 | */ |
286 | 286 | public function get($from, $to, $options = []) |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | /** |
296 | 296 | * Specifies a route that is only available to POST requests. |
297 | 297 | * |
298 | - * @param $from |
|
299 | - * @param $to |
|
298 | + * @param string $from |
|
299 | + * @param string $to |
|
300 | 300 | * @param array $options |
301 | 301 | */ |
302 | 302 | public function post($from, $to, $options = []) |
@@ -311,8 +311,8 @@ discard block |
||
311 | 311 | /** |
312 | 312 | * Specifies a route that is only available to PUT requests. |
313 | 313 | * |
314 | - * @param $from |
|
315 | - * @param $to |
|
314 | + * @param string $from |
|
315 | + * @param string $to |
|
316 | 316 | * @param array $options |
317 | 317 | */ |
318 | 318 | public function put($from, $to, $options = []) |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | /** |
328 | 328 | * Specifies a route that is only available to DELETE requests. |
329 | 329 | * |
330 | - * @param $from |
|
331 | - * @param $to |
|
330 | + * @param string $from |
|
331 | + * @param string $to |
|
332 | 332 | * @param array $options |
333 | 333 | */ |
334 | 334 | public function delete($from, $to, $options = []) |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | /** |
376 | 376 | * Specifies a route that is only available to OPTIONS requests. |
377 | 377 | * |
378 | - * @param $from |
|
379 | - * @param $to |
|
378 | + * @param string $from |
|
379 | + * @param string $to |
|
380 | 380 | * @param array $options |
381 | 381 | */ |
382 | 382 | public function options($from, $to, $options = []) |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | * Limits the routes to a specified ENVIRONMENT or they won't run. |
501 | 501 | * |
502 | 502 | * @param $env |
503 | - * @param callable $callback |
|
503 | + * @param \Closure $callback |
|
504 | 504 | * |
505 | 505 | * @return bool|null |
506 | 506 | */ |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | { |
163 | 163 | // Ensure consistency |
164 | 164 | $name = trim($name, '{} '); |
165 | - $pattern = '(' . trim($pattern, '() ') . ')'; |
|
165 | + $pattern = '('.trim($pattern, '() ').')'; |
|
166 | 166 | |
167 | 167 | // Not here? Add it and leave... |
168 | - if (! array_key_exists($name, $this->constraints)) { |
|
168 | + if ( ! array_key_exists($name, $this->constraints)) { |
|
169 | 169 | $this->constraints[$name] = $pattern; |
170 | 170 | |
171 | 171 | return; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | // To register a route, we'll set a flag so that our router |
233 | 233 | // so it will see the groupname. |
234 | - $this->group = ltrim($old_group . '/' . $name, '/'); |
|
234 | + $this->group = ltrim($old_group.'/'.$name, '/'); |
|
235 | 235 | |
236 | 236 | call_user_func($callback); |
237 | 237 | |
@@ -429,24 +429,23 @@ discard block |
||
429 | 429 | // If a new module was specified, simply put that path |
430 | 430 | // in front of the controller. |
431 | 431 | if (isset($options['module'])) { |
432 | - $new_name = $options['module'] . '/' . $new_name; |
|
432 | + $new_name = $options['module'].'/'.$new_name; |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | // In order to allow customization of allowed id values |
436 | 436 | // we need someplace to store them. |
437 | - $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : |
|
438 | - '(:any)'; |
|
437 | + $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : '(:any)'; |
|
439 | 438 | |
440 | 439 | if (isset($options['constraint'])) { |
441 | 440 | $id = $options['constraint']; |
442 | 441 | } |
443 | 442 | |
444 | - $this->get($name, $new_name . '/list_all', $options); |
|
445 | - $this->get($name . '/' . $id, $new_name . '/show/$1', $options); |
|
446 | - $this->post($name, $new_name . '/create', $options); |
|
447 | - $this->put($name . '/' . $id, $new_name . '/update/$1', $options); |
|
448 | - $this->delete($name . '/' . $id, $new_name . '/delete/$1', $options); |
|
449 | - $this->options($name, $new_name . '/index', $options); |
|
443 | + $this->get($name, $new_name.'/list_all', $options); |
|
444 | + $this->get($name.'/'.$id, $new_name.'/show/$1', $options); |
|
445 | + $this->post($name, $new_name.'/create', $options); |
|
446 | + $this->put($name.'/'.$id, $new_name.'/update/$1', $options); |
|
447 | + $this->delete($name.'/'.$id, $new_name.'/delete/$1', $options); |
|
448 | + $this->options($name, $new_name.'/index', $options); |
|
450 | 449 | } |
451 | 450 | |
452 | 451 | //-------------------------------------------------------------------- |
@@ -468,11 +467,11 @@ discard block |
||
468 | 467 | self::$areas[$area] = $controller; |
469 | 468 | |
470 | 469 | // Create routes for this area. |
471 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4/$5', $options); |
|
472 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4', $options); |
|
473 | - $this->create($area . '/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3', $options); |
|
474 | - $this->create($area . '/(:any)/(:any)', '$1/' . $controller . '/$2', $options); |
|
475 | - $this->create($area . '/(:any)', '$1/' . $controller, $options); |
|
470 | + $this->create($area.'/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/'.$controller.'/$2/$3/$4/$5', $options); |
|
471 | + $this->create($area.'/(:any)/(:any)/(:any)/(:any)', '$1/'.$controller.'/$2/$3/$4', $options); |
|
472 | + $this->create($area.'/(:any)/(:any)/(:any)', '$1/'.$controller.'/$2/$3', $options); |
|
473 | + $this->create($area.'/(:any)/(:any)', '$1/'.$controller.'/$2', $options); |
|
474 | + $this->create($area.'/(:any)', '$1/'.$controller, $options); |
|
476 | 475 | } |
477 | 476 | |
478 | 477 | //-------------------------------------------------------------------- |
@@ -534,7 +533,7 @@ discard block |
||
534 | 533 | { |
535 | 534 | $paths = func_get_args(); |
536 | 535 | |
537 | - if (! is_array($paths) || ! count($paths)) { |
|
536 | + if ( ! is_array($paths) || ! count($paths)) { |
|
538 | 537 | return; |
539 | 538 | } |
540 | 539 | |
@@ -577,20 +576,20 @@ discard block |
||
577 | 576 | */ |
578 | 577 | private function create($from, $to, $options = array()) |
579 | 578 | { |
580 | - $prefix = is_null($this->group) ? '' : $this->group . '/'; |
|
579 | + $prefix = is_null($this->group) ? '' : $this->group.'/'; |
|
581 | 580 | |
582 | - $from = $prefix . $from; |
|
581 | + $from = $prefix.$from; |
|
583 | 582 | |
584 | 583 | // Are we saving the name for this one? |
585 | - if (isset($options['as']) && !empty($options['as'])) { |
|
584 | + if (isset($options['as']) && ! empty($options['as'])) { |
|
586 | 585 | self::$names[$options['as']] = $from; |
587 | 586 | } |
588 | 587 | |
589 | 588 | // Limiting to subdomains? |
590 | - if (isset($options['subdomain']) && !empty($options['subdomain'])) { |
|
589 | + if (isset($options['subdomain']) && ! empty($options['subdomain'])) { |
|
591 | 590 | // If we don't match the current subdomain, then |
592 | 591 | // we don't need to add the route. |
593 | - if (!$this->checkSubdomains($options['subdomain'])) { |
|
592 | + if ( ! $this->checkSubdomains($options['subdomain'])) { |
|
594 | 593 | return; |
595 | 594 | } |
596 | 595 | } |
@@ -602,11 +601,11 @@ discard block |
||
602 | 601 | // Get a constant string to work with. |
603 | 602 | $to = preg_replace('/(\$\d+)/', '$X', $to); |
604 | 603 | |
605 | - for ($i = (int)$options['offset'] + 1; $i < (int)$options['offset'] + 7; $i ++) { |
|
604 | + for ($i = (int) $options['offset'] + 1; $i < (int) $options['offset'] + 7; $i++) { |
|
606 | 605 | $to = preg_replace_callback( |
607 | 606 | '/\$X/', |
608 | - function ($m) use ($i) { |
|
609 | - return '$' . $i; |
|
607 | + function($m) use ($i) { |
|
608 | + return '$'.$i; |
|
610 | 609 | }, |
611 | 610 | $to, |
612 | 611 | 1 |
@@ -616,7 +615,7 @@ discard block |
||
616 | 615 | |
617 | 616 | // Convert any custom constraints to the CI/pattern equivalent |
618 | 617 | foreach ($this->constraints as $name => $pattern) { |
619 | - $from = str_replace('{' . $name . '}', $pattern, $from); |
|
618 | + $from = str_replace('{'.$name.'}', $pattern, $from); |
|
620 | 619 | } |
621 | 620 | |
622 | 621 | $this->routes[$from] = $to; |
@@ -637,7 +636,7 @@ discard block |
||
637 | 636 | $this->determineCurrentSubdomain(); |
638 | 637 | } |
639 | 638 | |
640 | - if (!is_array($subdomains)) { |
|
639 | + if ( ! is_array($subdomains)) { |
|
641 | 640 | $subdomains = array($subdomains); |
642 | 641 | } |
643 | 642 | |
@@ -645,7 +644,7 @@ discard block |
||
645 | 644 | |
646 | 645 | array_walk( |
647 | 646 | $subdomains, |
648 | - function ($subdomain) use (&$matched) { |
|
647 | + function($subdomain) use (&$matched) { |
|
649 | 648 | if ($subdomain == $this->current_subdomain || $subdomain == '*') { |
650 | 649 | $matched = true; |
651 | 650 | } |
@@ -670,7 +669,7 @@ discard block |
||
670 | 669 | // If we only have 2 parts, then we don't have a subdomain. |
671 | 670 | // This won't be totally accurate, since URL's like example.co.uk |
672 | 671 | // would still pass, but it helps to separate the chaff... |
673 | - if (!is_array($host) || count($host) == 2) { |
|
672 | + if ( ! is_array($host) || count($host) == 2) { |
|
674 | 673 | // Set it to false so we don't make it back here again. |
675 | 674 | $this->current_subdomain = false; |
676 | 675 | return; |
@@ -43,644 +43,644 @@ |
||
43 | 43 | class Route |
44 | 44 | { |
45 | 45 | |
46 | - // Our routes, ripe for the picking. |
|
47 | - public $routes = array(); |
|
48 | - |
|
49 | - // Holds key/value pairs of named routes |
|
50 | - public static $names = array(); |
|
51 | - |
|
52 | - // Used for grouping routes together. |
|
53 | - public $group = null; |
|
54 | - |
|
55 | - // Holds the 'areas' of the site. |
|
56 | - public static $areas = array(); |
|
57 | - |
|
58 | - // The default controller to use in case |
|
59 | - // 'default_controller' is not in the routes file. |
|
60 | - protected $default_home = 'home'; |
|
61 | - |
|
62 | - // The default constraint to use in route building |
|
63 | - protected $default_constraint = 'any'; |
|
64 | - |
|
65 | - protected $constraints = [ |
|
66 | - 'any' => '(:any)', |
|
67 | - 'num' => '(:num)', |
|
68 | - 'id' => '(:num)', |
|
69 | - 'name' => "([a-zA-Z']+)" |
|
70 | - ]; |
|
71 | - |
|
72 | - protected $current_subdomain = null; |
|
73 | - |
|
74 | - //-------------------------------------------------------------------- |
|
75 | - |
|
76 | - /** |
|
77 | - * Combines the routes that we've defined with the Route class with the |
|
78 | - * routes passed in. This is intended to be used after all routes have been |
|
79 | - * defined to merge CI's default $route array with our routes. |
|
80 | - * |
|
81 | - * Example: |
|
82 | - * $route['default_controller'] = 'home'; |
|
83 | - * Route::resource('posts'); |
|
84 | - * $route = Route::map($route); |
|
85 | - * |
|
86 | - * @param array $routes |
|
87 | - * @internal param array $route The array to merge |
|
88 | - * @return array The merge route array. |
|
89 | - */ |
|
90 | - public function map($routes = array()) |
|
91 | - { |
|
92 | - $controller = isset($routes['default_controller']) ? $routes['default_controller'] : $this->default_home; |
|
93 | - |
|
94 | - $routes = array_merge($routes, $this->routes); |
|
95 | - |
|
96 | - foreach ($routes as $from => $to) { |
|
97 | - $routes[$from] = str_ireplace('{default_controller}', $controller, $to); |
|
98 | - } |
|
99 | - |
|
100 | - return $routes; |
|
101 | - } |
|
102 | - |
|
103 | - //-------------------------------------------------------------------- |
|
104 | - |
|
105 | - /** |
|
106 | - * A single point to the basic routing. Can be used in place of CI's $route |
|
107 | - * array if desired. Used internally by many of the methods. |
|
108 | - * |
|
109 | - * Available options are currently: |
|
110 | - * 'as' - remembers the route via a name that can be called outside of it. |
|
111 | - * 'offset' - Offsets and parameters ($1, $2, etc) in routes by the specified amount. |
|
112 | - * Useful while doing versioning of API's, etc. |
|
113 | - * |
|
114 | - * Example: |
|
115 | - * $route->any('news', 'posts/index'); |
|
116 | - * |
|
117 | - * @param string $from |
|
118 | - * @param string $to |
|
119 | - * @param array $options |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function any($from, $to, $options = array()) |
|
123 | - { |
|
124 | - $this->create($from, $to, $options); |
|
125 | - } |
|
126 | - |
|
127 | - //-------------------------------------------------------------------- |
|
128 | - |
|
129 | - /** |
|
130 | - * Sets the default constraint to be used in the system. Typically |
|
131 | - * for use with the 'resources' method. |
|
132 | - * |
|
133 | - * @param $constraint |
|
134 | - */ |
|
135 | - public function setDefaultConstraint($constraint) |
|
136 | - { |
|
137 | - if (array_key_exists($constraint, $this->constraints)) { |
|
138 | - $this->default_constraint = $constraint; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - //-------------------------------------------------------------------- |
|
143 | - |
|
144 | - /** |
|
145 | - * Registers a new constraint to be used internally. Useful for creating |
|
146 | - * very specific regex patterns, or simply to allow your routes to be |
|
147 | - * a tad more readable. |
|
148 | - * |
|
149 | - * Example: |
|
150 | - * $route->registerConstraint('hero', '(^.*)'); |
|
151 | - * |
|
152 | - * $route->any('home/{hero}', 'heroes/journey'); |
|
153 | - * |
|
154 | - * // Route then looks like: |
|
155 | - * $route['home/(^.*)'] = 'heroes/journey'; |
|
156 | - * |
|
157 | - * @param $name |
|
158 | - * @param $pattern |
|
159 | - * @param bool $overwrite |
|
160 | - */ |
|
161 | - public function registerConstraint($name, $pattern, $overwrite = false) |
|
162 | - { |
|
163 | - // Ensure consistency |
|
164 | - $name = trim($name, '{} '); |
|
165 | - $pattern = '(' . trim($pattern, '() ') . ')'; |
|
166 | - |
|
167 | - // Not here? Add it and leave... |
|
168 | - if (! array_key_exists($name, $this->constraints)) { |
|
169 | - $this->constraints[$name] = $pattern; |
|
170 | - |
|
171 | - return; |
|
172 | - } |
|
173 | - |
|
174 | - // Here? Then it exists. Should we overwrite it? |
|
175 | - if ($overwrite) { |
|
176 | - $this->constraints[$name] = $pattern; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - //-------------------------------------------------------------------- |
|
181 | - |
|
182 | - //-------------------------------------------------------------------- |
|
183 | - // Named Routes |
|
184 | - //-------------------------------------------------------------------- |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the value of a named route. Useful for getting named |
|
188 | - * routes for use while building with site_url() or in templates |
|
189 | - * where you don't need to instantiate the route class. |
|
190 | - * |
|
191 | - * Example: |
|
192 | - * $route->any('news', 'posts/index', ['as' => 'blog']); |
|
193 | - * |
|
194 | - * // Returns http://mysite.com/news |
|
195 | - * site_url( Route::named('blog') ); |
|
196 | - * |
|
197 | - * @param [type] $name [description] |
|
198 | - * @return [type] [description] |
|
199 | - */ |
|
200 | - public static function named($name) |
|
201 | - { |
|
202 | - if (isset(self::$names[$name])) { |
|
203 | - return self::$names[$name]; |
|
204 | - } |
|
205 | - |
|
206 | - return null; |
|
207 | - } |
|
208 | - |
|
209 | - //-------------------------------------------------------------------- |
|
210 | - |
|
211 | - //-------------------------------------------------------------------- |
|
212 | - // Grouping Routes |
|
213 | - //-------------------------------------------------------------------- |
|
214 | - |
|
215 | - /** |
|
216 | - * Group a series of routes under a single URL segment. This is handy |
|
217 | - * for grouping items into an admin area, like: |
|
218 | - * |
|
219 | - * Example: |
|
220 | - * $route->group('admin', function() { |
|
221 | - * $route->resources('users'); |
|
222 | - * }); |
|
223 | - * |
|
224 | - * @param string $name The name to group/prefix the routes with. |
|
225 | - * @param \Closure $callback An anonymous function that allows you route inside of this group. |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - public function group($name, \Closure $callback) |
|
229 | - { |
|
230 | - $old_group = $this->group; |
|
231 | - |
|
232 | - // To register a route, we'll set a flag so that our router |
|
233 | - // so it will see the groupname. |
|
234 | - $this->group = ltrim($old_group . '/' . $name, '/'); |
|
235 | - |
|
236 | - call_user_func($callback); |
|
237 | - |
|
238 | - // Make sure to clear the group name so we don't accidentally |
|
239 | - // group any ones we didn't want to. |
|
240 | - $this->group = $old_group; |
|
241 | - } |
|
242 | - |
|
243 | - //-------------------------------------------------------------------- |
|
244 | - |
|
245 | - //-------------------------------------------------------------------- |
|
246 | - // HTTP Verb-based routing |
|
247 | - //-------------------------------------------------------------------- |
|
248 | - // Routing works here because, as the routes config file is read in, |
|
249 | - // the various HTTP verb-based routes will only be added to the in-memory |
|
250 | - // routes if it is a call that should respond to that verb. |
|
251 | - // |
|
252 | - // The options array is typically used to pass in an 'as' or var, but may |
|
253 | - // be expanded in the future. See the docblock for 'any' method above for |
|
254 | - // current list of globally available options. |
|
255 | - // |
|
256 | - |
|
257 | - /** |
|
258 | - * Specifies a single route to match for multiple HTTP Verbs. |
|
259 | - * |
|
260 | - * Example: |
|
261 | - * $route->match( ['get', 'post'], 'users/(:num)', 'users/$1); |
|
262 | - * |
|
263 | - * @param array $verbs |
|
264 | - * @param $from |
|
265 | - * @param $to |
|
266 | - * @param array $options |
|
267 | - */ |
|
268 | - public function match($verbs = [], $from, $to, $options = []) |
|
269 | - { |
|
270 | - foreach ($verbs as $verb) { |
|
271 | - $verb = strtolower($verb); |
|
272 | - |
|
273 | - $this->{$verb}($from, $to, $options); |
|
274 | - } |
|
275 | - } |
|
276 | - |
|
277 | - //-------------------------------------------------------------------- |
|
278 | - |
|
279 | - /** |
|
280 | - * Specifies a route that is only available to GET requests. |
|
281 | - * |
|
282 | - * @param $from |
|
283 | - * @param $to |
|
284 | - * @param array $options |
|
285 | - */ |
|
286 | - public function get($from, $to, $options = []) |
|
287 | - { |
|
288 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') { |
|
289 | - $this->create($from, $to, $options); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - //-------------------------------------------------------------------- |
|
294 | - |
|
295 | - /** |
|
296 | - * Specifies a route that is only available to POST requests. |
|
297 | - * |
|
298 | - * @param $from |
|
299 | - * @param $to |
|
300 | - * @param array $options |
|
301 | - */ |
|
302 | - public function post($from, $to, $options = []) |
|
303 | - { |
|
304 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { |
|
305 | - $this->create($from, $to, $options); |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - //-------------------------------------------------------------------- |
|
310 | - |
|
311 | - /** |
|
312 | - * Specifies a route that is only available to PUT requests. |
|
313 | - * |
|
314 | - * @param $from |
|
315 | - * @param $to |
|
316 | - * @param array $options |
|
317 | - */ |
|
318 | - public function put($from, $to, $options = []) |
|
319 | - { |
|
320 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PUT') { |
|
321 | - $this->create($from, $to, $options); |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - //-------------------------------------------------------------------- |
|
326 | - |
|
327 | - /** |
|
328 | - * Specifies a route that is only available to DELETE requests. |
|
329 | - * |
|
330 | - * @param $from |
|
331 | - * @param $to |
|
332 | - * @param array $options |
|
333 | - */ |
|
334 | - public function delete($from, $to, $options = []) |
|
335 | - { |
|
336 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'DELETE') { |
|
337 | - $this->create($from, $to, $options); |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - //-------------------------------------------------------------------- |
|
342 | - |
|
343 | - /** |
|
344 | - * Specifies a route that is only available to HEAD requests. |
|
345 | - * |
|
346 | - * @param $from |
|
347 | - * @param $to |
|
348 | - * @param array $options |
|
349 | - */ |
|
350 | - public function head($from, $to, $options = []) |
|
351 | - { |
|
352 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') { |
|
353 | - $this->create($from, $to, $options); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - //-------------------------------------------------------------------- |
|
358 | - |
|
359 | - /** |
|
360 | - * Specifies a route that is only available to PATCH requests. |
|
361 | - * |
|
362 | - * @param $from |
|
363 | - * @param $to |
|
364 | - * @param array $options |
|
365 | - */ |
|
366 | - public function patch($from, $to, $options = []) |
|
367 | - { |
|
368 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PATCH') { |
|
369 | - $this->create($from, $to, $options); |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - //-------------------------------------------------------------------- |
|
374 | - |
|
375 | - /** |
|
376 | - * Specifies a route that is only available to OPTIONS requests. |
|
377 | - * |
|
378 | - * @param $from |
|
379 | - * @param $to |
|
380 | - * @param array $options |
|
381 | - */ |
|
382 | - public function options($from, $to, $options = []) |
|
383 | - { |
|
384 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') { |
|
385 | - $this->create($from, $to, $options); |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - //-------------------------------------------------------------------- |
|
390 | - |
|
391 | - /** |
|
392 | - * Creates a collections of HTTP-verb based routes for a controller. |
|
393 | - * |
|
394 | - * Possible Options: |
|
395 | - * 'controller' - Customize the name of the controller used in the 'to' route |
|
396 | - * 'module' - Prepend a module name to the generate 'to' routes |
|
397 | - * 'constraint' - The regex used by the Router. Defaults to '(:any)' |
|
398 | - * |
|
399 | - * Example: |
|
400 | - * $route->resources('photos'); |
|
401 | - * |
|
402 | - * // Generates the following routes: |
|
403 | - * HTTP Verb | Path | Action | Used for... |
|
404 | - * ----------+-------------+---------------+----------------- |
|
405 | - * GET /photos index display a list of photos |
|
406 | - * GET /photos/new creation_form return an HTML form for creating a new photo |
|
407 | - * GET /photos/{id} show display a specific photo |
|
408 | - * GET /photos/{id}/edit editing_form return an HTML form for editing the photo |
|
409 | - * POST /photos create create a new photo |
|
410 | - * PUT /photos/{id} update update an existing photo |
|
411 | - * DELETE /photos/{id}/delete delete delete an existing photo |
|
412 | - * |
|
413 | - * @param string $name The name of the controller to route to. |
|
414 | - * @param array $options An list of possible ways to customize the routing. |
|
415 | - */ |
|
416 | - public function resources($name, $options = []) |
|
417 | - { |
|
418 | - // In order to allow customization of the route the |
|
419 | - // resources are sent to, we need to have a new name |
|
420 | - // to store the values in. |
|
421 | - $new_name = $name; |
|
422 | - |
|
423 | - // If a new controller is specified, then we replace the |
|
424 | - // $name value with the name of the new controller. |
|
425 | - if (isset($options['controller'])) { |
|
426 | - $new_name = $options['controller']; |
|
427 | - } |
|
428 | - |
|
429 | - // If a new module was specified, simply put that path |
|
430 | - // in front of the controller. |
|
431 | - if (isset($options['module'])) { |
|
432 | - $new_name = $options['module'] . '/' . $new_name; |
|
433 | - } |
|
434 | - |
|
435 | - // In order to allow customization of allowed id values |
|
436 | - // we need someplace to store them. |
|
437 | - $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : |
|
438 | - '(:any)'; |
|
439 | - |
|
440 | - if (isset($options['constraint'])) { |
|
441 | - $id = $options['constraint']; |
|
442 | - } |
|
443 | - |
|
444 | - $this->get($name, $new_name . '/list_all', $options); |
|
445 | - $this->get($name . '/' . $id, $new_name . '/show/$1', $options); |
|
446 | - $this->post($name, $new_name . '/create', $options); |
|
447 | - $this->put($name . '/' . $id, $new_name . '/update/$1', $options); |
|
448 | - $this->delete($name . '/' . $id, $new_name . '/delete/$1', $options); |
|
449 | - $this->options($name, $new_name . '/index', $options); |
|
450 | - } |
|
451 | - |
|
452 | - //-------------------------------------------------------------------- |
|
453 | - |
|
454 | - /** |
|
455 | - * Lets the system know about different 'areas' within the site, like |
|
456 | - * the admin area, that maps to certain controllers. |
|
457 | - * |
|
458 | - * @param string $area The name of the area. |
|
459 | - * @param string $controller The controller name to look for. |
|
460 | - * @param $options |
|
461 | - */ |
|
462 | - public function area($area, $controller = null, $options = []) |
|
463 | - { |
|
464 | - // No controller? Match the area name. |
|
465 | - $controller = is_null($controller) ? $area : $controller; |
|
466 | - |
|
467 | - // Save the area so we can recognize it later. |
|
468 | - self::$areas[$area] = $controller; |
|
469 | - |
|
470 | - // Create routes for this area. |
|
471 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4/$5', $options); |
|
472 | - $this->create($area . '/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4', $options); |
|
473 | - $this->create($area . '/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3', $options); |
|
474 | - $this->create($area . '/(:any)/(:any)', '$1/' . $controller . '/$2', $options); |
|
475 | - $this->create($area . '/(:any)', '$1/' . $controller, $options); |
|
476 | - } |
|
477 | - |
|
478 | - //-------------------------------------------------------------------- |
|
479 | - |
|
480 | - /** |
|
481 | - * Returns the name of the area based on the controller name. |
|
482 | - * |
|
483 | - * @param string $controller The name of the controller |
|
484 | - * @return string The name of the corresponding area |
|
485 | - */ |
|
486 | - public static function getAreaName($controller) |
|
487 | - { |
|
488 | - foreach (self::$areas as $area => $cont) { |
|
489 | - if ($controller == $cont) { |
|
490 | - return $area; |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - return null; |
|
495 | - } |
|
496 | - |
|
497 | - //-------------------------------------------------------------------- |
|
498 | - |
|
499 | - /** |
|
500 | - * Limits the routes to a specified ENVIRONMENT or they won't run. |
|
501 | - * |
|
502 | - * @param $env |
|
503 | - * @param callable $callback |
|
504 | - * |
|
505 | - * @return bool|null |
|
506 | - */ |
|
507 | - public function environment($env, \Closure $callback) |
|
508 | - { |
|
509 | - if (ENVIRONMENT == $env) |
|
510 | - { |
|
511 | - call_user_func($callback); |
|
512 | - return true; |
|
513 | - } |
|
514 | - |
|
515 | - return null; |
|
516 | - } |
|
517 | - |
|
518 | - //-------------------------------------------------------------------- |
|
519 | - |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * Allows you to easily block access to any number of routes by setting |
|
524 | - * that route to an empty path (''). |
|
525 | - * |
|
526 | - * Example: |
|
527 | - * Route::block('posts', 'photos/(:num)'); |
|
528 | - * |
|
529 | - * // Same as... |
|
530 | - * $route['posts'] = ''; |
|
531 | - * $route['photos/(:num)'] = ''; |
|
532 | - */ |
|
533 | - public function block() |
|
534 | - { |
|
535 | - $paths = func_get_args(); |
|
536 | - |
|
537 | - if (! is_array($paths) || ! count($paths)) { |
|
538 | - return; |
|
539 | - } |
|
540 | - |
|
541 | - foreach ($paths as $path) { |
|
542 | - $this->create($path, ''); |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - //-------------------------------------------------------------------- |
|
547 | - |
|
548 | - /** |
|
549 | - * Empties all named and un-named routes from the system. |
|
550 | - * |
|
551 | - * @return void |
|
552 | - */ |
|
553 | - public function reset() |
|
554 | - { |
|
555 | - $this->routes = array(); |
|
556 | - $this->group = null; |
|
557 | - self::$names = array(); |
|
558 | - self::$areas = array(); |
|
559 | - } |
|
560 | - |
|
561 | - //-------------------------------------------------------------------- |
|
562 | - |
|
563 | - //-------------------------------------------------------------------- |
|
564 | - // Private Methods |
|
565 | - //-------------------------------------------------------------------- |
|
566 | - |
|
567 | - /** |
|
568 | - * Does the heavy lifting of creating an actual route. You must specify |
|
569 | - * the request method(s) that this route will work for. They can be separated |
|
570 | - * by a pipe character "|" if there is more than one. |
|
571 | - * |
|
572 | - * @param string $from |
|
573 | - * @param array $to |
|
574 | - * @param array $options |
|
575 | - * |
|
576 | - * @return array The built route. |
|
577 | - */ |
|
578 | - private function create($from, $to, $options = array()) |
|
579 | - { |
|
580 | - $prefix = is_null($this->group) ? '' : $this->group . '/'; |
|
581 | - |
|
582 | - $from = $prefix . $from; |
|
583 | - |
|
584 | - // Are we saving the name for this one? |
|
585 | - if (isset($options['as']) && !empty($options['as'])) { |
|
586 | - self::$names[$options['as']] = $from; |
|
587 | - } |
|
588 | - |
|
589 | - // Limiting to subdomains? |
|
590 | - if (isset($options['subdomain']) && !empty($options['subdomain'])) { |
|
591 | - // If we don't match the current subdomain, then |
|
592 | - // we don't need to add the route. |
|
593 | - if (!$this->checkSubdomains($options['subdomain'])) { |
|
594 | - return; |
|
595 | - } |
|
596 | - } |
|
597 | - |
|
598 | - // Are we offsetting the parameters? |
|
599 | - // If so, take care of them here in one |
|
600 | - // fell swoop. |
|
601 | - if (isset($options['offset'])) { |
|
602 | - // Get a constant string to work with. |
|
603 | - $to = preg_replace('/(\$\d+)/', '$X', $to); |
|
604 | - |
|
605 | - for ($i = (int)$options['offset'] + 1; $i < (int)$options['offset'] + 7; $i ++) { |
|
606 | - $to = preg_replace_callback( |
|
607 | - '/\$X/', |
|
608 | - function ($m) use ($i) { |
|
609 | - return '$' . $i; |
|
610 | - }, |
|
611 | - $to, |
|
612 | - 1 |
|
613 | - ); |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - // Convert any custom constraints to the CI/pattern equivalent |
|
618 | - foreach ($this->constraints as $name => $pattern) { |
|
619 | - $from = str_replace('{' . $name . '}', $pattern, $from); |
|
620 | - } |
|
621 | - |
|
622 | - $this->routes[$from] = $to; |
|
623 | - } |
|
624 | - |
|
625 | - //-------------------------------------------------------------------- |
|
626 | - |
|
627 | - /** |
|
628 | - * Compares the subdomain(s) passed in against the current subdomain |
|
629 | - * on this page request. |
|
630 | - * |
|
631 | - * @param $subdomains |
|
632 | - * @return bool |
|
633 | - */ |
|
634 | - private function checkSubdomains($subdomains) |
|
635 | - { |
|
636 | - if (is_null($this->current_subdomain)) { |
|
637 | - $this->determineCurrentSubdomain(); |
|
638 | - } |
|
639 | - |
|
640 | - if (!is_array($subdomains)) { |
|
641 | - $subdomains = array($subdomains); |
|
642 | - } |
|
643 | - |
|
644 | - $matched = false; |
|
645 | - |
|
646 | - array_walk( |
|
647 | - $subdomains, |
|
648 | - function ($subdomain) use (&$matched) { |
|
649 | - if ($subdomain == $this->current_subdomain || $subdomain == '*') { |
|
650 | - $matched = true; |
|
651 | - } |
|
652 | - } |
|
653 | - ); |
|
654 | - |
|
655 | - return $matched; |
|
656 | - } |
|
657 | - |
|
658 | - //-------------------------------------------------------------------- |
|
659 | - |
|
660 | - /** |
|
661 | - * Examines the HTTP_HOST to get a best match for the subdomain. It |
|
662 | - * won't be perfect, but should work for our needs. |
|
663 | - */ |
|
664 | - private function determineCurrentSubdomain() |
|
665 | - { |
|
666 | - $parsedUrl = parse_url($_SERVER['HTTP_HOST']); |
|
667 | - |
|
668 | - $host = explode('.', $parsedUrl['host']); |
|
669 | - |
|
670 | - // If we only have 2 parts, then we don't have a subdomain. |
|
671 | - // This won't be totally accurate, since URL's like example.co.uk |
|
672 | - // would still pass, but it helps to separate the chaff... |
|
673 | - if (!is_array($host) || count($host) == 2) { |
|
674 | - // Set it to false so we don't make it back here again. |
|
675 | - $this->current_subdomain = false; |
|
676 | - return; |
|
677 | - } |
|
678 | - |
|
679 | - // Now, we'll simply take the first element of the array. This should |
|
680 | - // be fine even in cases like example.co.uk, since they won't be looking |
|
681 | - // for 'example' when they try to match the subdomain, in most all cases. |
|
682 | - $this->current_subdomain = array_shift($host); |
|
683 | - } |
|
684 | - //-------------------------------------------------------------------- |
|
46 | + // Our routes, ripe for the picking. |
|
47 | + public $routes = array(); |
|
48 | + |
|
49 | + // Holds key/value pairs of named routes |
|
50 | + public static $names = array(); |
|
51 | + |
|
52 | + // Used for grouping routes together. |
|
53 | + public $group = null; |
|
54 | + |
|
55 | + // Holds the 'areas' of the site. |
|
56 | + public static $areas = array(); |
|
57 | + |
|
58 | + // The default controller to use in case |
|
59 | + // 'default_controller' is not in the routes file. |
|
60 | + protected $default_home = 'home'; |
|
61 | + |
|
62 | + // The default constraint to use in route building |
|
63 | + protected $default_constraint = 'any'; |
|
64 | + |
|
65 | + protected $constraints = [ |
|
66 | + 'any' => '(:any)', |
|
67 | + 'num' => '(:num)', |
|
68 | + 'id' => '(:num)', |
|
69 | + 'name' => "([a-zA-Z']+)" |
|
70 | + ]; |
|
71 | + |
|
72 | + protected $current_subdomain = null; |
|
73 | + |
|
74 | + //-------------------------------------------------------------------- |
|
75 | + |
|
76 | + /** |
|
77 | + * Combines the routes that we've defined with the Route class with the |
|
78 | + * routes passed in. This is intended to be used after all routes have been |
|
79 | + * defined to merge CI's default $route array with our routes. |
|
80 | + * |
|
81 | + * Example: |
|
82 | + * $route['default_controller'] = 'home'; |
|
83 | + * Route::resource('posts'); |
|
84 | + * $route = Route::map($route); |
|
85 | + * |
|
86 | + * @param array $routes |
|
87 | + * @internal param array $route The array to merge |
|
88 | + * @return array The merge route array. |
|
89 | + */ |
|
90 | + public function map($routes = array()) |
|
91 | + { |
|
92 | + $controller = isset($routes['default_controller']) ? $routes['default_controller'] : $this->default_home; |
|
93 | + |
|
94 | + $routes = array_merge($routes, $this->routes); |
|
95 | + |
|
96 | + foreach ($routes as $from => $to) { |
|
97 | + $routes[$from] = str_ireplace('{default_controller}', $controller, $to); |
|
98 | + } |
|
99 | + |
|
100 | + return $routes; |
|
101 | + } |
|
102 | + |
|
103 | + //-------------------------------------------------------------------- |
|
104 | + |
|
105 | + /** |
|
106 | + * A single point to the basic routing. Can be used in place of CI's $route |
|
107 | + * array if desired. Used internally by many of the methods. |
|
108 | + * |
|
109 | + * Available options are currently: |
|
110 | + * 'as' - remembers the route via a name that can be called outside of it. |
|
111 | + * 'offset' - Offsets and parameters ($1, $2, etc) in routes by the specified amount. |
|
112 | + * Useful while doing versioning of API's, etc. |
|
113 | + * |
|
114 | + * Example: |
|
115 | + * $route->any('news', 'posts/index'); |
|
116 | + * |
|
117 | + * @param string $from |
|
118 | + * @param string $to |
|
119 | + * @param array $options |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function any($from, $to, $options = array()) |
|
123 | + { |
|
124 | + $this->create($from, $to, $options); |
|
125 | + } |
|
126 | + |
|
127 | + //-------------------------------------------------------------------- |
|
128 | + |
|
129 | + /** |
|
130 | + * Sets the default constraint to be used in the system. Typically |
|
131 | + * for use with the 'resources' method. |
|
132 | + * |
|
133 | + * @param $constraint |
|
134 | + */ |
|
135 | + public function setDefaultConstraint($constraint) |
|
136 | + { |
|
137 | + if (array_key_exists($constraint, $this->constraints)) { |
|
138 | + $this->default_constraint = $constraint; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + //-------------------------------------------------------------------- |
|
143 | + |
|
144 | + /** |
|
145 | + * Registers a new constraint to be used internally. Useful for creating |
|
146 | + * very specific regex patterns, or simply to allow your routes to be |
|
147 | + * a tad more readable. |
|
148 | + * |
|
149 | + * Example: |
|
150 | + * $route->registerConstraint('hero', '(^.*)'); |
|
151 | + * |
|
152 | + * $route->any('home/{hero}', 'heroes/journey'); |
|
153 | + * |
|
154 | + * // Route then looks like: |
|
155 | + * $route['home/(^.*)'] = 'heroes/journey'; |
|
156 | + * |
|
157 | + * @param $name |
|
158 | + * @param $pattern |
|
159 | + * @param bool $overwrite |
|
160 | + */ |
|
161 | + public function registerConstraint($name, $pattern, $overwrite = false) |
|
162 | + { |
|
163 | + // Ensure consistency |
|
164 | + $name = trim($name, '{} '); |
|
165 | + $pattern = '(' . trim($pattern, '() ') . ')'; |
|
166 | + |
|
167 | + // Not here? Add it and leave... |
|
168 | + if (! array_key_exists($name, $this->constraints)) { |
|
169 | + $this->constraints[$name] = $pattern; |
|
170 | + |
|
171 | + return; |
|
172 | + } |
|
173 | + |
|
174 | + // Here? Then it exists. Should we overwrite it? |
|
175 | + if ($overwrite) { |
|
176 | + $this->constraints[$name] = $pattern; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + //-------------------------------------------------------------------- |
|
181 | + |
|
182 | + //-------------------------------------------------------------------- |
|
183 | + // Named Routes |
|
184 | + //-------------------------------------------------------------------- |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the value of a named route. Useful for getting named |
|
188 | + * routes for use while building with site_url() or in templates |
|
189 | + * where you don't need to instantiate the route class. |
|
190 | + * |
|
191 | + * Example: |
|
192 | + * $route->any('news', 'posts/index', ['as' => 'blog']); |
|
193 | + * |
|
194 | + * // Returns http://mysite.com/news |
|
195 | + * site_url( Route::named('blog') ); |
|
196 | + * |
|
197 | + * @param [type] $name [description] |
|
198 | + * @return [type] [description] |
|
199 | + */ |
|
200 | + public static function named($name) |
|
201 | + { |
|
202 | + if (isset(self::$names[$name])) { |
|
203 | + return self::$names[$name]; |
|
204 | + } |
|
205 | + |
|
206 | + return null; |
|
207 | + } |
|
208 | + |
|
209 | + //-------------------------------------------------------------------- |
|
210 | + |
|
211 | + //-------------------------------------------------------------------- |
|
212 | + // Grouping Routes |
|
213 | + //-------------------------------------------------------------------- |
|
214 | + |
|
215 | + /** |
|
216 | + * Group a series of routes under a single URL segment. This is handy |
|
217 | + * for grouping items into an admin area, like: |
|
218 | + * |
|
219 | + * Example: |
|
220 | + * $route->group('admin', function() { |
|
221 | + * $route->resources('users'); |
|
222 | + * }); |
|
223 | + * |
|
224 | + * @param string $name The name to group/prefix the routes with. |
|
225 | + * @param \Closure $callback An anonymous function that allows you route inside of this group. |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + public function group($name, \Closure $callback) |
|
229 | + { |
|
230 | + $old_group = $this->group; |
|
231 | + |
|
232 | + // To register a route, we'll set a flag so that our router |
|
233 | + // so it will see the groupname. |
|
234 | + $this->group = ltrim($old_group . '/' . $name, '/'); |
|
235 | + |
|
236 | + call_user_func($callback); |
|
237 | + |
|
238 | + // Make sure to clear the group name so we don't accidentally |
|
239 | + // group any ones we didn't want to. |
|
240 | + $this->group = $old_group; |
|
241 | + } |
|
242 | + |
|
243 | + //-------------------------------------------------------------------- |
|
244 | + |
|
245 | + //-------------------------------------------------------------------- |
|
246 | + // HTTP Verb-based routing |
|
247 | + //-------------------------------------------------------------------- |
|
248 | + // Routing works here because, as the routes config file is read in, |
|
249 | + // the various HTTP verb-based routes will only be added to the in-memory |
|
250 | + // routes if it is a call that should respond to that verb. |
|
251 | + // |
|
252 | + // The options array is typically used to pass in an 'as' or var, but may |
|
253 | + // be expanded in the future. See the docblock for 'any' method above for |
|
254 | + // current list of globally available options. |
|
255 | + // |
|
256 | + |
|
257 | + /** |
|
258 | + * Specifies a single route to match for multiple HTTP Verbs. |
|
259 | + * |
|
260 | + * Example: |
|
261 | + * $route->match( ['get', 'post'], 'users/(:num)', 'users/$1); |
|
262 | + * |
|
263 | + * @param array $verbs |
|
264 | + * @param $from |
|
265 | + * @param $to |
|
266 | + * @param array $options |
|
267 | + */ |
|
268 | + public function match($verbs = [], $from, $to, $options = []) |
|
269 | + { |
|
270 | + foreach ($verbs as $verb) { |
|
271 | + $verb = strtolower($verb); |
|
272 | + |
|
273 | + $this->{$verb}($from, $to, $options); |
|
274 | + } |
|
275 | + } |
|
276 | + |
|
277 | + //-------------------------------------------------------------------- |
|
278 | + |
|
279 | + /** |
|
280 | + * Specifies a route that is only available to GET requests. |
|
281 | + * |
|
282 | + * @param $from |
|
283 | + * @param $to |
|
284 | + * @param array $options |
|
285 | + */ |
|
286 | + public function get($from, $to, $options = []) |
|
287 | + { |
|
288 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') { |
|
289 | + $this->create($from, $to, $options); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + //-------------------------------------------------------------------- |
|
294 | + |
|
295 | + /** |
|
296 | + * Specifies a route that is only available to POST requests. |
|
297 | + * |
|
298 | + * @param $from |
|
299 | + * @param $to |
|
300 | + * @param array $options |
|
301 | + */ |
|
302 | + public function post($from, $to, $options = []) |
|
303 | + { |
|
304 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { |
|
305 | + $this->create($from, $to, $options); |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + //-------------------------------------------------------------------- |
|
310 | + |
|
311 | + /** |
|
312 | + * Specifies a route that is only available to PUT requests. |
|
313 | + * |
|
314 | + * @param $from |
|
315 | + * @param $to |
|
316 | + * @param array $options |
|
317 | + */ |
|
318 | + public function put($from, $to, $options = []) |
|
319 | + { |
|
320 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PUT') { |
|
321 | + $this->create($from, $to, $options); |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + //-------------------------------------------------------------------- |
|
326 | + |
|
327 | + /** |
|
328 | + * Specifies a route that is only available to DELETE requests. |
|
329 | + * |
|
330 | + * @param $from |
|
331 | + * @param $to |
|
332 | + * @param array $options |
|
333 | + */ |
|
334 | + public function delete($from, $to, $options = []) |
|
335 | + { |
|
336 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'DELETE') { |
|
337 | + $this->create($from, $to, $options); |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + //-------------------------------------------------------------------- |
|
342 | + |
|
343 | + /** |
|
344 | + * Specifies a route that is only available to HEAD requests. |
|
345 | + * |
|
346 | + * @param $from |
|
347 | + * @param $to |
|
348 | + * @param array $options |
|
349 | + */ |
|
350 | + public function head($from, $to, $options = []) |
|
351 | + { |
|
352 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') { |
|
353 | + $this->create($from, $to, $options); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + //-------------------------------------------------------------------- |
|
358 | + |
|
359 | + /** |
|
360 | + * Specifies a route that is only available to PATCH requests. |
|
361 | + * |
|
362 | + * @param $from |
|
363 | + * @param $to |
|
364 | + * @param array $options |
|
365 | + */ |
|
366 | + public function patch($from, $to, $options = []) |
|
367 | + { |
|
368 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PATCH') { |
|
369 | + $this->create($from, $to, $options); |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + //-------------------------------------------------------------------- |
|
374 | + |
|
375 | + /** |
|
376 | + * Specifies a route that is only available to OPTIONS requests. |
|
377 | + * |
|
378 | + * @param $from |
|
379 | + * @param $to |
|
380 | + * @param array $options |
|
381 | + */ |
|
382 | + public function options($from, $to, $options = []) |
|
383 | + { |
|
384 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') { |
|
385 | + $this->create($from, $to, $options); |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + //-------------------------------------------------------------------- |
|
390 | + |
|
391 | + /** |
|
392 | + * Creates a collections of HTTP-verb based routes for a controller. |
|
393 | + * |
|
394 | + * Possible Options: |
|
395 | + * 'controller' - Customize the name of the controller used in the 'to' route |
|
396 | + * 'module' - Prepend a module name to the generate 'to' routes |
|
397 | + * 'constraint' - The regex used by the Router. Defaults to '(:any)' |
|
398 | + * |
|
399 | + * Example: |
|
400 | + * $route->resources('photos'); |
|
401 | + * |
|
402 | + * // Generates the following routes: |
|
403 | + * HTTP Verb | Path | Action | Used for... |
|
404 | + * ----------+-------------+---------------+----------------- |
|
405 | + * GET /photos index display a list of photos |
|
406 | + * GET /photos/new creation_form return an HTML form for creating a new photo |
|
407 | + * GET /photos/{id} show display a specific photo |
|
408 | + * GET /photos/{id}/edit editing_form return an HTML form for editing the photo |
|
409 | + * POST /photos create create a new photo |
|
410 | + * PUT /photos/{id} update update an existing photo |
|
411 | + * DELETE /photos/{id}/delete delete delete an existing photo |
|
412 | + * |
|
413 | + * @param string $name The name of the controller to route to. |
|
414 | + * @param array $options An list of possible ways to customize the routing. |
|
415 | + */ |
|
416 | + public function resources($name, $options = []) |
|
417 | + { |
|
418 | + // In order to allow customization of the route the |
|
419 | + // resources are sent to, we need to have a new name |
|
420 | + // to store the values in. |
|
421 | + $new_name = $name; |
|
422 | + |
|
423 | + // If a new controller is specified, then we replace the |
|
424 | + // $name value with the name of the new controller. |
|
425 | + if (isset($options['controller'])) { |
|
426 | + $new_name = $options['controller']; |
|
427 | + } |
|
428 | + |
|
429 | + // If a new module was specified, simply put that path |
|
430 | + // in front of the controller. |
|
431 | + if (isset($options['module'])) { |
|
432 | + $new_name = $options['module'] . '/' . $new_name; |
|
433 | + } |
|
434 | + |
|
435 | + // In order to allow customization of allowed id values |
|
436 | + // we need someplace to store them. |
|
437 | + $id = isset($this->constraints[$this->default_constraint]) ? $this->constraints[$this->default_constraint] : |
|
438 | + '(:any)'; |
|
439 | + |
|
440 | + if (isset($options['constraint'])) { |
|
441 | + $id = $options['constraint']; |
|
442 | + } |
|
443 | + |
|
444 | + $this->get($name, $new_name . '/list_all', $options); |
|
445 | + $this->get($name . '/' . $id, $new_name . '/show/$1', $options); |
|
446 | + $this->post($name, $new_name . '/create', $options); |
|
447 | + $this->put($name . '/' . $id, $new_name . '/update/$1', $options); |
|
448 | + $this->delete($name . '/' . $id, $new_name . '/delete/$1', $options); |
|
449 | + $this->options($name, $new_name . '/index', $options); |
|
450 | + } |
|
451 | + |
|
452 | + //-------------------------------------------------------------------- |
|
453 | + |
|
454 | + /** |
|
455 | + * Lets the system know about different 'areas' within the site, like |
|
456 | + * the admin area, that maps to certain controllers. |
|
457 | + * |
|
458 | + * @param string $area The name of the area. |
|
459 | + * @param string $controller The controller name to look for. |
|
460 | + * @param $options |
|
461 | + */ |
|
462 | + public function area($area, $controller = null, $options = []) |
|
463 | + { |
|
464 | + // No controller? Match the area name. |
|
465 | + $controller = is_null($controller) ? $area : $controller; |
|
466 | + |
|
467 | + // Save the area so we can recognize it later. |
|
468 | + self::$areas[$area] = $controller; |
|
469 | + |
|
470 | + // Create routes for this area. |
|
471 | + $this->create($area . '/(:any)/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4/$5', $options); |
|
472 | + $this->create($area . '/(:any)/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3/$4', $options); |
|
473 | + $this->create($area . '/(:any)/(:any)/(:any)', '$1/' . $controller . '/$2/$3', $options); |
|
474 | + $this->create($area . '/(:any)/(:any)', '$1/' . $controller . '/$2', $options); |
|
475 | + $this->create($area . '/(:any)', '$1/' . $controller, $options); |
|
476 | + } |
|
477 | + |
|
478 | + //-------------------------------------------------------------------- |
|
479 | + |
|
480 | + /** |
|
481 | + * Returns the name of the area based on the controller name. |
|
482 | + * |
|
483 | + * @param string $controller The name of the controller |
|
484 | + * @return string The name of the corresponding area |
|
485 | + */ |
|
486 | + public static function getAreaName($controller) |
|
487 | + { |
|
488 | + foreach (self::$areas as $area => $cont) { |
|
489 | + if ($controller == $cont) { |
|
490 | + return $area; |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + return null; |
|
495 | + } |
|
496 | + |
|
497 | + //-------------------------------------------------------------------- |
|
498 | + |
|
499 | + /** |
|
500 | + * Limits the routes to a specified ENVIRONMENT or they won't run. |
|
501 | + * |
|
502 | + * @param $env |
|
503 | + * @param callable $callback |
|
504 | + * |
|
505 | + * @return bool|null |
|
506 | + */ |
|
507 | + public function environment($env, \Closure $callback) |
|
508 | + { |
|
509 | + if (ENVIRONMENT == $env) |
|
510 | + { |
|
511 | + call_user_func($callback); |
|
512 | + return true; |
|
513 | + } |
|
514 | + |
|
515 | + return null; |
|
516 | + } |
|
517 | + |
|
518 | + //-------------------------------------------------------------------- |
|
519 | + |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * Allows you to easily block access to any number of routes by setting |
|
524 | + * that route to an empty path (''). |
|
525 | + * |
|
526 | + * Example: |
|
527 | + * Route::block('posts', 'photos/(:num)'); |
|
528 | + * |
|
529 | + * // Same as... |
|
530 | + * $route['posts'] = ''; |
|
531 | + * $route['photos/(:num)'] = ''; |
|
532 | + */ |
|
533 | + public function block() |
|
534 | + { |
|
535 | + $paths = func_get_args(); |
|
536 | + |
|
537 | + if (! is_array($paths) || ! count($paths)) { |
|
538 | + return; |
|
539 | + } |
|
540 | + |
|
541 | + foreach ($paths as $path) { |
|
542 | + $this->create($path, ''); |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + //-------------------------------------------------------------------- |
|
547 | + |
|
548 | + /** |
|
549 | + * Empties all named and un-named routes from the system. |
|
550 | + * |
|
551 | + * @return void |
|
552 | + */ |
|
553 | + public function reset() |
|
554 | + { |
|
555 | + $this->routes = array(); |
|
556 | + $this->group = null; |
|
557 | + self::$names = array(); |
|
558 | + self::$areas = array(); |
|
559 | + } |
|
560 | + |
|
561 | + //-------------------------------------------------------------------- |
|
562 | + |
|
563 | + //-------------------------------------------------------------------- |
|
564 | + // Private Methods |
|
565 | + //-------------------------------------------------------------------- |
|
566 | + |
|
567 | + /** |
|
568 | + * Does the heavy lifting of creating an actual route. You must specify |
|
569 | + * the request method(s) that this route will work for. They can be separated |
|
570 | + * by a pipe character "|" if there is more than one. |
|
571 | + * |
|
572 | + * @param string $from |
|
573 | + * @param array $to |
|
574 | + * @param array $options |
|
575 | + * |
|
576 | + * @return array The built route. |
|
577 | + */ |
|
578 | + private function create($from, $to, $options = array()) |
|
579 | + { |
|
580 | + $prefix = is_null($this->group) ? '' : $this->group . '/'; |
|
581 | + |
|
582 | + $from = $prefix . $from; |
|
583 | + |
|
584 | + // Are we saving the name for this one? |
|
585 | + if (isset($options['as']) && !empty($options['as'])) { |
|
586 | + self::$names[$options['as']] = $from; |
|
587 | + } |
|
588 | + |
|
589 | + // Limiting to subdomains? |
|
590 | + if (isset($options['subdomain']) && !empty($options['subdomain'])) { |
|
591 | + // If we don't match the current subdomain, then |
|
592 | + // we don't need to add the route. |
|
593 | + if (!$this->checkSubdomains($options['subdomain'])) { |
|
594 | + return; |
|
595 | + } |
|
596 | + } |
|
597 | + |
|
598 | + // Are we offsetting the parameters? |
|
599 | + // If so, take care of them here in one |
|
600 | + // fell swoop. |
|
601 | + if (isset($options['offset'])) { |
|
602 | + // Get a constant string to work with. |
|
603 | + $to = preg_replace('/(\$\d+)/', '$X', $to); |
|
604 | + |
|
605 | + for ($i = (int)$options['offset'] + 1; $i < (int)$options['offset'] + 7; $i ++) { |
|
606 | + $to = preg_replace_callback( |
|
607 | + '/\$X/', |
|
608 | + function ($m) use ($i) { |
|
609 | + return '$' . $i; |
|
610 | + }, |
|
611 | + $to, |
|
612 | + 1 |
|
613 | + ); |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + // Convert any custom constraints to the CI/pattern equivalent |
|
618 | + foreach ($this->constraints as $name => $pattern) { |
|
619 | + $from = str_replace('{' . $name . '}', $pattern, $from); |
|
620 | + } |
|
621 | + |
|
622 | + $this->routes[$from] = $to; |
|
623 | + } |
|
624 | + |
|
625 | + //-------------------------------------------------------------------- |
|
626 | + |
|
627 | + /** |
|
628 | + * Compares the subdomain(s) passed in against the current subdomain |
|
629 | + * on this page request. |
|
630 | + * |
|
631 | + * @param $subdomains |
|
632 | + * @return bool |
|
633 | + */ |
|
634 | + private function checkSubdomains($subdomains) |
|
635 | + { |
|
636 | + if (is_null($this->current_subdomain)) { |
|
637 | + $this->determineCurrentSubdomain(); |
|
638 | + } |
|
639 | + |
|
640 | + if (!is_array($subdomains)) { |
|
641 | + $subdomains = array($subdomains); |
|
642 | + } |
|
643 | + |
|
644 | + $matched = false; |
|
645 | + |
|
646 | + array_walk( |
|
647 | + $subdomains, |
|
648 | + function ($subdomain) use (&$matched) { |
|
649 | + if ($subdomain == $this->current_subdomain || $subdomain == '*') { |
|
650 | + $matched = true; |
|
651 | + } |
|
652 | + } |
|
653 | + ); |
|
654 | + |
|
655 | + return $matched; |
|
656 | + } |
|
657 | + |
|
658 | + //-------------------------------------------------------------------- |
|
659 | + |
|
660 | + /** |
|
661 | + * Examines the HTTP_HOST to get a best match for the subdomain. It |
|
662 | + * won't be perfect, but should work for our needs. |
|
663 | + */ |
|
664 | + private function determineCurrentSubdomain() |
|
665 | + { |
|
666 | + $parsedUrl = parse_url($_SERVER['HTTP_HOST']); |
|
667 | + |
|
668 | + $host = explode('.', $parsedUrl['host']); |
|
669 | + |
|
670 | + // If we only have 2 parts, then we don't have a subdomain. |
|
671 | + // This won't be totally accurate, since URL's like example.co.uk |
|
672 | + // would still pass, but it helps to separate the chaff... |
|
673 | + if (!is_array($host) || count($host) == 2) { |
|
674 | + // Set it to false so we don't make it back here again. |
|
675 | + $this->current_subdomain = false; |
|
676 | + return; |
|
677 | + } |
|
678 | + |
|
679 | + // Now, we'll simply take the first element of the array. This should |
|
680 | + // be fine even in cases like example.co.uk, since they won't be looking |
|
681 | + // for 'example' when they try to match the subdomain, in most all cases. |
|
682 | + $this->current_subdomain = array_shift($host); |
|
683 | + } |
|
684 | + //-------------------------------------------------------------------- |
|
685 | 685 | |
686 | 686 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param $alias |
40 | 40 | * @param null $value |
41 | 41 | * |
42 | - * @return mixed |
|
42 | + * @return MetaCollection |
|
43 | 43 | */ |
44 | 44 | public function set($alias, $value=null); |
45 | 45 | |
@@ -59,9 +59,8 @@ discard block |
||
59 | 59 | /** |
60 | 60 | * Renders out all defined meta tags. |
61 | 61 | * |
62 | - * @param array $show_tags |
|
63 | 62 | * |
64 | - * @return mixed |
|
63 | + * @return null|string |
|
65 | 64 | */ |
66 | 65 | public function renderTags(); |
67 | 66 |
@@ -33,50 +33,50 @@ |
||
33 | 33 | |
34 | 34 | interface MetaInterface { |
35 | 35 | |
36 | - /** |
|
37 | - * Sets a single meta item. |
|
38 | - * |
|
39 | - * @param $alias |
|
40 | - * @param null $value |
|
41 | - * |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - public function set($alias, $value=null); |
|
36 | + /** |
|
37 | + * Sets a single meta item. |
|
38 | + * |
|
39 | + * @param $alias |
|
40 | + * @param null $value |
|
41 | + * |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + public function set($alias, $value=null); |
|
45 | 45 | |
46 | - //-------------------------------------------------------------------- |
|
46 | + //-------------------------------------------------------------------- |
|
47 | 47 | |
48 | - /** |
|
49 | - * Returns a single meta item. |
|
50 | - * |
|
51 | - * @param $alias |
|
52 | - * |
|
53 | - * @return mixed |
|
54 | - */ |
|
55 | - public function get($alias); |
|
48 | + /** |
|
49 | + * Returns a single meta item. |
|
50 | + * |
|
51 | + * @param $alias |
|
52 | + * |
|
53 | + * @return mixed |
|
54 | + */ |
|
55 | + public function get($alias); |
|
56 | 56 | |
57 | - //-------------------------------------------------------------------- |
|
57 | + //-------------------------------------------------------------------- |
|
58 | 58 | |
59 | - /** |
|
60 | - * Renders out all defined meta tags. |
|
61 | - * |
|
62 | - * @param array $show_tags |
|
63 | - * |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - public function renderTags(); |
|
59 | + /** |
|
60 | + * Renders out all defined meta tags. |
|
61 | + * |
|
62 | + * @param array $show_tags |
|
63 | + * |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + public function renderTags(); |
|
67 | 67 | |
68 | - //-------------------------------------------------------------------- |
|
68 | + //-------------------------------------------------------------------- |
|
69 | 69 | |
70 | - /** |
|
71 | - * Registers a new HTTP Equivalent meta tag so it can be |
|
72 | - * rendered out properly. |
|
73 | - * |
|
74 | - * @param $name |
|
75 | - * |
|
76 | - * @return $this |
|
77 | - */ |
|
78 | - public function registerHTTPEquivTag($name); |
|
70 | + /** |
|
71 | + * Registers a new HTTP Equivalent meta tag so it can be |
|
72 | + * rendered out properly. |
|
73 | + * |
|
74 | + * @param $name |
|
75 | + * |
|
76 | + * @return $this |
|
77 | + */ |
|
78 | + public function registerHTTPEquivTag($name); |
|
79 | 79 | |
80 | - //-------------------------------------------------------------------- |
|
80 | + //-------------------------------------------------------------------- |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | \ No newline at end of file |
@@ -41,7 +41,7 @@ |
||
41 | 41 | * |
42 | 42 | * @return mixed |
43 | 43 | */ |
44 | - public function set($alias, $value=null); |
|
44 | + public function set($alias, $value = null); |
|
45 | 45 | |
46 | 46 | //-------------------------------------------------------------------- |
47 | 47 |
@@ -73,7 +73,6 @@ discard block |
||
73 | 73 | * controller and is generally the last method called. |
74 | 74 | * |
75 | 75 | * @param string $layout If provided, will override the default layout. |
76 | - * @param int $cache_time The number of seconds to cache the output for. |
|
77 | 76 | * @return mixed |
78 | 77 | */ |
79 | 78 | public function render($layout = null) |
@@ -104,7 +103,6 @@ discard block |
||
104 | 103 | * Used within the template layout file to render the current content. |
105 | 104 | * This content is typically used to display the current view. |
106 | 105 | * |
107 | - * @param int $cache_time |
|
108 | 106 | * |
109 | 107 | * @return mixed |
110 | 108 | */ |
@@ -304,7 +302,7 @@ discard block |
||
304 | 302 | /** |
305 | 303 | * Returns the current theme. |
306 | 304 | * |
307 | - * @return mixed|string |
|
305 | + * @return string |
|
308 | 306 | */ |
309 | 307 | public function theme() |
310 | 308 | { |
@@ -343,7 +341,7 @@ discard block |
||
343 | 341 | /** |
344 | 342 | * Returns the current view. |
345 | 343 | * |
346 | - * @return mixed|string |
|
344 | + * @return string |
|
347 | 345 | */ |
348 | 346 | public function view() |
349 | 347 | { |
@@ -371,7 +369,7 @@ discard block |
||
371 | 369 | /** |
372 | 370 | * Returns the current layout. |
373 | 371 | * |
374 | - * @return mixed|string |
|
372 | + * @return string |
|
375 | 373 | */ |
376 | 374 | public function layout() |
377 | 375 | { |
@@ -425,7 +423,7 @@ discard block |
||
425 | 423 | * CodeIgniter's parser. |
426 | 424 | * |
427 | 425 | * @param bool $parse |
428 | - * @return mixed |
|
426 | + * @return ViewThemer |
|
429 | 427 | */ |
430 | 428 | public function parseViews($parse = false) |
431 | 429 | { |
@@ -444,7 +442,7 @@ discard block |
||
444 | 442 | * @param $alias The name the theme can be referenced by |
445 | 443 | * @param $path A new path where themes can be found. |
446 | 444 | * |
447 | - * @return mixed |
|
445 | + * @return ViewThemer |
|
448 | 446 | */ |
449 | 447 | public function addThemePath($alias, $path) |
450 | 448 | { |
@@ -525,7 +523,7 @@ discard block |
||
525 | 523 | * |
526 | 524 | * @param $name |
527 | 525 | * @param $postfix |
528 | - * @return $this|mixed |
|
526 | + * @return ViewThemer |
|
529 | 527 | */ |
530 | 528 | public function addVariant($name, $postfix) |
531 | 529 | { |
@@ -540,7 +538,7 @@ discard block |
||
540 | 538 | * Removes a variant from the system. |
541 | 539 | * |
542 | 540 | * @param $name |
543 | - * @return $this|mixed |
|
541 | + * @return ViewThemer |
|
544 | 542 | */ |
545 | 543 | public function removeVariant($name) |
546 | 544 | { |
@@ -35,70 +35,70 @@ discard block |
||
35 | 35 | class ViewThemer implements ThemerInterface |
36 | 36 | { |
37 | 37 | |
38 | - protected $theme = ''; |
|
38 | + protected $theme = ''; |
|
39 | 39 | |
40 | - protected $default_theme = null; |
|
40 | + protected $default_theme = null; |
|
41 | 41 | |
42 | 42 | protected $active_theme = null; |
43 | 43 | |
44 | - protected $layout = 'index'; |
|
44 | + protected $layout = 'index'; |
|
45 | 45 | |
46 | - protected $view = ''; |
|
46 | + protected $view = ''; |
|
47 | 47 | |
48 | - protected $vars = []; |
|
48 | + protected $vars = []; |
|
49 | 49 | |
50 | - protected $folders = []; |
|
50 | + protected $folders = []; |
|
51 | 51 | |
52 | - protected $variants = []; |
|
52 | + protected $variants = []; |
|
53 | 53 | |
54 | - protected $current_variant = ''; |
|
54 | + protected $current_variant = ''; |
|
55 | 55 | |
56 | 56 | protected $parse_views = false; |
57 | 57 | |
58 | - protected $ci; |
|
58 | + protected $ci; |
|
59 | 59 | |
60 | - //-------------------------------------------------------------------- |
|
60 | + //-------------------------------------------------------------------- |
|
61 | 61 | |
62 | - public function __construct($ci) |
|
63 | - { |
|
64 | - $this->ci = $ci; |
|
62 | + public function __construct($ci) |
|
63 | + { |
|
64 | + $this->ci = $ci; |
|
65 | 65 | |
66 | - $this->parse_views = config_item('theme.parse_views'); |
|
67 | - } |
|
66 | + $this->parse_views = config_item('theme.parse_views'); |
|
67 | + } |
|
68 | 68 | |
69 | - //-------------------------------------------------------------------- |
|
69 | + //-------------------------------------------------------------------- |
|
70 | 70 | |
71 | - /** |
|
72 | - * The main entryway into rendering a view. This is called from the |
|
73 | - * controller and is generally the last method called. |
|
74 | - * |
|
75 | - * @param string $layout If provided, will override the default layout. |
|
76 | - * @param int $cache_time The number of seconds to cache the output for. |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function render($layout = null) |
|
80 | - { |
|
81 | - // Make the template engine available within the views. |
|
82 | - $this->vars['themer'] = $this; |
|
71 | + /** |
|
72 | + * The main entryway into rendering a view. This is called from the |
|
73 | + * controller and is generally the last method called. |
|
74 | + * |
|
75 | + * @param string $layout If provided, will override the default layout. |
|
76 | + * @param int $cache_time The number of seconds to cache the output for. |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function render($layout = null) |
|
80 | + { |
|
81 | + // Make the template engine available within the views. |
|
82 | + $this->vars['themer'] = $this; |
|
83 | 83 | |
84 | - // Render our current view content |
|
85 | - $this->vars['view_content'] = $this->content(); |
|
84 | + // Render our current view content |
|
85 | + $this->vars['view_content'] = $this->content(); |
|
86 | 86 | |
87 | - $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
87 | + $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
88 | 88 | |
89 | - if (! isset($this->folders[$theme])) { |
|
90 | - throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
91 | - } |
|
89 | + if (! isset($this->folders[$theme])) { |
|
90 | + throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
91 | + } |
|
92 | 92 | |
93 | - $this->active_theme = $theme; |
|
93 | + $this->active_theme = $theme; |
|
94 | 94 | |
95 | - // Make the path available within views. |
|
96 | - $this->vars['theme_path'] = $this->folders[$theme]; |
|
95 | + // Make the path available within views. |
|
96 | + $this->vars['theme_path'] = $this->folders[$theme]; |
|
97 | 97 | |
98 | - return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
99 | - } |
|
98 | + return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
99 | + } |
|
100 | 100 | |
101 | - //-------------------------------------------------------------------- |
|
101 | + //-------------------------------------------------------------------- |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Used within the template layout file to render the current content. |
@@ -108,490 +108,490 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return mixed |
110 | 110 | */ |
111 | - public function content() |
|
112 | - { |
|
113 | - // Calc our view name based on current method/controller |
|
114 | - $dir = $this->ci->router->fetch_directory(); |
|
111 | + public function content() |
|
112 | + { |
|
113 | + // Calc our view name based on current method/controller |
|
114 | + $dir = $this->ci->router->fetch_directory(); |
|
115 | 115 | |
116 | - foreach (Modules::$locations as $key => $offset) { |
|
116 | + foreach (Modules::$locations as $key => $offset) { |
|
117 | 117 | |
118 | - if (stripos($dir, 'module') !== false) { |
|
118 | + if (stripos($dir, 'module') !== false) { |
|
119 | 119 | // $dir = str_replace($offset, '', $dir); |
120 | - $dir = str_replace('controllers/', '', $dir); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - $module = $this->ci->router->fetch_module(); |
|
125 | - |
|
126 | - if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
127 | - $dir = ''; |
|
128 | - } |
|
129 | - |
|
130 | - $view = ! empty($this->view) ? $this->view : |
|
131 | - $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
132 | - |
|
133 | - return $this->display($view); |
|
134 | - } |
|
135 | - |
|
136 | - //-------------------------------------------------------------------- |
|
137 | - |
|
138 | - /** |
|
139 | - * Loads a view file. Useful to control caching. Intended for use |
|
140 | - * from within view files. |
|
141 | - * |
|
142 | - * You can specify that a view should belong to a theme by prefixing |
|
143 | - * the name of the theme and a colon to the view name. For example, |
|
144 | - * "admin:header" would try to display the "header.php" file within |
|
145 | - * the "admin" theme. |
|
146 | - * |
|
147 | - * If a variant has been specified, it will be added to the end |
|
148 | - * of the view name before looking for the file. |
|
149 | - * |
|
150 | - * @param string $view |
|
151 | - * @param array $data |
|
152 | - * @param int $cache_time Number of minutes to cache the page for |
|
153 | - * @param string $cache_name A custom name for the cached file. |
|
154 | - * @return mixed |
|
155 | - */ |
|
156 | - public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
157 | - { |
|
158 | - if (empty($cache_name)) |
|
159 | - { |
|
160 | - $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
161 | - $cache_name = str_replace( '/', '_', $cache_name ); |
|
162 | - } |
|
163 | - |
|
164 | - if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
|
165 | - { |
|
166 | - $theme = NULL; |
|
167 | - $variant_view = NULL; |
|
168 | - |
|
169 | - // Pull out the theme from the view, if given. |
|
170 | - if ( strpos( $view, ':' ) !== FALSE ) |
|
171 | - { |
|
172 | - list( $theme, $view ) = explode( ':', $view ); |
|
173 | - |
|
174 | - $theme = str_replace('{theme}', $this->active_theme, $theme); |
|
175 | - } |
|
176 | - |
|
177 | - if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
178 | - { |
|
179 | - $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
180 | - } |
|
181 | - |
|
182 | - if (! is_array($data)) |
|
183 | - { |
|
184 | - $data = []; |
|
185 | - } |
|
186 | - |
|
187 | - $data = array_merge( $this->vars, $data ); |
|
188 | - |
|
189 | - // if using a variant, add it to the view name. |
|
190 | - if ( ! empty( $this->current_variant ) ) |
|
191 | - { |
|
192 | - $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
193 | - |
|
194 | - $output = $this->loadView($variant_view, $data); |
|
195 | - } |
|
196 | - |
|
197 | - // If that didn't find anything, then try it without a variant |
|
198 | - if ( empty( $output ) ) |
|
199 | - { |
|
200 | - $output = $this->loadView($view, $data); |
|
201 | - } |
|
202 | - |
|
203 | - // Cache it |
|
204 | - if ((int)$cache_time > 0) |
|
205 | - { |
|
206 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - // Parse views? |
|
211 | - if ($this->parse_views) |
|
212 | - { |
|
213 | - $this->ci->load->library('parser'); |
|
214 | - |
|
215 | - // Any class objects will cause failure |
|
216 | - // so get rid of those bad boys.... |
|
217 | - unset($data['uikit'], $data['themer']); |
|
218 | - |
|
219 | - $output = $this->ci->parser->parse_string($output, $data, true); |
|
220 | - } |
|
221 | - |
|
222 | - return $output; |
|
223 | - } |
|
224 | - |
|
225 | - //-------------------------------------------------------------------- |
|
226 | - |
|
227 | - /** |
|
228 | - * Runs a callback method and returns the contents to the view. |
|
229 | - * |
|
230 | - * @param $command |
|
231 | - * @param int $cache_time |
|
232 | - * @param string $cache_name // Number of MINUTES to cache output |
|
233 | - * @return mixed|void |
|
234 | - */ |
|
235 | - public function call($command, $cache_time=0, $cache_name=null) |
|
236 | - { |
|
237 | - if (empty($cache_name)) |
|
238 | - { |
|
239 | - $cache_name = 'theme_call_' . md5( $command ); |
|
240 | - } |
|
241 | - |
|
242 | - if (! $output = $this->ci->cache->get($cache_name)) { |
|
243 | - $parts = explode(' ', $command); |
|
244 | - |
|
245 | - list($class, $method) = explode(':', array_shift($parts)); |
|
246 | - |
|
247 | - // Prepare our parameter list to send to the callback |
|
248 | - // by splitting $parts on equal signs. |
|
249 | - $params = array(); |
|
250 | - |
|
251 | - foreach ($parts as $part) { |
|
252 | - $p = explode('=', $part); |
|
253 | - |
|
254 | - if (empty($p[0]) || empty($p[1])) |
|
255 | - { |
|
256 | - continue; |
|
257 | - } |
|
258 | - |
|
259 | - $params[ $p[0] ] = $p[1]; |
|
260 | - } |
|
261 | - |
|
262 | - // Let PHP try to autoload it through any available autoloaders |
|
263 | - // (including Composer and user's custom autoloaders). If we |
|
264 | - // don't find it, then assume it's a CI library that we can reach. |
|
265 | - if (class_exists($class)) { |
|
266 | - $class = new $class(); |
|
267 | - } else { |
|
268 | - $this->ci->load->library($class); |
|
269 | - $class =& $this->ci->$class; |
|
270 | - } |
|
271 | - |
|
272 | - if (! method_exists($class, $method)) { |
|
273 | - throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
274 | - } |
|
275 | - |
|
276 | - // Call the class with our parameters |
|
277 | - $output = $class->{$method}($params); |
|
278 | - |
|
279 | - // Cache it |
|
280 | - if ((int)$cache_time > 0) |
|
281 | - { |
|
282 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - return $output; |
|
287 | - } |
|
288 | - |
|
289 | - //-------------------------------------------------------------------- |
|
290 | - |
|
291 | - /** |
|
292 | - * Sets the active theme to use. This theme should be |
|
293 | - * relative to one of the 'theme_paths' folders. |
|
294 | - * |
|
295 | - * @param $theme |
|
296 | - */ |
|
297 | - public function setTheme($theme) |
|
298 | - { |
|
299 | - $this->theme = $theme; |
|
300 | - } |
|
301 | - |
|
302 | - //-------------------------------------------------------------------- |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns the current theme. |
|
306 | - * |
|
307 | - * @return mixed|string |
|
308 | - */ |
|
309 | - public function theme() |
|
310 | - { |
|
311 | - return $this->theme; |
|
312 | - } |
|
313 | - |
|
314 | - //-------------------------------------------------------------------- |
|
315 | - |
|
316 | - /** |
|
317 | - * Sets the default theme to use if another isn't specified. |
|
318 | - * |
|
319 | - * @param $theme |
|
320 | - * @return mixed|void |
|
321 | - */ |
|
322 | - public function setDefaultTheme($theme) |
|
323 | - { |
|
324 | - $this->default_theme = $theme; |
|
325 | - } |
|
326 | - |
|
327 | - //-------------------------------------------------------------------- |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Sets the current view file to render. |
|
332 | - * |
|
333 | - * @param $file |
|
334 | - * @return mixed |
|
335 | - */ |
|
336 | - public function setView($file) |
|
337 | - { |
|
338 | - $this->view = $file; |
|
339 | - } |
|
340 | - |
|
341 | - //-------------------------------------------------------------------- |
|
342 | - |
|
343 | - /** |
|
344 | - * Returns the current view. |
|
345 | - * |
|
346 | - * @return mixed|string |
|
347 | - */ |
|
348 | - public function view() |
|
349 | - { |
|
350 | - return $this->view; |
|
351 | - } |
|
352 | - |
|
353 | - //-------------------------------------------------------------------- |
|
354 | - |
|
355 | - /** |
|
356 | - * Sets the current layout to be used. MUST be the name of one of |
|
357 | - * the layout files within the current theme. Case-sensitive. |
|
358 | - * |
|
359 | - * @param $file |
|
360 | - * @return mixed |
|
361 | - */ |
|
362 | - public function setLayout($file) |
|
363 | - { |
|
364 | - if (empty($file)) return; |
|
365 | - |
|
366 | - $this->layout = $file; |
|
367 | - } |
|
368 | - |
|
369 | - //-------------------------------------------------------------------- |
|
370 | - |
|
371 | - /** |
|
372 | - * Returns the current layout. |
|
373 | - * |
|
374 | - * @return mixed|string |
|
375 | - */ |
|
376 | - public function layout() |
|
377 | - { |
|
378 | - return $this->layout; |
|
379 | - } |
|
380 | - |
|
381 | - //-------------------------------------------------------------------- |
|
382 | - |
|
383 | - /** |
|
384 | - * Stores one or more pieces of data to be passed to the views when |
|
385 | - * they are rendered out. |
|
386 | - * |
|
387 | - * If both $key and $value are ! empty, then it will treat it as a |
|
388 | - * key/value pair. If $key is an array of key/value pairs, then $value |
|
389 | - * is ignored and each element of the array are made available to the |
|
390 | - * view as if it was a single $key/$value pair. |
|
391 | - * |
|
392 | - * @param string|array $key |
|
393 | - * @param mixed $value |
|
394 | - * @return $this |
|
395 | - */ |
|
396 | - public function set($key, $value = null) |
|
397 | - { |
|
398 | - if (is_array($key)) { |
|
399 | - $this->vars = array_merge($this->vars, $key); |
|
400 | - return; |
|
401 | - } |
|
402 | - |
|
403 | - $this->vars[$key] = $value; |
|
404 | - |
|
405 | - return $this; |
|
406 | - } |
|
407 | - |
|
408 | - //-------------------------------------------------------------------- |
|
409 | - |
|
410 | - /** |
|
411 | - * Returns a value that has been previously set(). |
|
412 | - * |
|
413 | - * @param $key |
|
414 | - * @return mixed |
|
415 | - */ |
|
416 | - public function get($key) |
|
417 | - { |
|
418 | - return isset($this->vars[$key]) ? $this->vars[$key] : null; |
|
419 | - } |
|
420 | - |
|
421 | - //-------------------------------------------------------------------- |
|
422 | - |
|
423 | - /** |
|
424 | - * Determines whether or not the view should be parsed with the |
|
425 | - * CodeIgniter's parser. |
|
426 | - * |
|
427 | - * @param bool $parse |
|
428 | - * @return mixed |
|
429 | - */ |
|
430 | - public function parseViews($parse = false) |
|
431 | - { |
|
432 | - $this->parse_views = $parse; |
|
433 | - |
|
434 | - return $this; |
|
435 | - } |
|
436 | - |
|
437 | - //-------------------------------------------------------------------- |
|
438 | - |
|
439 | - /** |
|
440 | - * Theme paths allow you to have multiple locations for themes to be |
|
441 | - * stored. This might be used for separating themes for different sub- |
|
442 | - * applications, or a core theme and user-submitted themes. |
|
443 | - * |
|
444 | - * @param $alias The name the theme can be referenced by |
|
445 | - * @param $path A new path where themes can be found. |
|
446 | - * |
|
447 | - * @return mixed |
|
448 | - */ |
|
449 | - public function addThemePath($alias, $path) |
|
450 | - { |
|
451 | - $this->folders[$alias] = $path; |
|
452 | - |
|
453 | - return $this; |
|
454 | - } |
|
455 | - |
|
456 | - //-------------------------------------------------------------------- |
|
457 | - |
|
458 | - /** |
|
459 | - * Removes a single theme path. |
|
460 | - * |
|
461 | - * @param $alias |
|
462 | - * @return $this |
|
463 | - */ |
|
464 | - public function removeThemePath($alias) |
|
465 | - { |
|
466 | - unset($this->folders[$alias]); |
|
467 | - |
|
468 | - return $this; |
|
469 | - } |
|
470 | - |
|
471 | - //-------------------------------------------------------------------- |
|
472 | - |
|
473 | - /** |
|
474 | - * Returns the path to the active/default theme's folder. |
|
475 | - * |
|
476 | - * @return string|null |
|
477 | - */ |
|
478 | - public function getThemePath() |
|
479 | - { |
|
480 | - $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
481 | - |
|
482 | - if (! isset($this->folders[ $theme ])) |
|
483 | - { |
|
484 | - return null; |
|
485 | - } |
|
486 | - |
|
487 | - return $this->folders[$theme]; |
|
488 | - } |
|
489 | - |
|
490 | - //-------------------------------------------------------------------- |
|
491 | - |
|
492 | - |
|
493 | - |
|
494 | - //-------------------------------------------------------------------- |
|
495 | - // Variants |
|
496 | - //-------------------------------------------------------------------- |
|
497 | - |
|
498 | - /** |
|
499 | - * Sets the variant used when creating view names. These variants can |
|
500 | - * be anything, but by default are used to render specific templates |
|
501 | - * for desktop, tablet, and phone. The name of the variant is added |
|
502 | - * to the view name, joined by a "+" symbol. |
|
503 | - * |
|
504 | - * Example: |
|
505 | - * $this->setVariant('phone'); |
|
506 | - * $this->display('header'); |
|
507 | - * |
|
508 | - * Tries to display "views/header+phone.php" |
|
509 | - * |
|
510 | - * @param $variant |
|
511 | - * @return $this |
|
512 | - */ |
|
513 | - public function setVariant($variant) |
|
514 | - { |
|
515 | - if (isset($this->variants[$variant])) { |
|
516 | - $this->current_variant = $variant; |
|
517 | - } |
|
518 | - |
|
519 | - return $this; |
|
520 | - } |
|
521 | - //-------------------------------------------------------------------- |
|
522 | - |
|
523 | - /** |
|
524 | - * Adds a new variant to the system. |
|
525 | - * |
|
526 | - * @param $name |
|
527 | - * @param $postfix |
|
528 | - * @return $this|mixed |
|
529 | - */ |
|
530 | - public function addVariant($name, $postfix) |
|
531 | - { |
|
532 | - $this->variants[$name] = $postfix; |
|
533 | - |
|
534 | - return $this; |
|
535 | - } |
|
536 | - |
|
537 | - //-------------------------------------------------------------------- |
|
538 | - |
|
539 | - /** |
|
540 | - * Removes a variant from the system. |
|
541 | - * |
|
542 | - * @param $name |
|
543 | - * @return $this|mixed |
|
544 | - */ |
|
545 | - public function removeVariant($name) |
|
546 | - { |
|
547 | - if (isset($this->variants[$name])) { |
|
548 | - unset($this->variants[$name]); |
|
549 | - } |
|
550 | - |
|
551 | - return $this; |
|
552 | - } |
|
553 | - |
|
554 | - //-------------------------------------------------------------------- |
|
555 | - // Private Methods |
|
556 | - //-------------------------------------------------------------------- |
|
557 | - |
|
558 | - /** |
|
559 | - * Handles the actual loading of a view file, and checks for any |
|
560 | - * overrides in themes, etc. |
|
561 | - * |
|
562 | - * @param $view |
|
563 | - * @param $data |
|
564 | - * |
|
565 | - * @return string |
|
566 | - */ |
|
567 | - private function loadView($view, $data) |
|
568 | - { |
|
569 | - // First - does it exist in the current theme? |
|
570 | - $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
|
571 | - $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
|
572 | - $theme = rtrim($theme, '/ ') .'/'; |
|
573 | - |
|
574 | - if (file_exists($theme ."{$view}.php")) |
|
575 | - { |
|
576 | - $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
577 | - } |
|
578 | - |
|
579 | - // Next, if it's a real file with path, then load it |
|
580 | - elseif ( realpath( $view . '.php' ) ) |
|
581 | - { |
|
582 | - $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
583 | - } |
|
584 | - |
|
585 | - // Otherwise, treat it as a standard view, which means |
|
586 | - // application/views will override any modules. (See HMVC/Loader) |
|
587 | - else |
|
588 | - { |
|
589 | - $output = $this->ci->load->view( $view, $data, TRUE ); |
|
590 | - } |
|
591 | - |
|
592 | - return $output; |
|
593 | - } |
|
594 | - |
|
595 | - //-------------------------------------------------------------------- |
|
120 | + $dir = str_replace('controllers/', '', $dir); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + $module = $this->ci->router->fetch_module(); |
|
125 | + |
|
126 | + if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
127 | + $dir = ''; |
|
128 | + } |
|
129 | + |
|
130 | + $view = ! empty($this->view) ? $this->view : |
|
131 | + $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
132 | + |
|
133 | + return $this->display($view); |
|
134 | + } |
|
135 | + |
|
136 | + //-------------------------------------------------------------------- |
|
137 | + |
|
138 | + /** |
|
139 | + * Loads a view file. Useful to control caching. Intended for use |
|
140 | + * from within view files. |
|
141 | + * |
|
142 | + * You can specify that a view should belong to a theme by prefixing |
|
143 | + * the name of the theme and a colon to the view name. For example, |
|
144 | + * "admin:header" would try to display the "header.php" file within |
|
145 | + * the "admin" theme. |
|
146 | + * |
|
147 | + * If a variant has been specified, it will be added to the end |
|
148 | + * of the view name before looking for the file. |
|
149 | + * |
|
150 | + * @param string $view |
|
151 | + * @param array $data |
|
152 | + * @param int $cache_time Number of minutes to cache the page for |
|
153 | + * @param string $cache_name A custom name for the cached file. |
|
154 | + * @return mixed |
|
155 | + */ |
|
156 | + public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
157 | + { |
|
158 | + if (empty($cache_name)) |
|
159 | + { |
|
160 | + $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
161 | + $cache_name = str_replace( '/', '_', $cache_name ); |
|
162 | + } |
|
163 | + |
|
164 | + if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
|
165 | + { |
|
166 | + $theme = NULL; |
|
167 | + $variant_view = NULL; |
|
168 | + |
|
169 | + // Pull out the theme from the view, if given. |
|
170 | + if ( strpos( $view, ':' ) !== FALSE ) |
|
171 | + { |
|
172 | + list( $theme, $view ) = explode( ':', $view ); |
|
173 | + |
|
174 | + $theme = str_replace('{theme}', $this->active_theme, $theme); |
|
175 | + } |
|
176 | + |
|
177 | + if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
178 | + { |
|
179 | + $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
180 | + } |
|
181 | + |
|
182 | + if (! is_array($data)) |
|
183 | + { |
|
184 | + $data = []; |
|
185 | + } |
|
186 | + |
|
187 | + $data = array_merge( $this->vars, $data ); |
|
188 | + |
|
189 | + // if using a variant, add it to the view name. |
|
190 | + if ( ! empty( $this->current_variant ) ) |
|
191 | + { |
|
192 | + $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
193 | + |
|
194 | + $output = $this->loadView($variant_view, $data); |
|
195 | + } |
|
196 | + |
|
197 | + // If that didn't find anything, then try it without a variant |
|
198 | + if ( empty( $output ) ) |
|
199 | + { |
|
200 | + $output = $this->loadView($view, $data); |
|
201 | + } |
|
202 | + |
|
203 | + // Cache it |
|
204 | + if ((int)$cache_time > 0) |
|
205 | + { |
|
206 | + $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + // Parse views? |
|
211 | + if ($this->parse_views) |
|
212 | + { |
|
213 | + $this->ci->load->library('parser'); |
|
214 | + |
|
215 | + // Any class objects will cause failure |
|
216 | + // so get rid of those bad boys.... |
|
217 | + unset($data['uikit'], $data['themer']); |
|
218 | + |
|
219 | + $output = $this->ci->parser->parse_string($output, $data, true); |
|
220 | + } |
|
221 | + |
|
222 | + return $output; |
|
223 | + } |
|
224 | + |
|
225 | + //-------------------------------------------------------------------- |
|
226 | + |
|
227 | + /** |
|
228 | + * Runs a callback method and returns the contents to the view. |
|
229 | + * |
|
230 | + * @param $command |
|
231 | + * @param int $cache_time |
|
232 | + * @param string $cache_name // Number of MINUTES to cache output |
|
233 | + * @return mixed|void |
|
234 | + */ |
|
235 | + public function call($command, $cache_time=0, $cache_name=null) |
|
236 | + { |
|
237 | + if (empty($cache_name)) |
|
238 | + { |
|
239 | + $cache_name = 'theme_call_' . md5( $command ); |
|
240 | + } |
|
241 | + |
|
242 | + if (! $output = $this->ci->cache->get($cache_name)) { |
|
243 | + $parts = explode(' ', $command); |
|
244 | + |
|
245 | + list($class, $method) = explode(':', array_shift($parts)); |
|
246 | + |
|
247 | + // Prepare our parameter list to send to the callback |
|
248 | + // by splitting $parts on equal signs. |
|
249 | + $params = array(); |
|
250 | + |
|
251 | + foreach ($parts as $part) { |
|
252 | + $p = explode('=', $part); |
|
253 | + |
|
254 | + if (empty($p[0]) || empty($p[1])) |
|
255 | + { |
|
256 | + continue; |
|
257 | + } |
|
258 | + |
|
259 | + $params[ $p[0] ] = $p[1]; |
|
260 | + } |
|
261 | + |
|
262 | + // Let PHP try to autoload it through any available autoloaders |
|
263 | + // (including Composer and user's custom autoloaders). If we |
|
264 | + // don't find it, then assume it's a CI library that we can reach. |
|
265 | + if (class_exists($class)) { |
|
266 | + $class = new $class(); |
|
267 | + } else { |
|
268 | + $this->ci->load->library($class); |
|
269 | + $class =& $this->ci->$class; |
|
270 | + } |
|
271 | + |
|
272 | + if (! method_exists($class, $method)) { |
|
273 | + throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
274 | + } |
|
275 | + |
|
276 | + // Call the class with our parameters |
|
277 | + $output = $class->{$method}($params); |
|
278 | + |
|
279 | + // Cache it |
|
280 | + if ((int)$cache_time > 0) |
|
281 | + { |
|
282 | + $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + return $output; |
|
287 | + } |
|
288 | + |
|
289 | + //-------------------------------------------------------------------- |
|
290 | + |
|
291 | + /** |
|
292 | + * Sets the active theme to use. This theme should be |
|
293 | + * relative to one of the 'theme_paths' folders. |
|
294 | + * |
|
295 | + * @param $theme |
|
296 | + */ |
|
297 | + public function setTheme($theme) |
|
298 | + { |
|
299 | + $this->theme = $theme; |
|
300 | + } |
|
301 | + |
|
302 | + //-------------------------------------------------------------------- |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns the current theme. |
|
306 | + * |
|
307 | + * @return mixed|string |
|
308 | + */ |
|
309 | + public function theme() |
|
310 | + { |
|
311 | + return $this->theme; |
|
312 | + } |
|
313 | + |
|
314 | + //-------------------------------------------------------------------- |
|
315 | + |
|
316 | + /** |
|
317 | + * Sets the default theme to use if another isn't specified. |
|
318 | + * |
|
319 | + * @param $theme |
|
320 | + * @return mixed|void |
|
321 | + */ |
|
322 | + public function setDefaultTheme($theme) |
|
323 | + { |
|
324 | + $this->default_theme = $theme; |
|
325 | + } |
|
326 | + |
|
327 | + //-------------------------------------------------------------------- |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Sets the current view file to render. |
|
332 | + * |
|
333 | + * @param $file |
|
334 | + * @return mixed |
|
335 | + */ |
|
336 | + public function setView($file) |
|
337 | + { |
|
338 | + $this->view = $file; |
|
339 | + } |
|
340 | + |
|
341 | + //-------------------------------------------------------------------- |
|
342 | + |
|
343 | + /** |
|
344 | + * Returns the current view. |
|
345 | + * |
|
346 | + * @return mixed|string |
|
347 | + */ |
|
348 | + public function view() |
|
349 | + { |
|
350 | + return $this->view; |
|
351 | + } |
|
352 | + |
|
353 | + //-------------------------------------------------------------------- |
|
354 | + |
|
355 | + /** |
|
356 | + * Sets the current layout to be used. MUST be the name of one of |
|
357 | + * the layout files within the current theme. Case-sensitive. |
|
358 | + * |
|
359 | + * @param $file |
|
360 | + * @return mixed |
|
361 | + */ |
|
362 | + public function setLayout($file) |
|
363 | + { |
|
364 | + if (empty($file)) return; |
|
365 | + |
|
366 | + $this->layout = $file; |
|
367 | + } |
|
368 | + |
|
369 | + //-------------------------------------------------------------------- |
|
370 | + |
|
371 | + /** |
|
372 | + * Returns the current layout. |
|
373 | + * |
|
374 | + * @return mixed|string |
|
375 | + */ |
|
376 | + public function layout() |
|
377 | + { |
|
378 | + return $this->layout; |
|
379 | + } |
|
380 | + |
|
381 | + //-------------------------------------------------------------------- |
|
382 | + |
|
383 | + /** |
|
384 | + * Stores one or more pieces of data to be passed to the views when |
|
385 | + * they are rendered out. |
|
386 | + * |
|
387 | + * If both $key and $value are ! empty, then it will treat it as a |
|
388 | + * key/value pair. If $key is an array of key/value pairs, then $value |
|
389 | + * is ignored and each element of the array are made available to the |
|
390 | + * view as if it was a single $key/$value pair. |
|
391 | + * |
|
392 | + * @param string|array $key |
|
393 | + * @param mixed $value |
|
394 | + * @return $this |
|
395 | + */ |
|
396 | + public function set($key, $value = null) |
|
397 | + { |
|
398 | + if (is_array($key)) { |
|
399 | + $this->vars = array_merge($this->vars, $key); |
|
400 | + return; |
|
401 | + } |
|
402 | + |
|
403 | + $this->vars[$key] = $value; |
|
404 | + |
|
405 | + return $this; |
|
406 | + } |
|
407 | + |
|
408 | + //-------------------------------------------------------------------- |
|
409 | + |
|
410 | + /** |
|
411 | + * Returns a value that has been previously set(). |
|
412 | + * |
|
413 | + * @param $key |
|
414 | + * @return mixed |
|
415 | + */ |
|
416 | + public function get($key) |
|
417 | + { |
|
418 | + return isset($this->vars[$key]) ? $this->vars[$key] : null; |
|
419 | + } |
|
420 | + |
|
421 | + //-------------------------------------------------------------------- |
|
422 | + |
|
423 | + /** |
|
424 | + * Determines whether or not the view should be parsed with the |
|
425 | + * CodeIgniter's parser. |
|
426 | + * |
|
427 | + * @param bool $parse |
|
428 | + * @return mixed |
|
429 | + */ |
|
430 | + public function parseViews($parse = false) |
|
431 | + { |
|
432 | + $this->parse_views = $parse; |
|
433 | + |
|
434 | + return $this; |
|
435 | + } |
|
436 | + |
|
437 | + //-------------------------------------------------------------------- |
|
438 | + |
|
439 | + /** |
|
440 | + * Theme paths allow you to have multiple locations for themes to be |
|
441 | + * stored. This might be used for separating themes for different sub- |
|
442 | + * applications, or a core theme and user-submitted themes. |
|
443 | + * |
|
444 | + * @param $alias The name the theme can be referenced by |
|
445 | + * @param $path A new path where themes can be found. |
|
446 | + * |
|
447 | + * @return mixed |
|
448 | + */ |
|
449 | + public function addThemePath($alias, $path) |
|
450 | + { |
|
451 | + $this->folders[$alias] = $path; |
|
452 | + |
|
453 | + return $this; |
|
454 | + } |
|
455 | + |
|
456 | + //-------------------------------------------------------------------- |
|
457 | + |
|
458 | + /** |
|
459 | + * Removes a single theme path. |
|
460 | + * |
|
461 | + * @param $alias |
|
462 | + * @return $this |
|
463 | + */ |
|
464 | + public function removeThemePath($alias) |
|
465 | + { |
|
466 | + unset($this->folders[$alias]); |
|
467 | + |
|
468 | + return $this; |
|
469 | + } |
|
470 | + |
|
471 | + //-------------------------------------------------------------------- |
|
472 | + |
|
473 | + /** |
|
474 | + * Returns the path to the active/default theme's folder. |
|
475 | + * |
|
476 | + * @return string|null |
|
477 | + */ |
|
478 | + public function getThemePath() |
|
479 | + { |
|
480 | + $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
481 | + |
|
482 | + if (! isset($this->folders[ $theme ])) |
|
483 | + { |
|
484 | + return null; |
|
485 | + } |
|
486 | + |
|
487 | + return $this->folders[$theme]; |
|
488 | + } |
|
489 | + |
|
490 | + //-------------------------------------------------------------------- |
|
491 | + |
|
492 | + |
|
493 | + |
|
494 | + //-------------------------------------------------------------------- |
|
495 | + // Variants |
|
496 | + //-------------------------------------------------------------------- |
|
497 | + |
|
498 | + /** |
|
499 | + * Sets the variant used when creating view names. These variants can |
|
500 | + * be anything, but by default are used to render specific templates |
|
501 | + * for desktop, tablet, and phone. The name of the variant is added |
|
502 | + * to the view name, joined by a "+" symbol. |
|
503 | + * |
|
504 | + * Example: |
|
505 | + * $this->setVariant('phone'); |
|
506 | + * $this->display('header'); |
|
507 | + * |
|
508 | + * Tries to display "views/header+phone.php" |
|
509 | + * |
|
510 | + * @param $variant |
|
511 | + * @return $this |
|
512 | + */ |
|
513 | + public function setVariant($variant) |
|
514 | + { |
|
515 | + if (isset($this->variants[$variant])) { |
|
516 | + $this->current_variant = $variant; |
|
517 | + } |
|
518 | + |
|
519 | + return $this; |
|
520 | + } |
|
521 | + //-------------------------------------------------------------------- |
|
522 | + |
|
523 | + /** |
|
524 | + * Adds a new variant to the system. |
|
525 | + * |
|
526 | + * @param $name |
|
527 | + * @param $postfix |
|
528 | + * @return $this|mixed |
|
529 | + */ |
|
530 | + public function addVariant($name, $postfix) |
|
531 | + { |
|
532 | + $this->variants[$name] = $postfix; |
|
533 | + |
|
534 | + return $this; |
|
535 | + } |
|
536 | + |
|
537 | + //-------------------------------------------------------------------- |
|
538 | + |
|
539 | + /** |
|
540 | + * Removes a variant from the system. |
|
541 | + * |
|
542 | + * @param $name |
|
543 | + * @return $this|mixed |
|
544 | + */ |
|
545 | + public function removeVariant($name) |
|
546 | + { |
|
547 | + if (isset($this->variants[$name])) { |
|
548 | + unset($this->variants[$name]); |
|
549 | + } |
|
550 | + |
|
551 | + return $this; |
|
552 | + } |
|
553 | + |
|
554 | + //-------------------------------------------------------------------- |
|
555 | + // Private Methods |
|
556 | + //-------------------------------------------------------------------- |
|
557 | + |
|
558 | + /** |
|
559 | + * Handles the actual loading of a view file, and checks for any |
|
560 | + * overrides in themes, etc. |
|
561 | + * |
|
562 | + * @param $view |
|
563 | + * @param $data |
|
564 | + * |
|
565 | + * @return string |
|
566 | + */ |
|
567 | + private function loadView($view, $data) |
|
568 | + { |
|
569 | + // First - does it exist in the current theme? |
|
570 | + $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
|
571 | + $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
|
572 | + $theme = rtrim($theme, '/ ') .'/'; |
|
573 | + |
|
574 | + if (file_exists($theme ."{$view}.php")) |
|
575 | + { |
|
576 | + $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
577 | + } |
|
578 | + |
|
579 | + // Next, if it's a real file with path, then load it |
|
580 | + elseif ( realpath( $view . '.php' ) ) |
|
581 | + { |
|
582 | + $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
583 | + } |
|
584 | + |
|
585 | + // Otherwise, treat it as a standard view, which means |
|
586 | + // application/views will override any modules. (See HMVC/Loader) |
|
587 | + else |
|
588 | + { |
|
589 | + $output = $this->ci->load->view( $view, $data, TRUE ); |
|
590 | + } |
|
591 | + |
|
592 | + return $output; |
|
593 | + } |
|
594 | + |
|
595 | + //-------------------------------------------------------------------- |
|
596 | 596 | |
597 | 597 | } |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | |
87 | 87 | $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
88 | 88 | |
89 | - if (! isset($this->folders[$theme])) { |
|
90 | - throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
89 | + if ( ! isset($this->folders[$theme])) { |
|
90 | + throw new \LogicException(sprintf(lang('theme.bad_folder'), $theme)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $this->active_theme = $theme; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | // Make the path available within views. |
96 | 96 | $this->vars['theme_path'] = $this->folders[$theme]; |
97 | 97 | |
98 | - return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
98 | + return $this->display($this->folders[$theme].'/'.$this->layout); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | //-------------------------------------------------------------------- |
@@ -123,12 +123,11 @@ discard block |
||
123 | 123 | |
124 | 124 | $module = $this->ci->router->fetch_module(); |
125 | 125 | |
126 | - if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
126 | + if ( ! empty($module) && substr($dir, -strlen($module.'/')) == $module.'/') { |
|
127 | 127 | $dir = ''; |
128 | 128 | } |
129 | 129 | |
130 | - $view = ! empty($this->view) ? $this->view : |
|
131 | - $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
130 | + $view = ! empty($this->view) ? $this->view : $dir.$this->ci->router->fetch_class().'/'.$this->ci->router->fetch_method(); |
|
132 | 131 | |
133 | 132 | return $this->display($view); |
134 | 133 | } |
@@ -153,12 +152,12 @@ discard block |
||
153 | 152 | * @param string $cache_name A custom name for the cached file. |
154 | 153 | * @return mixed |
155 | 154 | */ |
156 | - public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
155 | + public function display($view, $data = array(), $cache_time = 0, $cache_name = null) |
|
157 | 156 | { |
158 | 157 | if (empty($cache_name)) |
159 | 158 | { |
160 | - $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
161 | - $cache_name = str_replace( '/', '_', $cache_name ); |
|
159 | + $cache_name = 'theme_view_'.$view.'_'.$this->ci->router->fetch_class().'_'.$this->ci->router->fetch_method(); |
|
160 | + $cache_name = str_replace('/', '_', $cache_name); |
|
162 | 161 | } |
163 | 162 | |
164 | 163 | if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
@@ -167,43 +166,43 @@ discard block |
||
167 | 166 | $variant_view = NULL; |
168 | 167 | |
169 | 168 | // Pull out the theme from the view, if given. |
170 | - if ( strpos( $view, ':' ) !== FALSE ) |
|
169 | + if (strpos($view, ':') !== FALSE) |
|
171 | 170 | { |
172 | - list( $theme, $view ) = explode( ':', $view ); |
|
171 | + list($theme, $view) = explode(':', $view); |
|
173 | 172 | |
174 | 173 | $theme = str_replace('{theme}', $this->active_theme, $theme); |
175 | 174 | } |
176 | 175 | |
177 | - if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
176 | + if ( ! empty($theme) && isset($this->folders[$theme])) |
|
178 | 177 | { |
179 | - $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
178 | + $view = rtrim($this->folders[$theme], '/').'/'.$view; |
|
180 | 179 | } |
181 | 180 | |
182 | - if (! is_array($data)) |
|
181 | + if ( ! is_array($data)) |
|
183 | 182 | { |
184 | 183 | $data = []; |
185 | 184 | } |
186 | 185 | |
187 | - $data = array_merge( $this->vars, $data ); |
|
186 | + $data = array_merge($this->vars, $data); |
|
188 | 187 | |
189 | 188 | // if using a variant, add it to the view name. |
190 | - if ( ! empty( $this->current_variant ) ) |
|
189 | + if ( ! empty($this->current_variant)) |
|
191 | 190 | { |
192 | - $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
191 | + $variant_view = $view.$this->variants[$this->current_variant]; |
|
193 | 192 | |
194 | 193 | $output = $this->loadView($variant_view, $data); |
195 | 194 | } |
196 | 195 | |
197 | 196 | // If that didn't find anything, then try it without a variant |
198 | - if ( empty( $output ) ) |
|
197 | + if (empty($output)) |
|
199 | 198 | { |
200 | 199 | $output = $this->loadView($view, $data); |
201 | 200 | } |
202 | 201 | |
203 | 202 | // Cache it |
204 | - if ((int)$cache_time > 0) |
|
203 | + if ((int) $cache_time > 0) |
|
205 | 204 | { |
206 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
205 | + $this->ci->cache->save($cache_name, $output, (int) $cache_time * 60); |
|
207 | 206 | } |
208 | 207 | } |
209 | 208 | |
@@ -232,14 +231,14 @@ discard block |
||
232 | 231 | * @param string $cache_name // Number of MINUTES to cache output |
233 | 232 | * @return mixed|void |
234 | 233 | */ |
235 | - public function call($command, $cache_time=0, $cache_name=null) |
|
234 | + public function call($command, $cache_time = 0, $cache_name = null) |
|
236 | 235 | { |
237 | 236 | if (empty($cache_name)) |
238 | 237 | { |
239 | - $cache_name = 'theme_call_' . md5( $command ); |
|
238 | + $cache_name = 'theme_call_'.md5($command); |
|
240 | 239 | } |
241 | 240 | |
242 | - if (! $output = $this->ci->cache->get($cache_name)) { |
|
241 | + if ( ! $output = $this->ci->cache->get($cache_name)) { |
|
243 | 242 | $parts = explode(' ', $command); |
244 | 243 | |
245 | 244 | list($class, $method) = explode(':', array_shift($parts)); |
@@ -256,7 +255,7 @@ discard block |
||
256 | 255 | continue; |
257 | 256 | } |
258 | 257 | |
259 | - $params[ $p[0] ] = $p[1]; |
|
258 | + $params[$p[0]] = $p[1]; |
|
260 | 259 | } |
261 | 260 | |
262 | 261 | // Let PHP try to autoload it through any available autoloaders |
@@ -266,20 +265,20 @@ discard block |
||
266 | 265 | $class = new $class(); |
267 | 266 | } else { |
268 | 267 | $this->ci->load->library($class); |
269 | - $class =& $this->ci->$class; |
|
268 | + $class = & $this->ci->$class; |
|
270 | 269 | } |
271 | 270 | |
272 | - if (! method_exists($class, $method)) { |
|
273 | - throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
271 | + if ( ! method_exists($class, $method)) { |
|
272 | + throw new \RuntimeException(sprintf(lang('themer.bad_callback'), $class, $method)); |
|
274 | 273 | } |
275 | 274 | |
276 | 275 | // Call the class with our parameters |
277 | 276 | $output = $class->{$method}($params); |
278 | 277 | |
279 | 278 | // Cache it |
280 | - if ((int)$cache_time > 0) |
|
279 | + if ((int) $cache_time > 0) |
|
281 | 280 | { |
282 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
281 | + $this->ci->cache->save($cache_name, $output, (int) $cache_time * 60); |
|
283 | 282 | } |
284 | 283 | } |
285 | 284 | |
@@ -479,7 +478,7 @@ discard block |
||
479 | 478 | { |
480 | 479 | $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
481 | 480 | |
482 | - if (! isset($this->folders[ $theme ])) |
|
481 | + if ( ! isset($this->folders[$theme])) |
|
483 | 482 | { |
484 | 483 | return null; |
485 | 484 | } |
@@ -569,24 +568,24 @@ discard block |
||
569 | 568 | // First - does it exist in the current theme? |
570 | 569 | $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
571 | 570 | $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
572 | - $theme = rtrim($theme, '/ ') .'/'; |
|
571 | + $theme = rtrim($theme, '/ ').'/'; |
|
573 | 572 | |
574 | - if (file_exists($theme ."{$view}.php")) |
|
573 | + if (file_exists($theme."{$view}.php")) |
|
575 | 574 | { |
576 | - $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
575 | + $output = $this->ci->load->view_path($theme.$view, $data, TRUE); |
|
577 | 576 | } |
578 | 577 | |
579 | 578 | // Next, if it's a real file with path, then load it |
580 | - elseif ( realpath( $view . '.php' ) ) |
|
579 | + elseif (realpath($view.'.php')) |
|
581 | 580 | { |
582 | - $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
581 | + $output = $this->ci->load->view_path($view, $data, TRUE); |
|
583 | 582 | } |
584 | 583 | |
585 | 584 | // Otherwise, treat it as a standard view, which means |
586 | 585 | // application/views will override any modules. (See HMVC/Loader) |
587 | 586 | else |
588 | 587 | { |
589 | - $output = $this->ci->load->view( $view, $data, TRUE ); |
|
588 | + $output = $this->ci->load->view($view, $data, TRUE); |
|
590 | 589 | } |
591 | 590 | |
592 | 591 | return $output; |
@@ -361,7 +361,9 @@ |
||
361 | 361 | */ |
362 | 362 | public function setLayout($file) |
363 | 363 | { |
364 | - if (empty($file)) return; |
|
364 | + if (empty($file)) { |
|
365 | + return; |
|
366 | + } |
|
365 | 367 | |
366 | 368 | $this->layout = $file; |
367 | 369 | } |
@@ -91,7 +91,6 @@ discard block |
||
91 | 91 | * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
92 | 92 | * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
93 | 93 | * |
94 | - * @param array $attributes |
|
95 | 94 | * @return mixed |
96 | 95 | */ |
97 | 96 | abstract public function column($options=[], \Closure $c); |
@@ -107,7 +106,7 @@ discard block |
||
107 | 106 | * top of a page. |
108 | 107 | * |
109 | 108 | * @param array $options |
110 | - * @param callable $c |
|
109 | + * @param \Closure $c |
|
111 | 110 | * @return string |
112 | 111 | */ |
113 | 112 | abstract public function navbar($options=[], \Closure $c); |
@@ -133,7 +132,7 @@ discard block |
||
133 | 132 | * 'class' - An additional class to add |
134 | 133 | * |
135 | 134 | * @param array $options |
136 | - * @param callable $c |
|
135 | + * @param \Closure $c |
|
137 | 136 | * @return string |
138 | 137 | */ |
139 | 138 | abstract public function navbarRight($options=[], \Closure $c); |
@@ -157,7 +156,7 @@ discard block |
||
157 | 156 | * |
158 | 157 | * @param $title |
159 | 158 | * @param array $options |
160 | - * @param callable $c |
|
159 | + * @param \Closure $c |
|
161 | 160 | */ |
162 | 161 | abstract public function navDropdown($title,$options=[], \Closure $c); |
163 | 162 | |
@@ -176,7 +175,7 @@ discard block |
||
176 | 175 | * Creates a list of nav items to function as breadcrumbs for a site. |
177 | 176 | * |
178 | 177 | * @param array $options |
179 | - * @param callable $c |
|
178 | + * @param \Closure $c |
|
180 | 179 | * @return mixed |
181 | 180 | */ |
182 | 181 | abstract public function breadcrumb($options=[], \Closure $c); |
@@ -218,7 +217,7 @@ discard block |
||
218 | 217 | * Creates button groups wrapping HTML. |
219 | 218 | * |
220 | 219 | * @param $options |
221 | - * @param callable $c |
|
220 | + * @param \Closure $c |
|
222 | 221 | * @return mixed |
223 | 222 | */ |
224 | 223 | abstract public function buttonGroup($options, \Closure $c); |
@@ -227,7 +226,7 @@ discard block |
||
227 | 226 | * Creates the button bar wrapping HTML. |
228 | 227 | * |
229 | 228 | * @param $options |
230 | - * @param callable $c |
|
229 | + * @param \Closure $c |
|
231 | 230 | * @return mixed |
232 | 231 | */ |
233 | 232 | abstract public function buttonBar($options, \Closure $c); |
@@ -240,7 +239,7 @@ discard block |
||
240 | 239 | * @param string $style |
241 | 240 | * @param string $size |
242 | 241 | * @param array $options |
243 | - * @param callable $c |
|
242 | + * @param \Closure $c |
|
244 | 243 | * @return mixed |
245 | 244 | */ |
246 | 245 | abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
@@ -272,7 +271,7 @@ discard block |
||
272 | 271 | * |
273 | 272 | * @param $label_text |
274 | 273 | * @param array $options |
275 | - * @param callable $c |
|
274 | + * @param \Closure $c |
|
276 | 275 | * |
277 | 276 | * @return mixed |
278 | 277 | */ |
@@ -285,7 +284,7 @@ discard block |
||
285 | 284 | /** |
286 | 285 | * Helper method to run a Closure and collect the output of it. |
287 | 286 | * |
288 | - * @param callable $c |
|
287 | + * @param \Closure $c |
|
289 | 288 | * @return string |
290 | 289 | */ |
291 | 290 | protected function runClosure(\Closure $c) |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param array $options |
74 | 74 | * @return mixed |
75 | 75 | */ |
76 | - abstract public function row($options=[], \Closure $c); |
|
76 | + abstract public function row($options = [], \Closure $c); |
|
77 | 77 | |
78 | 78 | //-------------------------------------------------------------------- |
79 | 79 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param array $attributes |
95 | 95 | * @return mixed |
96 | 96 | */ |
97 | - abstract public function column($options=[], \Closure $c); |
|
97 | + abstract public function column($options = [], \Closure $c); |
|
98 | 98 | |
99 | 99 | //-------------------------------------------------------------------- |
100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param callable $c |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - abstract public function navbar($options=[], \Closure $c); |
|
113 | + abstract public function navbar($options = [], \Closure $c); |
|
114 | 114 | |
115 | 115 | //-------------------------------------------------------------------- |
116 | 116 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @param string $url |
123 | 123 | * @return string |
124 | 124 | */ |
125 | - abstract public function navbarTitle($title, $url='#'); |
|
125 | + abstract public function navbarTitle($title, $url = '#'); |
|
126 | 126 | |
127 | 127 | //-------------------------------------------------------------------- |
128 | 128 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @param callable $c |
137 | 137 | * @return string |
138 | 138 | */ |
139 | - abstract public function navbarRight($options=[], \Closure $c); |
|
139 | + abstract public function navbarRight($options = [], \Closure $c); |
|
140 | 140 | |
141 | 141 | //-------------------------------------------------------------------- |
142 | 142 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param array $options |
149 | 149 | * @return string |
150 | 150 | */ |
151 | - abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
151 | + abstract public function navItem($title, $url, $options = [], $isActive = false); |
|
152 | 152 | |
153 | 153 | //-------------------------------------------------------------------- |
154 | 154 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param array $options |
160 | 160 | * @param callable $c |
161 | 161 | */ |
162 | - abstract public function navDropdown($title,$options=[], \Closure $c); |
|
162 | + abstract public function navDropdown($title, $options = [], \Closure $c); |
|
163 | 163 | |
164 | 164 | //-------------------------------------------------------------------- |
165 | 165 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param callable $c |
180 | 180 | * @return mixed |
181 | 181 | */ |
182 | - abstract public function breadcrumb($options=[], \Closure $c); |
|
182 | + abstract public function breadcrumb($options = [], \Closure $c); |
|
183 | 183 | |
184 | 184 | //-------------------------------------------------------------------- |
185 | 185 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @param array $options |
199 | 199 | * @return mixed |
200 | 200 | */ |
201 | - abstract public function button($title, $style='default', $size='default', $options=[]); |
|
201 | + abstract public function button($title, $style = 'default', $size = 'default', $options = []); |
|
202 | 202 | |
203 | 203 | /** |
204 | 204 | * Creates a simple link styled as a button. |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @param array $options |
213 | 213 | * @return mixed |
214 | 214 | */ |
215 | - abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
215 | + abstract public function buttonLink($title, $url = '#', $style = 'default', $size = 'default', $options = []); |
|
216 | 216 | |
217 | 217 | /** |
218 | 218 | * Creates button groups wrapping HTML. |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @param callable $c |
244 | 244 | * @return mixed |
245 | 245 | */ |
246 | - abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
246 | + abstract public function buttonDropdown($title, $style = 'default', $size = 'default', $options = [], \Closure $c); |
|
247 | 247 | |
248 | 248 | //-------------------------------------------------------------------- |
249 | 249 | // Notices |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @param bool $closable |
260 | 260 | * @return mixed |
261 | 261 | */ |
262 | - abstract public function notice($content, $style='success', $closable=true); |
|
262 | + abstract public function notice($content, $style = 'success', $closable = true); |
|
263 | 263 | |
264 | 264 | //-------------------------------------------------------------------- |
265 | 265 | // Forms |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return mixed |
278 | 278 | */ |
279 | - abstract public function inputWrap($label_text, $options=[], \Closure $c); |
|
279 | + abstract public function inputWrap($label_text, $options = [], \Closure $c); |
|
280 | 280 | |
281 | 281 | //-------------------------------------------------------------------- |
282 | 282 | // Utility Methods |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | */ |
291 | 291 | protected function runClosure(\Closure $c) |
292 | 292 | { |
293 | - if (! is_callable($c)) return ''; |
|
293 | + if ( ! is_callable($c)) return ''; |
|
294 | 294 | |
295 | 295 | ob_start(); |
296 | 296 | $c(); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param bool $fullClassString |
312 | 312 | * @return array |
313 | 313 | */ |
314 | - protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
314 | + protected function parseStandardOptions($options, $initial_classes = '', $fullClassString = false) |
|
315 | 315 | { |
316 | 316 | return [ |
317 | 317 | $this->buildClassString($initial_classes, $options, $fullClassString), |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * @param array $options |
349 | 349 | * @return array |
350 | 350 | */ |
351 | - protected function buildClassString($initial, $options, $buildEntireString=false) |
|
351 | + protected function buildClassString($initial, $options, $buildEntireString = false) |
|
352 | 352 | { |
353 | 353 | $classes = explode(' ', $initial); |
354 | 354 | |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | { |
405 | 405 | if (isset($options['attributes']) && ! is_array($options['attributes'])) |
406 | 406 | { |
407 | - $options['attributes'] = [ $options['attributes'] ]; |
|
407 | + $options['attributes'] = [$options['attributes']]; |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | return isset($options['attributes']) ? implode($options['attributes']) : ''; |
@@ -290,7 +290,9 @@ |
||
290 | 290 | */ |
291 | 291 | protected function runClosure(\Closure $c) |
292 | 292 | { |
293 | - if (! is_callable($c)) return ''; |
|
293 | + if (! is_callable($c)) { |
|
294 | + return ''; |
|
295 | + } |
|
294 | 296 | |
295 | 297 | ob_start(); |
296 | 298 | $c(); |
@@ -38,228 +38,228 @@ discard block |
||
38 | 38 | */ |
39 | 39 | abstract class BaseUIKit { |
40 | 40 | |
41 | - /** |
|
42 | - * Bucket for methods to control their current state between method calls. |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $states = []; |
|
46 | - |
|
47 | - protected $name = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * Attached to nav items that are considered active. |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $active_class = 'active'; |
|
54 | - |
|
55 | - //-------------------------------------------------------------------- |
|
56 | - |
|
57 | - public function name() |
|
58 | - { |
|
59 | - return $this->name; |
|
60 | - } |
|
61 | - |
|
62 | - //-------------------------------------------------------------------- |
|
63 | - |
|
64 | - //-------------------------------------------------------------------- |
|
65 | - // Grids |
|
66 | - //-------------------------------------------------------------------- |
|
67 | - |
|
68 | - /** |
|
69 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
70 | - * the class for it, but some frameworks use a completely different |
|
71 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
72 | - * |
|
73 | - * @param array $options |
|
74 | - * @return mixed |
|
75 | - */ |
|
76 | - abstract public function row($options=[], \Closure $c); |
|
77 | - |
|
78 | - //-------------------------------------------------------------------- |
|
79 | - |
|
80 | - /** |
|
81 | - * Creates the CSS for a column in a grid. |
|
82 | - * |
|
83 | - * The attribute array is made up of key/value pairs with the |
|
84 | - * key being the size, and the value being the number of columns/offset |
|
85 | - * in a 12-column grid. |
|
86 | - * |
|
87 | - * Note that we currently DO NOT support offset columns. |
|
88 | - * |
|
89 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
90 | - * |
|
91 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
92 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
93 | - * |
|
94 | - * @param array $attributes |
|
95 | - * @return mixed |
|
96 | - */ |
|
97 | - abstract public function column($options=[], \Closure $c); |
|
98 | - |
|
99 | - //-------------------------------------------------------------------- |
|
100 | - |
|
101 | - //-------------------------------------------------------------------- |
|
102 | - // Navigation |
|
103 | - //-------------------------------------------------------------------- |
|
104 | - |
|
105 | - /** |
|
106 | - * Generates the container code for a navbar, typically used along the |
|
107 | - * top of a page. |
|
108 | - * |
|
109 | - * @param array $options |
|
110 | - * @param callable $c |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - abstract public function navbar($options=[], \Closure $c); |
|
114 | - |
|
115 | - //-------------------------------------------------------------------- |
|
116 | - |
|
117 | - /** |
|
118 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
119 | - * includes the code for the hamburger menu on small resolutions. |
|
120 | - * |
|
121 | - * @param $title |
|
122 | - * @param string $url |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - abstract public function navbarTitle($title, $url='#'); |
|
126 | - |
|
127 | - //-------------------------------------------------------------------- |
|
128 | - |
|
129 | - /** |
|
130 | - * Creates a UL meant to pull to the right within the navbar. |
|
131 | - * |
|
132 | - * Available options: |
|
133 | - * 'class' - An additional class to add |
|
134 | - * |
|
135 | - * @param array $options |
|
136 | - * @param callable $c |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - abstract public function navbarRight($options=[], \Closure $c); |
|
140 | - |
|
141 | - //-------------------------------------------------------------------- |
|
142 | - |
|
143 | - /** |
|
144 | - * Creates a single list item for use within a nav section. |
|
145 | - * |
|
146 | - * @param $title |
|
147 | - * @param $url |
|
148 | - * @param array $options |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
152 | - |
|
153 | - //-------------------------------------------------------------------- |
|
154 | - |
|
155 | - /** |
|
156 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
157 | - * |
|
158 | - * @param $title |
|
159 | - * @param array $options |
|
160 | - * @param callable $c |
|
161 | - */ |
|
162 | - abstract public function navDropdown($title,$options=[], \Closure $c); |
|
163 | - |
|
164 | - //-------------------------------------------------------------------- |
|
165 | - |
|
166 | - /** |
|
167 | - * Creates a divider for use within a nav list. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - abstract public function navDivider(); |
|
172 | - |
|
173 | - //-------------------------------------------------------------------- |
|
174 | - |
|
175 | - /** |
|
176 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
177 | - * |
|
178 | - * @param array $options |
|
179 | - * @param callable $c |
|
180 | - * @return mixed |
|
181 | - */ |
|
182 | - abstract public function breadcrumb($options=[], \Closure $c); |
|
183 | - |
|
184 | - //-------------------------------------------------------------------- |
|
185 | - |
|
186 | - //-------------------------------------------------------------------- |
|
187 | - // Buttons |
|
188 | - //-------------------------------------------------------------------- |
|
189 | - |
|
190 | - /** |
|
191 | - * Creates a simple button. |
|
192 | - * |
|
193 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
194 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
195 | - * |
|
196 | - * @param $title |
|
197 | - * @param string $style |
|
198 | - * @param array $options |
|
199 | - * @return mixed |
|
200 | - */ |
|
201 | - abstract public function button($title, $style='default', $size='default', $options=[]); |
|
202 | - |
|
203 | - /** |
|
204 | - * Creates a simple link styled as a button. |
|
205 | - * |
|
206 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
207 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
208 | - * |
|
209 | - * @param $title |
|
210 | - * @param string $url |
|
211 | - * @param string $style |
|
212 | - * @param array $options |
|
213 | - * @return mixed |
|
214 | - */ |
|
215 | - abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
216 | - |
|
217 | - /** |
|
218 | - * Creates button groups wrapping HTML. |
|
219 | - * |
|
220 | - * @param $options |
|
221 | - * @param callable $c |
|
222 | - * @return mixed |
|
223 | - */ |
|
224 | - abstract public function buttonGroup($options, \Closure $c); |
|
225 | - |
|
226 | - /** |
|
227 | - * Creates the button bar wrapping HTML. |
|
228 | - * |
|
229 | - * @param $options |
|
230 | - * @param callable $c |
|
231 | - * @return mixed |
|
232 | - */ |
|
233 | - abstract public function buttonBar($options, \Closure $c); |
|
234 | - |
|
235 | - /** |
|
236 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
237 | - * by some frameworks. |
|
238 | - * |
|
239 | - * @param $title |
|
240 | - * @param string $style |
|
241 | - * @param string $size |
|
242 | - * @param array $options |
|
243 | - * @param callable $c |
|
244 | - * @return mixed |
|
245 | - */ |
|
246 | - abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
247 | - |
|
248 | - //-------------------------------------------------------------------- |
|
249 | - // Notices |
|
250 | - //-------------------------------------------------------------------- |
|
251 | - |
|
252 | - /** |
|
253 | - * Creates an 'alert-box' style of notice grid. |
|
254 | - * |
|
255 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
256 | - * |
|
257 | - * @param $content |
|
258 | - * @param string $style |
|
259 | - * @param bool $closable |
|
260 | - * @return mixed |
|
261 | - */ |
|
262 | - abstract public function notice($content, $style='success', $closable=true); |
|
41 | + /** |
|
42 | + * Bucket for methods to control their current state between method calls. |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $states = []; |
|
46 | + |
|
47 | + protected $name = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * Attached to nav items that are considered active. |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $active_class = 'active'; |
|
54 | + |
|
55 | + //-------------------------------------------------------------------- |
|
56 | + |
|
57 | + public function name() |
|
58 | + { |
|
59 | + return $this->name; |
|
60 | + } |
|
61 | + |
|
62 | + //-------------------------------------------------------------------- |
|
63 | + |
|
64 | + //-------------------------------------------------------------------- |
|
65 | + // Grids |
|
66 | + //-------------------------------------------------------------------- |
|
67 | + |
|
68 | + /** |
|
69 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
70 | + * the class for it, but some frameworks use a completely different |
|
71 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
72 | + * |
|
73 | + * @param array $options |
|
74 | + * @return mixed |
|
75 | + */ |
|
76 | + abstract public function row($options=[], \Closure $c); |
|
77 | + |
|
78 | + //-------------------------------------------------------------------- |
|
79 | + |
|
80 | + /** |
|
81 | + * Creates the CSS for a column in a grid. |
|
82 | + * |
|
83 | + * The attribute array is made up of key/value pairs with the |
|
84 | + * key being the size, and the value being the number of columns/offset |
|
85 | + * in a 12-column grid. |
|
86 | + * |
|
87 | + * Note that we currently DO NOT support offset columns. |
|
88 | + * |
|
89 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
90 | + * |
|
91 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
92 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
93 | + * |
|
94 | + * @param array $attributes |
|
95 | + * @return mixed |
|
96 | + */ |
|
97 | + abstract public function column($options=[], \Closure $c); |
|
98 | + |
|
99 | + //-------------------------------------------------------------------- |
|
100 | + |
|
101 | + //-------------------------------------------------------------------- |
|
102 | + // Navigation |
|
103 | + //-------------------------------------------------------------------- |
|
104 | + |
|
105 | + /** |
|
106 | + * Generates the container code for a navbar, typically used along the |
|
107 | + * top of a page. |
|
108 | + * |
|
109 | + * @param array $options |
|
110 | + * @param callable $c |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + abstract public function navbar($options=[], \Closure $c); |
|
114 | + |
|
115 | + //-------------------------------------------------------------------- |
|
116 | + |
|
117 | + /** |
|
118 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
119 | + * includes the code for the hamburger menu on small resolutions. |
|
120 | + * |
|
121 | + * @param $title |
|
122 | + * @param string $url |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + abstract public function navbarTitle($title, $url='#'); |
|
126 | + |
|
127 | + //-------------------------------------------------------------------- |
|
128 | + |
|
129 | + /** |
|
130 | + * Creates a UL meant to pull to the right within the navbar. |
|
131 | + * |
|
132 | + * Available options: |
|
133 | + * 'class' - An additional class to add |
|
134 | + * |
|
135 | + * @param array $options |
|
136 | + * @param callable $c |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + abstract public function navbarRight($options=[], \Closure $c); |
|
140 | + |
|
141 | + //-------------------------------------------------------------------- |
|
142 | + |
|
143 | + /** |
|
144 | + * Creates a single list item for use within a nav section. |
|
145 | + * |
|
146 | + * @param $title |
|
147 | + * @param $url |
|
148 | + * @param array $options |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
152 | + |
|
153 | + //-------------------------------------------------------------------- |
|
154 | + |
|
155 | + /** |
|
156 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
157 | + * |
|
158 | + * @param $title |
|
159 | + * @param array $options |
|
160 | + * @param callable $c |
|
161 | + */ |
|
162 | + abstract public function navDropdown($title,$options=[], \Closure $c); |
|
163 | + |
|
164 | + //-------------------------------------------------------------------- |
|
165 | + |
|
166 | + /** |
|
167 | + * Creates a divider for use within a nav list. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + abstract public function navDivider(); |
|
172 | + |
|
173 | + //-------------------------------------------------------------------- |
|
174 | + |
|
175 | + /** |
|
176 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
177 | + * |
|
178 | + * @param array $options |
|
179 | + * @param callable $c |
|
180 | + * @return mixed |
|
181 | + */ |
|
182 | + abstract public function breadcrumb($options=[], \Closure $c); |
|
183 | + |
|
184 | + //-------------------------------------------------------------------- |
|
185 | + |
|
186 | + //-------------------------------------------------------------------- |
|
187 | + // Buttons |
|
188 | + //-------------------------------------------------------------------- |
|
189 | + |
|
190 | + /** |
|
191 | + * Creates a simple button. |
|
192 | + * |
|
193 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
194 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
195 | + * |
|
196 | + * @param $title |
|
197 | + * @param string $style |
|
198 | + * @param array $options |
|
199 | + * @return mixed |
|
200 | + */ |
|
201 | + abstract public function button($title, $style='default', $size='default', $options=[]); |
|
202 | + |
|
203 | + /** |
|
204 | + * Creates a simple link styled as a button. |
|
205 | + * |
|
206 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
207 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
208 | + * |
|
209 | + * @param $title |
|
210 | + * @param string $url |
|
211 | + * @param string $style |
|
212 | + * @param array $options |
|
213 | + * @return mixed |
|
214 | + */ |
|
215 | + abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
216 | + |
|
217 | + /** |
|
218 | + * Creates button groups wrapping HTML. |
|
219 | + * |
|
220 | + * @param $options |
|
221 | + * @param callable $c |
|
222 | + * @return mixed |
|
223 | + */ |
|
224 | + abstract public function buttonGroup($options, \Closure $c); |
|
225 | + |
|
226 | + /** |
|
227 | + * Creates the button bar wrapping HTML. |
|
228 | + * |
|
229 | + * @param $options |
|
230 | + * @param callable $c |
|
231 | + * @return mixed |
|
232 | + */ |
|
233 | + abstract public function buttonBar($options, \Closure $c); |
|
234 | + |
|
235 | + /** |
|
236 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
237 | + * by some frameworks. |
|
238 | + * |
|
239 | + * @param $title |
|
240 | + * @param string $style |
|
241 | + * @param string $size |
|
242 | + * @param array $options |
|
243 | + * @param callable $c |
|
244 | + * @return mixed |
|
245 | + */ |
|
246 | + abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
247 | + |
|
248 | + //-------------------------------------------------------------------- |
|
249 | + // Notices |
|
250 | + //-------------------------------------------------------------------- |
|
251 | + |
|
252 | + /** |
|
253 | + * Creates an 'alert-box' style of notice grid. |
|
254 | + * |
|
255 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
256 | + * |
|
257 | + * @param $content |
|
258 | + * @param string $style |
|
259 | + * @param bool $closable |
|
260 | + * @return mixed |
|
261 | + */ |
|
262 | + abstract public function notice($content, $style='success', $closable=true); |
|
263 | 263 | |
264 | 264 | //-------------------------------------------------------------------- |
265 | 265 | // Forms |
@@ -278,137 +278,137 @@ discard block |
||
278 | 278 | */ |
279 | 279 | abstract public function inputWrap($label_text, $options=[], \Closure $c); |
280 | 280 | |
281 | - //-------------------------------------------------------------------- |
|
282 | - // Utility Methods |
|
283 | - //-------------------------------------------------------------------- |
|
284 | - |
|
285 | - /** |
|
286 | - * Helper method to run a Closure and collect the output of it. |
|
287 | - * |
|
288 | - * @param callable $c |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - protected function runClosure(\Closure $c) |
|
292 | - { |
|
293 | - if (! is_callable($c)) return ''; |
|
294 | - |
|
295 | - ob_start(); |
|
296 | - $c(); |
|
297 | - $output = ob_get_contents(); |
|
298 | - ob_end_clean(); |
|
299 | - |
|
300 | - return $output; |
|
301 | - } |
|
302 | - |
|
303 | - //-------------------------------------------------------------------- |
|
304 | - |
|
305 | - /** |
|
306 | - * Provides a single method call to get the $classes, $id, and $attributes |
|
307 | - * from the options array. |
|
308 | - * |
|
309 | - * @param $options |
|
310 | - * @param string $initial_classes |
|
311 | - * @param bool $fullClassString |
|
312 | - * @return array |
|
313 | - */ |
|
314 | - protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
315 | - { |
|
316 | - return [ |
|
317 | - $this->buildClassString($initial_classes, $options, $fullClassString), |
|
318 | - $this->buildIdFromOptions($options), |
|
319 | - $this->buildAttributesFromOptions($options) |
|
320 | - ]; |
|
321 | - } |
|
322 | - |
|
323 | - //-------------------------------------------------------------------- |
|
324 | - |
|
325 | - /** |
|
326 | - * Sets the element that is to be considered the active item. This is |
|
327 | - * based on the navItem's $title so it must match, though it is NOT |
|
328 | - * case sensitive. |
|
329 | - * |
|
330 | - * @param $title |
|
331 | - * @return mixed |
|
332 | - */ |
|
333 | - public function setActiveNavItem($title) |
|
334 | - { |
|
335 | - $this->states['activeNavItem'] = strtolower($title); |
|
336 | - } |
|
337 | - |
|
338 | - //-------------------------------------------------------------------- |
|
339 | - |
|
340 | - /** |
|
341 | - * Combines an initial classes string with a 'class' item that |
|
342 | - * might be available within the options array. |
|
343 | - * |
|
344 | - * If 'buildEntireString' is TRUE will return the string with the 'class=""' portion. |
|
345 | - * Otherwise, just returns the raw classes. |
|
346 | - * |
|
347 | - * @param string $initial |
|
348 | - * @param array $options |
|
349 | - * @return array |
|
350 | - */ |
|
351 | - protected function buildClassString($initial, $options, $buildEntireString=false) |
|
352 | - { |
|
353 | - $classes = explode(' ', $initial); |
|
354 | - |
|
355 | - if (isset($options['class'])) |
|
356 | - { |
|
357 | - $classes = array_merge($classes, explode(' ', $options['class'])); |
|
358 | - } |
|
359 | - |
|
360 | - if (isset($this->states['activeNavItem']) && isset($this->states['activeNavTitle']) && |
|
361 | - $this->states['activeNavItem'] == strtolower($this->states['activeNavTitle'])) |
|
362 | - { |
|
363 | - $classes[] = $this->active_class; |
|
364 | - } |
|
365 | - |
|
366 | - $classes = implode(' ', $classes); |
|
367 | - |
|
368 | - // Substitute the active class for a placeholder. |
|
369 | - $classes = str_replace('{active}', $this->active_class, $classes); |
|
370 | - |
|
371 | - return $buildEntireString ? "class='{$classes}'" : $classes; |
|
372 | - } |
|
373 | - //-------------------------------------------------------------------- |
|
374 | - |
|
375 | - /** |
|
376 | - * Checks the options array for an ID and returns the entire string. |
|
377 | - * |
|
378 | - * Example Return: |
|
379 | - * id='MyID' |
|
380 | - * |
|
381 | - * @param $options |
|
382 | - * @return string |
|
383 | - */ |
|
384 | - protected function buildIdFromOptions($options) |
|
385 | - { |
|
386 | - return isset($options['id']) ? "id='{$options['id']}'" : ' '; |
|
387 | - } |
|
388 | - |
|
389 | - //-------------------------------------------------------------------- |
|
390 | - |
|
391 | - /** |
|
392 | - * Parses out attributes from the options array. The attributes array |
|
393 | - * should all contain no key names, only values, so: |
|
394 | - * |
|
395 | - * 'attributes' => [ |
|
396 | - * 'style="width:100%", |
|
397 | - * 'required' |
|
398 | - * ] |
|
399 | - * |
|
400 | - * @param $options |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - protected function buildAttributesFromOptions($options) |
|
404 | - { |
|
405 | - if (isset($options['attributes']) && ! is_array($options['attributes'])) |
|
406 | - { |
|
407 | - $options['attributes'] = [ $options['attributes'] ]; |
|
408 | - } |
|
409 | - |
|
410 | - return isset($options['attributes']) ? implode($options['attributes']) : ''; |
|
411 | - } |
|
412 | - |
|
413 | - //-------------------------------------------------------------------- |
|
281 | + //-------------------------------------------------------------------- |
|
282 | + // Utility Methods |
|
283 | + //-------------------------------------------------------------------- |
|
284 | + |
|
285 | + /** |
|
286 | + * Helper method to run a Closure and collect the output of it. |
|
287 | + * |
|
288 | + * @param callable $c |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + protected function runClosure(\Closure $c) |
|
292 | + { |
|
293 | + if (! is_callable($c)) return ''; |
|
294 | + |
|
295 | + ob_start(); |
|
296 | + $c(); |
|
297 | + $output = ob_get_contents(); |
|
298 | + ob_end_clean(); |
|
299 | + |
|
300 | + return $output; |
|
301 | + } |
|
302 | + |
|
303 | + //-------------------------------------------------------------------- |
|
304 | + |
|
305 | + /** |
|
306 | + * Provides a single method call to get the $classes, $id, and $attributes |
|
307 | + * from the options array. |
|
308 | + * |
|
309 | + * @param $options |
|
310 | + * @param string $initial_classes |
|
311 | + * @param bool $fullClassString |
|
312 | + * @return array |
|
313 | + */ |
|
314 | + protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
315 | + { |
|
316 | + return [ |
|
317 | + $this->buildClassString($initial_classes, $options, $fullClassString), |
|
318 | + $this->buildIdFromOptions($options), |
|
319 | + $this->buildAttributesFromOptions($options) |
|
320 | + ]; |
|
321 | + } |
|
322 | + |
|
323 | + //-------------------------------------------------------------------- |
|
324 | + |
|
325 | + /** |
|
326 | + * Sets the element that is to be considered the active item. This is |
|
327 | + * based on the navItem's $title so it must match, though it is NOT |
|
328 | + * case sensitive. |
|
329 | + * |
|
330 | + * @param $title |
|
331 | + * @return mixed |
|
332 | + */ |
|
333 | + public function setActiveNavItem($title) |
|
334 | + { |
|
335 | + $this->states['activeNavItem'] = strtolower($title); |
|
336 | + } |
|
337 | + |
|
338 | + //-------------------------------------------------------------------- |
|
339 | + |
|
340 | + /** |
|
341 | + * Combines an initial classes string with a 'class' item that |
|
342 | + * might be available within the options array. |
|
343 | + * |
|
344 | + * If 'buildEntireString' is TRUE will return the string with the 'class=""' portion. |
|
345 | + * Otherwise, just returns the raw classes. |
|
346 | + * |
|
347 | + * @param string $initial |
|
348 | + * @param array $options |
|
349 | + * @return array |
|
350 | + */ |
|
351 | + protected function buildClassString($initial, $options, $buildEntireString=false) |
|
352 | + { |
|
353 | + $classes = explode(' ', $initial); |
|
354 | + |
|
355 | + if (isset($options['class'])) |
|
356 | + { |
|
357 | + $classes = array_merge($classes, explode(' ', $options['class'])); |
|
358 | + } |
|
359 | + |
|
360 | + if (isset($this->states['activeNavItem']) && isset($this->states['activeNavTitle']) && |
|
361 | + $this->states['activeNavItem'] == strtolower($this->states['activeNavTitle'])) |
|
362 | + { |
|
363 | + $classes[] = $this->active_class; |
|
364 | + } |
|
365 | + |
|
366 | + $classes = implode(' ', $classes); |
|
367 | + |
|
368 | + // Substitute the active class for a placeholder. |
|
369 | + $classes = str_replace('{active}', $this->active_class, $classes); |
|
370 | + |
|
371 | + return $buildEntireString ? "class='{$classes}'" : $classes; |
|
372 | + } |
|
373 | + //-------------------------------------------------------------------- |
|
374 | + |
|
375 | + /** |
|
376 | + * Checks the options array for an ID and returns the entire string. |
|
377 | + * |
|
378 | + * Example Return: |
|
379 | + * id='MyID' |
|
380 | + * |
|
381 | + * @param $options |
|
382 | + * @return string |
|
383 | + */ |
|
384 | + protected function buildIdFromOptions($options) |
|
385 | + { |
|
386 | + return isset($options['id']) ? "id='{$options['id']}'" : ' '; |
|
387 | + } |
|
388 | + |
|
389 | + //-------------------------------------------------------------------- |
|
390 | + |
|
391 | + /** |
|
392 | + * Parses out attributes from the options array. The attributes array |
|
393 | + * should all contain no key names, only values, so: |
|
394 | + * |
|
395 | + * 'attributes' => [ |
|
396 | + * 'style="width:100%", |
|
397 | + * 'required' |
|
398 | + * ] |
|
399 | + * |
|
400 | + * @param $options |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + protected function buildAttributesFromOptions($options) |
|
404 | + { |
|
405 | + if (isset($options['attributes']) && ! is_array($options['attributes'])) |
|
406 | + { |
|
407 | + $options['attributes'] = [ $options['attributes'] ]; |
|
408 | + } |
|
409 | + |
|
410 | + return isset($options['attributes']) ? implode($options['attributes']) : ''; |
|
411 | + } |
|
412 | + |
|
413 | + //-------------------------------------------------------------------- |
|
414 | 414 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * approach to rows and columns than the reference Bootstrap and Foundation. |
50 | 50 | * |
51 | 51 | * @param array $options |
52 | - * @return mixed |
|
52 | + * @return string |
|
53 | 53 | */ |
54 | 54 | public function row($options=[], \Closure $c) |
55 | 55 | { |
@@ -80,8 +80,7 @@ discard block |
||
80 | 80 | * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
81 | 81 | * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
82 | 82 | * |
83 | - * @param array $attributes |
|
84 | - * @return mixed |
|
83 | + * @return string |
|
85 | 84 | */ |
86 | 85 | public function column($options=[], \Closure $c) |
87 | 86 | { |
@@ -141,7 +140,7 @@ discard block |
||
141 | 140 | * top of a page. |
142 | 141 | * |
143 | 142 | * @param array $options |
144 | - * @param callable $c |
|
143 | + * @param \Closure $c |
|
145 | 144 | * @return string |
146 | 145 | */ |
147 | 146 | public function navbar($options=[], \Closure $c) |
@@ -218,7 +217,7 @@ discard block |
||
218 | 217 | * 'class' - An additional class to add |
219 | 218 | * |
220 | 219 | * @param array $options |
221 | - * @param callable $c |
|
220 | + * @param \Closure $c |
|
222 | 221 | * @return string |
223 | 222 | */ |
224 | 223 | public function navbarRight($options=[], \Closure $c) |
@@ -270,7 +269,7 @@ discard block |
||
270 | 269 | * |
271 | 270 | * @param $title |
272 | 271 | * @param array $options |
273 | - * @param callable $c |
|
272 | + * @param \Closure $c |
|
274 | 273 | */ |
275 | 274 | public function navDropdown($title,$options=[], \Closure $c) |
276 | 275 | { |
@@ -320,8 +319,8 @@ discard block |
||
320 | 319 | * Creates a list of nav items to function as breadcrumbs for a site. |
321 | 320 | * |
322 | 321 | * @param array $options |
323 | - * @param callable $c |
|
324 | - * @return mixed |
|
322 | + * @param \Closure $c |
|
323 | + * @return string |
|
325 | 324 | */ |
326 | 325 | public function breadcrumb($options=[], \Closure $c) |
327 | 326 | { |
@@ -401,9 +400,10 @@ discard block |
||
401 | 400 | * Helper method to render out our buttons in a DRY manner. |
402 | 401 | * |
403 | 402 | * @param $title |
404 | - * @param $style |
|
405 | - * @param $size |
|
403 | + * @param string $style |
|
404 | + * @param string $size |
|
406 | 405 | * @param $tag |
406 | + * @return \Closure |
|
407 | 407 | */ |
408 | 408 | protected function renderButtonElement($title, $style, $size, $options, $tag) |
409 | 409 | { |
@@ -473,8 +473,8 @@ discard block |
||
473 | 473 | * Creates button groups wrapping HTML. |
474 | 474 | * |
475 | 475 | * @param $options |
476 | - * @param callable $c |
|
477 | - * @return mixed |
|
476 | + * @param \Closure $c |
|
477 | + * @return string |
|
478 | 478 | */ |
479 | 479 | public function buttonGroup($options, \Closure $c) |
480 | 480 | { |
@@ -495,8 +495,8 @@ discard block |
||
495 | 495 | * Creates the button bar wrapping HTML. |
496 | 496 | * |
497 | 497 | * @param $options |
498 | - * @param callable $c |
|
499 | - * @return mixed |
|
498 | + * @param \Closure $c |
|
499 | + * @return string |
|
500 | 500 | */ |
501 | 501 | public function buttonBar($options, \Closure $c) |
502 | 502 | { |
@@ -523,8 +523,8 @@ discard block |
||
523 | 523 | * @param string $style |
524 | 524 | * @param string $size |
525 | 525 | * @param array $options |
526 | - * @param callable $c |
|
527 | - * @return mixed |
|
526 | + * @param \Closure $c |
|
527 | + * @return string |
|
528 | 528 | */ |
529 | 529 | public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
530 | 530 | { |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | * @param $content |
557 | 557 | * @param string $style |
558 | 558 | * @param bool $closable |
559 | - * @return mixed |
|
559 | + * @return string |
|
560 | 560 | */ |
561 | 561 | public function notice($content, $style='success', $closable=true, $options=[]) |
562 | 562 | { |
@@ -609,9 +609,9 @@ discard block |
||
609 | 609 | * |
610 | 610 | * @param $label_text |
611 | 611 | * @param array $options |
612 | - * @param callable $c |
|
612 | + * @param \Closure $c |
|
613 | 613 | * |
614 | - * @return mixed |
|
614 | + * @return string |
|
615 | 615 | */ |
616 | 616 | public function inputWrap($label_text, $options=[], \Closure $c) |
617 | 617 | { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param array $options |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - public function row($options=[], \Closure $c) |
|
54 | + public function row($options = [], \Closure $c) |
|
55 | 55 | { |
56 | 56 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
57 | 57 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param array $attributes |
84 | 84 | * @return mixed |
85 | 85 | */ |
86 | - public function column($options=[], \Closure $c) |
|
86 | + public function column($options = [], \Closure $c) |
|
87 | 87 | { |
88 | 88 | // Build our classes |
89 | 89 | $classes = ''; |
@@ -93,28 +93,28 @@ discard block |
||
93 | 93 | switch ($size) |
94 | 94 | { |
95 | 95 | case 's': |
96 | - $classes .= ' col-xs-'. $value; |
|
96 | + $classes .= ' col-xs-'.$value; |
|
97 | 97 | break; |
98 | 98 | case 'm': |
99 | - $classes .= ' col-sm-'. $value; |
|
99 | + $classes .= ' col-sm-'.$value; |
|
100 | 100 | break; |
101 | 101 | case 'l': |
102 | - $classes .= ' col-md-'. $value; |
|
102 | + $classes .= ' col-md-'.$value; |
|
103 | 103 | break; |
104 | 104 | case 'xl': |
105 | - $classes .= ' col-lg-'. $value; |
|
105 | + $classes .= ' col-lg-'.$value; |
|
106 | 106 | break; |
107 | 107 | case 's-offset': |
108 | - $classes .= ' col-xs-offset-'. $value; |
|
108 | + $classes .= ' col-xs-offset-'.$value; |
|
109 | 109 | break; |
110 | 110 | case 'm-offset': |
111 | - $classes .= ' col-sm-offset-'. $value; |
|
111 | + $classes .= ' col-sm-offset-'.$value; |
|
112 | 112 | break; |
113 | 113 | case 'l-offset': |
114 | - $classes .= ' col-md-offset-'. $value; |
|
114 | + $classes .= ' col-md-offset-'.$value; |
|
115 | 115 | break; |
116 | 116 | case 'xl-offset': |
117 | - $classes .= ' col-lg-offset-'. $value; |
|
117 | + $classes .= ' col-lg-offset-'.$value; |
|
118 | 118 | break; |
119 | 119 | } |
120 | 120 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param callable $c |
145 | 145 | * @return string |
146 | 146 | */ |
147 | - public function navbar($options=[], \Closure $c) |
|
147 | + public function navbar($options = [], \Closure $c) |
|
148 | 148 | { |
149 | 149 | $output = ''; |
150 | 150 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param string $url |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function navbarTitle($title, $url='#') |
|
199 | + public function navbarTitle($title, $url = '#') |
|
200 | 200 | { |
201 | 201 | return '<div class="navbar-header"> |
202 | 202 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1"> |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | <span class="icon-bar"></span> |
206 | 206 | <span class="icon-bar"></span> |
207 | 207 | </button> |
208 | - <a class="navbar-brand" href="'. $url .'">'. $title .'</a> |
|
208 | + <a class="navbar-brand" href="'. $url.'">'.$title.'</a> |
|
209 | 209 | </div>'; |
210 | 210 | } |
211 | 211 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param callable $c |
222 | 222 | * @return string |
223 | 223 | */ |
224 | - public function navbarRight($options=[], \Closure $c) |
|
224 | + public function navbarRight($options = [], \Closure $c) |
|
225 | 225 | { |
226 | 226 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
227 | 227 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param array $options |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - public function navItem($title, $url='#', $options=[], $isActive=false) |
|
255 | + public function navItem($title, $url = '#', $options = [], $isActive = false) |
|
256 | 256 | { |
257 | 257 | $this->states['activeNavTitle'] = $title; |
258 | 258 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @param array $options |
273 | 273 | * @param callable $c |
274 | 274 | */ |
275 | - public function navDropdown($title,$options=[], \Closure $c) |
|
275 | + public function navDropdown($title, $options = [], \Closure $c) |
|
276 | 276 | { |
277 | 277 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
278 | 278 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | //-------------------------------------------------------------------- |
303 | 303 | |
304 | - public function sideNav($options=[], \Closure $c) |
|
304 | + public function sideNav($options = [], \Closure $c) |
|
305 | 305 | { |
306 | 306 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
307 | 307 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * @param callable $c |
324 | 324 | * @return mixed |
325 | 325 | */ |
326 | - public function breadcrumb($options=[], \Closure $c) |
|
326 | + public function breadcrumb($options = [], \Closure $c) |
|
327 | 327 | { |
328 | 328 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
329 | 329 | |
@@ -367,9 +367,9 @@ discard block |
||
367 | 367 | * @param array $options |
368 | 368 | * @return mixed |
369 | 369 | */ |
370 | - public function button($title, $style='default', $size='default', $options=[]) |
|
370 | + public function button($title, $style = 'default', $size = 'default', $options = []) |
|
371 | 371 | { |
372 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
372 | + $tag = "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
373 | 373 | |
374 | 374 | return $this->renderButtonElement($title, $style, $size, $options, $tag); |
375 | 375 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * @param array $options |
389 | 389 | * @return mixed |
390 | 390 | */ |
391 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
391 | + public function buttonLink($title, $url = '#', $style = 'default', $size = 'default', $options = []) |
|
392 | 392 | { |
393 | 393 | $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
394 | 394 | |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
411 | 411 | $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
412 | 412 | |
413 | - if (! in_array($style, $valid_styles)) |
|
413 | + if ( ! in_array($style, $valid_styles)) |
|
414 | 414 | { |
415 | 415 | $style = 'default'; |
416 | 416 | $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | $classes = 'btn '; |
420 | 420 | |
421 | 421 | // Sizes |
422 | - switch($size) |
|
422 | + switch ($size) |
|
423 | 423 | { |
424 | 424 | case 'small': |
425 | 425 | $classes .= 'btn-sm '; |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | * @param callable $c |
527 | 527 | * @return mixed |
528 | 528 | */ |
529 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
529 | + public function buttonDropdown($title, $style = 'default', $size = 'default', $options = [], \Closure $c) |
|
530 | 530 | { |
531 | 531 | $tag = "<button type='button' {classes} data-toggle='dropdown'> |
532 | 532 | {title} <span class='caret'></span> |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | * @param bool $closable |
559 | 559 | * @return mixed |
560 | 560 | */ |
561 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
561 | + public function notice($content, $style = 'success', $closable = true, $options = []) |
|
562 | 562 | { |
563 | 563 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
564 | 564 | |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @return mixed |
615 | 615 | */ |
616 | - public function inputWrap($label_text, $options=[], \Closure $c) |
|
616 | + public function inputWrap($label_text, $options = [], \Closure $c) |
|
617 | 617 | { |
618 | 618 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'form-group', true); |
619 | 619 |
@@ -37,168 +37,168 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class Bootstrap extends BaseUIKit { |
39 | 39 | |
40 | - protected $name = 'Bootstrap3UIKit'; |
|
41 | - |
|
42 | - //-------------------------------------------------------------------- |
|
43 | - // Grid |
|
44 | - //-------------------------------------------------------------------- |
|
45 | - |
|
46 | - /** |
|
47 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
48 | - * the class for it, but some frameworks use a completely different |
|
49 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
50 | - * |
|
51 | - * @param array $options |
|
52 | - * @return mixed |
|
53 | - */ |
|
54 | - public function row($options=[], \Closure $c) |
|
55 | - { |
|
56 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
57 | - |
|
58 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
59 | - |
|
60 | - $output .= $this->runClosure($c); |
|
61 | - |
|
62 | - $output .= "</div>\n"; |
|
63 | - |
|
64 | - return $output; |
|
65 | - } |
|
66 | - |
|
67 | - //-------------------------------------------------------------------- |
|
68 | - |
|
69 | - /** |
|
70 | - * Creates the CSS for a column in a grid. |
|
71 | - * |
|
72 | - * The attribute array is made up of key/value pairs with the |
|
73 | - * key being the size, and the value being the number of columns/offset |
|
74 | - * in a 12-column grid. |
|
75 | - * |
|
76 | - * Note that we currently DO NOT support offset columns. |
|
77 | - * |
|
78 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
79 | - * |
|
80 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
81 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
82 | - * |
|
83 | - * @param array $attributes |
|
84 | - * @return mixed |
|
85 | - */ |
|
86 | - public function column($options=[], \Closure $c) |
|
87 | - { |
|
88 | - // Build our classes |
|
89 | - $classes = ''; |
|
90 | - |
|
91 | - foreach ($options['sizes'] as $size => $value) |
|
92 | - { |
|
93 | - switch ($size) |
|
94 | - { |
|
95 | - case 's': |
|
96 | - $classes .= ' col-xs-'. $value; |
|
97 | - break; |
|
98 | - case 'm': |
|
99 | - $classes .= ' col-sm-'. $value; |
|
100 | - break; |
|
101 | - case 'l': |
|
102 | - $classes .= ' col-md-'. $value; |
|
103 | - break; |
|
104 | - case 'xl': |
|
105 | - $classes .= ' col-lg-'. $value; |
|
106 | - break; |
|
107 | - case 's-offset': |
|
108 | - $classes .= ' col-xs-offset-'. $value; |
|
109 | - break; |
|
110 | - case 'm-offset': |
|
111 | - $classes .= ' col-sm-offset-'. $value; |
|
112 | - break; |
|
113 | - case 'l-offset': |
|
114 | - $classes .= ' col-md-offset-'. $value; |
|
115 | - break; |
|
116 | - case 'xl-offset': |
|
117 | - $classes .= ' col-lg-offset-'. $value; |
|
118 | - break; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
123 | - |
|
124 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
125 | - |
|
126 | - $output .= $this->runClosure($c); |
|
127 | - |
|
128 | - $output .= "</div>\n"; |
|
129 | - |
|
130 | - return $output; |
|
131 | - } |
|
132 | - |
|
133 | - //-------------------------------------------------------------------- |
|
134 | - |
|
135 | - //-------------------------------------------------------------------- |
|
136 | - // Navigation |
|
137 | - //-------------------------------------------------------------------- |
|
138 | - |
|
139 | - /** |
|
140 | - * Generates the container code for a navbar, typically used along the |
|
141 | - * top of a page. |
|
142 | - * |
|
143 | - * @param array $options |
|
144 | - * @param callable $c |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - public function navbar($options=[], \Closure $c) |
|
148 | - { |
|
149 | - $output = ''; |
|
150 | - |
|
151 | - /* |
|
40 | + protected $name = 'Bootstrap3UIKit'; |
|
41 | + |
|
42 | + //-------------------------------------------------------------------- |
|
43 | + // Grid |
|
44 | + //-------------------------------------------------------------------- |
|
45 | + |
|
46 | + /** |
|
47 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
48 | + * the class for it, but some frameworks use a completely different |
|
49 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
50 | + * |
|
51 | + * @param array $options |
|
52 | + * @return mixed |
|
53 | + */ |
|
54 | + public function row($options=[], \Closure $c) |
|
55 | + { |
|
56 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
57 | + |
|
58 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
59 | + |
|
60 | + $output .= $this->runClosure($c); |
|
61 | + |
|
62 | + $output .= "</div>\n"; |
|
63 | + |
|
64 | + return $output; |
|
65 | + } |
|
66 | + |
|
67 | + //-------------------------------------------------------------------- |
|
68 | + |
|
69 | + /** |
|
70 | + * Creates the CSS for a column in a grid. |
|
71 | + * |
|
72 | + * The attribute array is made up of key/value pairs with the |
|
73 | + * key being the size, and the value being the number of columns/offset |
|
74 | + * in a 12-column grid. |
|
75 | + * |
|
76 | + * Note that we currently DO NOT support offset columns. |
|
77 | + * |
|
78 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
79 | + * |
|
80 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
81 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
82 | + * |
|
83 | + * @param array $attributes |
|
84 | + * @return mixed |
|
85 | + */ |
|
86 | + public function column($options=[], \Closure $c) |
|
87 | + { |
|
88 | + // Build our classes |
|
89 | + $classes = ''; |
|
90 | + |
|
91 | + foreach ($options['sizes'] as $size => $value) |
|
92 | + { |
|
93 | + switch ($size) |
|
94 | + { |
|
95 | + case 's': |
|
96 | + $classes .= ' col-xs-'. $value; |
|
97 | + break; |
|
98 | + case 'm': |
|
99 | + $classes .= ' col-sm-'. $value; |
|
100 | + break; |
|
101 | + case 'l': |
|
102 | + $classes .= ' col-md-'. $value; |
|
103 | + break; |
|
104 | + case 'xl': |
|
105 | + $classes .= ' col-lg-'. $value; |
|
106 | + break; |
|
107 | + case 's-offset': |
|
108 | + $classes .= ' col-xs-offset-'. $value; |
|
109 | + break; |
|
110 | + case 'm-offset': |
|
111 | + $classes .= ' col-sm-offset-'. $value; |
|
112 | + break; |
|
113 | + case 'l-offset': |
|
114 | + $classes .= ' col-md-offset-'. $value; |
|
115 | + break; |
|
116 | + case 'xl-offset': |
|
117 | + $classes .= ' col-lg-offset-'. $value; |
|
118 | + break; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
123 | + |
|
124 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
125 | + |
|
126 | + $output .= $this->runClosure($c); |
|
127 | + |
|
128 | + $output .= "</div>\n"; |
|
129 | + |
|
130 | + return $output; |
|
131 | + } |
|
132 | + |
|
133 | + //-------------------------------------------------------------------- |
|
134 | + |
|
135 | + //-------------------------------------------------------------------- |
|
136 | + // Navigation |
|
137 | + //-------------------------------------------------------------------- |
|
138 | + |
|
139 | + /** |
|
140 | + * Generates the container code for a navbar, typically used along the |
|
141 | + * top of a page. |
|
142 | + * |
|
143 | + * @param array $options |
|
144 | + * @param callable $c |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + public function navbar($options=[], \Closure $c) |
|
148 | + { |
|
149 | + $output = ''; |
|
150 | + |
|
151 | + /* |
|
152 | 152 | * Open the navbar |
153 | 153 | */ |
154 | - $classes = "navbar navbar-default "; |
|
155 | - |
|
156 | - foreach ($options as $option) |
|
157 | - { |
|
158 | - switch ($option) |
|
159 | - { |
|
160 | - case 'sticky-top': |
|
161 | - $classes .= " navbar-static-top"; |
|
162 | - break; |
|
163 | - case 'fixed': |
|
164 | - $classes .= " navbar-fixed-top"; |
|
165 | - break; |
|
166 | - case 'inverse': |
|
167 | - $classes .= " navbar-inverse"; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - list($class, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
172 | - |
|
173 | - $output .= "<nav {$class} {$id} {$attributes} role='navigation'> |
|
154 | + $classes = "navbar navbar-default "; |
|
155 | + |
|
156 | + foreach ($options as $option) |
|
157 | + { |
|
158 | + switch ($option) |
|
159 | + { |
|
160 | + case 'sticky-top': |
|
161 | + $classes .= " navbar-static-top"; |
|
162 | + break; |
|
163 | + case 'fixed': |
|
164 | + $classes .= " navbar-fixed-top"; |
|
165 | + break; |
|
166 | + case 'inverse': |
|
167 | + $classes .= " navbar-inverse"; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + list($class, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
172 | + |
|
173 | + $output .= "<nav {$class} {$id} {$attributes} role='navigation'> |
|
174 | 174 | <div class='container-fluid'>\n"; |
175 | 175 | |
176 | - /* |
|
176 | + /* |
|
177 | 177 | * Do any user content inside the bar |
178 | 178 | */ |
179 | - $output .= $this->runClosure($c); |
|
179 | + $output .= $this->runClosure($c); |
|
180 | 180 | |
181 | - /* |
|
181 | + /* |
|
182 | 182 | * Close out the navbar |
183 | 183 | */ |
184 | - $output .= "</div></nav>\n"; |
|
185 | - |
|
186 | - return $output; |
|
187 | - } |
|
188 | - |
|
189 | - //-------------------------------------------------------------------- |
|
190 | - |
|
191 | - /** |
|
192 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
193 | - * includes the code for the hamburger menu on small resolutions. |
|
194 | - * |
|
195 | - * @param $title |
|
196 | - * @param string $url |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function navbarTitle($title, $url='#') |
|
200 | - { |
|
201 | - return '<div class="navbar-header"> |
|
184 | + $output .= "</div></nav>\n"; |
|
185 | + |
|
186 | + return $output; |
|
187 | + } |
|
188 | + |
|
189 | + //-------------------------------------------------------------------- |
|
190 | + |
|
191 | + /** |
|
192 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
193 | + * includes the code for the hamburger menu on small resolutions. |
|
194 | + * |
|
195 | + * @param $title |
|
196 | + * @param string $url |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function navbarTitle($title, $url='#') |
|
200 | + { |
|
201 | + return '<div class="navbar-header"> |
|
202 | 202 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1"> |
203 | 203 | <span class="sr-only">Toggle navigation</span> |
204 | 204 | <span class="icon-bar"></span> |
@@ -207,396 +207,396 @@ discard block |
||
207 | 207 | </button> |
208 | 208 | <a class="navbar-brand" href="'. $url .'">'. $title .'</a> |
209 | 209 | </div>'; |
210 | - } |
|
211 | - |
|
212 | - //-------------------------------------------------------------------- |
|
213 | - |
|
214 | - /** |
|
215 | - * Creates a UL meant to pull to the right within the navbar. |
|
216 | - * |
|
217 | - * Available options: |
|
218 | - * 'class' - An additional class to add |
|
219 | - * |
|
220 | - * @param array $options |
|
221 | - * @param callable $c |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public function navbarRight($options=[], \Closure $c) |
|
225 | - { |
|
226 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
|
210 | + } |
|
211 | + |
|
212 | + //-------------------------------------------------------------------- |
|
213 | + |
|
214 | + /** |
|
215 | + * Creates a UL meant to pull to the right within the navbar. |
|
216 | + * |
|
217 | + * Available options: |
|
218 | + * 'class' - An additional class to add |
|
219 | + * |
|
220 | + * @param array $options |
|
221 | + * @param callable $c |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + public function navbarRight($options=[], \Closure $c) |
|
225 | + { |
|
226 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
|
227 | 227 | |
228 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
228 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
229 | 229 | |
230 | - $output .= $this->runClosure($c); |
|
230 | + $output .= $this->runClosure($c); |
|
231 | 231 | |
232 | - $output .= "</ul>\n"; |
|
232 | + $output .= "</ul>\n"; |
|
233 | 233 | |
234 | - return $output; |
|
235 | - } |
|
234 | + return $output; |
|
235 | + } |
|
236 | 236 | |
237 | - //-------------------------------------------------------------------- |
|
237 | + //-------------------------------------------------------------------- |
|
238 | 238 | |
239 | - public function nav() |
|
240 | - { |
|
239 | + public function nav() |
|
240 | + { |
|
241 | 241 | |
242 | - } |
|
242 | + } |
|
243 | 243 | |
244 | - //-------------------------------------------------------------------- |
|
244 | + //-------------------------------------------------------------------- |
|
245 | 245 | |
246 | 246 | |
247 | - /** |
|
248 | - * Creates a single list item for use within a nav section. |
|
249 | - * |
|
250 | - * @param $title |
|
251 | - * @param $url |
|
252 | - * @param array $options |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function navItem($title, $url='#', $options=[], $isActive=false) |
|
256 | - { |
|
257 | - $this->states['activeNavTitle'] = $title; |
|
247 | + /** |
|
248 | + * Creates a single list item for use within a nav section. |
|
249 | + * |
|
250 | + * @param $title |
|
251 | + * @param $url |
|
252 | + * @param array $options |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function navItem($title, $url='#', $options=[], $isActive=false) |
|
256 | + { |
|
257 | + $this->states['activeNavTitle'] = $title; |
|
258 | 258 | |
259 | - $class = $isActive ? $this->active_class : ''; |
|
259 | + $class = $isActive ? $this->active_class : ''; |
|
260 | 260 | |
261 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $class, true); |
|
261 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $class, true); |
|
262 | 262 | |
263 | - return " <li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>\n"; |
|
264 | - } |
|
263 | + return " <li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>\n"; |
|
264 | + } |
|
265 | 265 | |
266 | - //-------------------------------------------------------------------- |
|
267 | - |
|
268 | - /** |
|
269 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
270 | - * |
|
271 | - * @param $title |
|
272 | - * @param array $options |
|
273 | - * @param callable $c |
|
274 | - */ |
|
275 | - public function navDropdown($title,$options=[], \Closure $c) |
|
276 | - { |
|
277 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
|
278 | - |
|
279 | - $output = "\t<li {$classes} {$id} {$attributes}> |
|
266 | + //-------------------------------------------------------------------- |
|
267 | + |
|
268 | + /** |
|
269 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
270 | + * |
|
271 | + * @param $title |
|
272 | + * @param array $options |
|
273 | + * @param callable $c |
|
274 | + */ |
|
275 | + public function navDropdown($title,$options=[], \Closure $c) |
|
276 | + { |
|
277 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
|
278 | + |
|
279 | + $output = "\t<li {$classes} {$id} {$attributes}> |
|
280 | 280 | <a href='#' class='dropdown-toggle' data-toggle='dropdown'>{$title} <span class='caret'></span></a> |
281 | 281 | <ul class='dropdown-menu' role='menu'>\n"; |
282 | 282 | |
283 | - $output .= $this->runClosure($c); |
|
283 | + $output .= $this->runClosure($c); |
|
284 | + |
|
285 | + $output .= " </ul></li>\n"; |
|
284 | 286 | |
285 | - $output .= " </ul></li>\n"; |
|
287 | + return $output; |
|
288 | + } |
|
286 | 289 | |
287 | - return $output; |
|
288 | - } |
|
290 | + //-------------------------------------------------------------------- |
|
289 | 291 | |
290 | - //-------------------------------------------------------------------- |
|
292 | + /** |
|
293 | + * Creates a divider for use within a nav list. |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function navDivider() |
|
298 | + { |
|
299 | + return "<li class=\"divider\"></li>\n"; |
|
300 | + } |
|
301 | + |
|
302 | + //-------------------------------------------------------------------- |
|
303 | + |
|
304 | + public function sideNav($options=[], \Closure $c) |
|
305 | + { |
|
306 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
|
291 | 307 | |
292 | - /** |
|
293 | - * Creates a divider for use within a nav list. |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function navDivider() |
|
298 | - { |
|
299 | - return "<li class=\"divider\"></li>\n"; |
|
300 | - } |
|
308 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
301 | 309 | |
302 | - //-------------------------------------------------------------------- |
|
310 | + $output .= $this->runClosure($c); |
|
311 | + |
|
312 | + $output .= "</ul>\n"; |
|
313 | + |
|
314 | + return $output; |
|
315 | + } |
|
316 | + |
|
317 | + //-------------------------------------------------------------------- |
|
318 | + |
|
319 | + /** |
|
320 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
321 | + * |
|
322 | + * @param array $options |
|
323 | + * @param callable $c |
|
324 | + * @return mixed |
|
325 | + */ |
|
326 | + public function breadcrumb($options=[], \Closure $c) |
|
327 | + { |
|
328 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
|
303 | 329 | |
304 | - public function sideNav($options=[], \Closure $c) |
|
305 | - { |
|
306 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
|
330 | + $output = "<ol {$classes} {$id} {$attributes}>\n"; |
|
307 | 331 | |
308 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
309 | - |
|
310 | - $output .= $this->runClosure($c); |
|
311 | - |
|
312 | - $output .= "</ul>\n"; |
|
313 | - |
|
314 | - return $output; |
|
315 | - } |
|
316 | - |
|
317 | - //-------------------------------------------------------------------- |
|
318 | - |
|
319 | - /** |
|
320 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
321 | - * |
|
322 | - * @param array $options |
|
323 | - * @param callable $c |
|
324 | - * @return mixed |
|
325 | - */ |
|
326 | - public function breadcrumb($options=[], \Closure $c) |
|
327 | - { |
|
328 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
|
329 | - |
|
330 | - $output = "<ol {$classes} {$id} {$attributes}>\n"; |
|
331 | - |
|
332 | - $output .= $this->runClosure($c); |
|
333 | - |
|
334 | - $output .= "</ol>\n"; |
|
335 | - |
|
336 | - return $output; |
|
337 | - } |
|
338 | - |
|
339 | - //-------------------------------------------------------------------- |
|
340 | - |
|
341 | - |
|
342 | - //-------------------------------------------------------------------- |
|
343 | - |
|
344 | - //-------------------------------------------------------------------- |
|
345 | - // Tables |
|
346 | - //-------------------------------------------------------------------- |
|
347 | - |
|
348 | - public function table() |
|
349 | - { |
|
350 | - return 'table'; |
|
351 | - } |
|
352 | - |
|
353 | - //-------------------------------------------------------------------- |
|
354 | - |
|
355 | - //-------------------------------------------------------------------- |
|
356 | - // Buttons |
|
357 | - //-------------------------------------------------------------------- |
|
358 | - |
|
359 | - /** |
|
360 | - * Creates a simple button. |
|
361 | - * |
|
362 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
363 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
364 | - * |
|
365 | - * @param $title |
|
366 | - * @param string $style |
|
367 | - * @param array $options |
|
368 | - * @return mixed |
|
369 | - */ |
|
370 | - public function button($title, $style='default', $size='default', $options=[]) |
|
371 | - { |
|
372 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
373 | - |
|
374 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
375 | - } |
|
376 | - |
|
377 | - //-------------------------------------------------------------------- |
|
378 | - |
|
379 | - /** |
|
380 | - * Creates a simple link styled as a button. |
|
381 | - * |
|
382 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
383 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
384 | - * |
|
385 | - * @param $title |
|
386 | - * @param string $url |
|
387 | - * @param string $style |
|
388 | - * @param array $options |
|
389 | - * @return mixed |
|
390 | - */ |
|
391 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
392 | - { |
|
393 | - $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
394 | - |
|
395 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
396 | - } |
|
397 | - |
|
398 | - //-------------------------------------------------------------------- |
|
399 | - |
|
400 | - /** |
|
401 | - * Helper method to render out our buttons in a DRY manner. |
|
402 | - * |
|
403 | - * @param $title |
|
404 | - * @param $style |
|
405 | - * @param $size |
|
406 | - * @param $tag |
|
407 | - */ |
|
408 | - protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
409 | - { |
|
410 | - $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
411 | - $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
412 | - |
|
413 | - if (! in_array($style, $valid_styles)) |
|
414 | - { |
|
415 | - $style = 'default'; |
|
416 | - $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
417 | - } |
|
418 | - |
|
419 | - $classes = 'btn '; |
|
420 | - |
|
421 | - // Sizes |
|
422 | - switch($size) |
|
423 | - { |
|
424 | - case 'small': |
|
425 | - $classes .= 'btn-sm '; |
|
426 | - break; |
|
427 | - case 'xsmall': |
|
428 | - $classes .= 'btn-xs '; |
|
429 | - break; |
|
430 | - case 'large': |
|
431 | - $classes .= 'btn-lg '; |
|
432 | - break; |
|
433 | - default: |
|
434 | - break; |
|
435 | - } |
|
436 | - |
|
437 | - // Styles |
|
438 | - switch ($style) |
|
439 | - { |
|
440 | - case 'primary': |
|
441 | - $classes .= 'btn-primary '; |
|
442 | - break; |
|
443 | - case 'success': |
|
444 | - $classes .= 'btn-success '; |
|
445 | - break; |
|
446 | - case 'info': |
|
447 | - $classes .= 'btn-info '; |
|
448 | - break; |
|
449 | - case 'warning': |
|
450 | - $classes .= 'btn-warning '; |
|
451 | - break; |
|
452 | - case 'danger': |
|
453 | - $classes .= 'btn-danger '; |
|
454 | - break; |
|
455 | - case 'default': |
|
456 | - $classes .= 'btn-default '; |
|
457 | - break; |
|
458 | - } |
|
459 | - |
|
460 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
461 | - |
|
462 | - $tag = str_replace('{classes}', $classes, $tag); |
|
463 | - $tag = str_replace('{id}', $id, $tag); |
|
464 | - $tag = str_replace('{attributes}', $attributes, $tag); |
|
465 | - $tag = str_replace('{title}', $title, $tag); |
|
466 | - |
|
467 | - return $tag; |
|
468 | - } |
|
469 | - |
|
470 | - //-------------------------------------------------------------------- |
|
471 | - |
|
472 | - /** |
|
473 | - * Creates button groups wrapping HTML. |
|
474 | - * |
|
475 | - * @param $options |
|
476 | - * @param callable $c |
|
477 | - * @return mixed |
|
478 | - */ |
|
479 | - public function buttonGroup($options, \Closure $c) |
|
480 | - { |
|
481 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-group', true); |
|
482 | - |
|
483 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
484 | - |
|
485 | - $output .= $this->runClosure($c); |
|
486 | - |
|
487 | - $output .= "</div>\n"; |
|
488 | - |
|
489 | - return $output; |
|
490 | - } |
|
491 | - |
|
492 | - //-------------------------------------------------------------------- |
|
493 | - |
|
494 | - /** |
|
495 | - * Creates the button bar wrapping HTML. |
|
496 | - * |
|
497 | - * @param $options |
|
498 | - * @param callable $c |
|
499 | - * @return mixed |
|
500 | - */ |
|
501 | - public function buttonBar($options, \Closure $c) |
|
502 | - { |
|
503 | - $options['attributes'][] = 'role="toolbar"'; |
|
504 | - |
|
505 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-toolbar', true); |
|
506 | - |
|
507 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
508 | - |
|
509 | - $output .= $this->runClosure($c); |
|
510 | - |
|
511 | - $output .= "</div>\n"; |
|
512 | - |
|
513 | - return $output; |
|
514 | - } |
|
515 | - |
|
516 | - //-------------------------------------------------------------------- |
|
517 | - |
|
518 | - /** |
|
519 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
520 | - * by some frameworks. |
|
521 | - * |
|
522 | - * @param $title |
|
523 | - * @param string $style |
|
524 | - * @param string $size |
|
525 | - * @param array $options |
|
526 | - * @param callable $c |
|
527 | - * @return mixed |
|
528 | - */ |
|
529 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
530 | - { |
|
531 | - $tag = "<button type='button' {classes} data-toggle='dropdown'> |
|
332 | + $output .= $this->runClosure($c); |
|
333 | + |
|
334 | + $output .= "</ol>\n"; |
|
335 | + |
|
336 | + return $output; |
|
337 | + } |
|
338 | + |
|
339 | + //-------------------------------------------------------------------- |
|
340 | + |
|
341 | + |
|
342 | + //-------------------------------------------------------------------- |
|
343 | + |
|
344 | + //-------------------------------------------------------------------- |
|
345 | + // Tables |
|
346 | + //-------------------------------------------------------------------- |
|
347 | + |
|
348 | + public function table() |
|
349 | + { |
|
350 | + return 'table'; |
|
351 | + } |
|
352 | + |
|
353 | + //-------------------------------------------------------------------- |
|
354 | + |
|
355 | + //-------------------------------------------------------------------- |
|
356 | + // Buttons |
|
357 | + //-------------------------------------------------------------------- |
|
358 | + |
|
359 | + /** |
|
360 | + * Creates a simple button. |
|
361 | + * |
|
362 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
363 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
364 | + * |
|
365 | + * @param $title |
|
366 | + * @param string $style |
|
367 | + * @param array $options |
|
368 | + * @return mixed |
|
369 | + */ |
|
370 | + public function button($title, $style='default', $size='default', $options=[]) |
|
371 | + { |
|
372 | + $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
373 | + |
|
374 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
375 | + } |
|
376 | + |
|
377 | + //-------------------------------------------------------------------- |
|
378 | + |
|
379 | + /** |
|
380 | + * Creates a simple link styled as a button. |
|
381 | + * |
|
382 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
383 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
384 | + * |
|
385 | + * @param $title |
|
386 | + * @param string $url |
|
387 | + * @param string $style |
|
388 | + * @param array $options |
|
389 | + * @return mixed |
|
390 | + */ |
|
391 | + public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
392 | + { |
|
393 | + $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
394 | + |
|
395 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
396 | + } |
|
397 | + |
|
398 | + //-------------------------------------------------------------------- |
|
399 | + |
|
400 | + /** |
|
401 | + * Helper method to render out our buttons in a DRY manner. |
|
402 | + * |
|
403 | + * @param $title |
|
404 | + * @param $style |
|
405 | + * @param $size |
|
406 | + * @param $tag |
|
407 | + */ |
|
408 | + protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
409 | + { |
|
410 | + $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
411 | + $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
412 | + |
|
413 | + if (! in_array($style, $valid_styles)) |
|
414 | + { |
|
415 | + $style = 'default'; |
|
416 | + $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
417 | + } |
|
418 | + |
|
419 | + $classes = 'btn '; |
|
420 | + |
|
421 | + // Sizes |
|
422 | + switch($size) |
|
423 | + { |
|
424 | + case 'small': |
|
425 | + $classes .= 'btn-sm '; |
|
426 | + break; |
|
427 | + case 'xsmall': |
|
428 | + $classes .= 'btn-xs '; |
|
429 | + break; |
|
430 | + case 'large': |
|
431 | + $classes .= 'btn-lg '; |
|
432 | + break; |
|
433 | + default: |
|
434 | + break; |
|
435 | + } |
|
436 | + |
|
437 | + // Styles |
|
438 | + switch ($style) |
|
439 | + { |
|
440 | + case 'primary': |
|
441 | + $classes .= 'btn-primary '; |
|
442 | + break; |
|
443 | + case 'success': |
|
444 | + $classes .= 'btn-success '; |
|
445 | + break; |
|
446 | + case 'info': |
|
447 | + $classes .= 'btn-info '; |
|
448 | + break; |
|
449 | + case 'warning': |
|
450 | + $classes .= 'btn-warning '; |
|
451 | + break; |
|
452 | + case 'danger': |
|
453 | + $classes .= 'btn-danger '; |
|
454 | + break; |
|
455 | + case 'default': |
|
456 | + $classes .= 'btn-default '; |
|
457 | + break; |
|
458 | + } |
|
459 | + |
|
460 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
461 | + |
|
462 | + $tag = str_replace('{classes}', $classes, $tag); |
|
463 | + $tag = str_replace('{id}', $id, $tag); |
|
464 | + $tag = str_replace('{attributes}', $attributes, $tag); |
|
465 | + $tag = str_replace('{title}', $title, $tag); |
|
466 | + |
|
467 | + return $tag; |
|
468 | + } |
|
469 | + |
|
470 | + //-------------------------------------------------------------------- |
|
471 | + |
|
472 | + /** |
|
473 | + * Creates button groups wrapping HTML. |
|
474 | + * |
|
475 | + * @param $options |
|
476 | + * @param callable $c |
|
477 | + * @return mixed |
|
478 | + */ |
|
479 | + public function buttonGroup($options, \Closure $c) |
|
480 | + { |
|
481 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-group', true); |
|
482 | + |
|
483 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
484 | + |
|
485 | + $output .= $this->runClosure($c); |
|
486 | + |
|
487 | + $output .= "</div>\n"; |
|
488 | + |
|
489 | + return $output; |
|
490 | + } |
|
491 | + |
|
492 | + //-------------------------------------------------------------------- |
|
493 | + |
|
494 | + /** |
|
495 | + * Creates the button bar wrapping HTML. |
|
496 | + * |
|
497 | + * @param $options |
|
498 | + * @param callable $c |
|
499 | + * @return mixed |
|
500 | + */ |
|
501 | + public function buttonBar($options, \Closure $c) |
|
502 | + { |
|
503 | + $options['attributes'][] = 'role="toolbar"'; |
|
504 | + |
|
505 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-toolbar', true); |
|
506 | + |
|
507 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
508 | + |
|
509 | + $output .= $this->runClosure($c); |
|
510 | + |
|
511 | + $output .= "</div>\n"; |
|
512 | + |
|
513 | + return $output; |
|
514 | + } |
|
515 | + |
|
516 | + //-------------------------------------------------------------------- |
|
517 | + |
|
518 | + /** |
|
519 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
520 | + * by some frameworks. |
|
521 | + * |
|
522 | + * @param $title |
|
523 | + * @param string $style |
|
524 | + * @param string $size |
|
525 | + * @param array $options |
|
526 | + * @param callable $c |
|
527 | + * @return mixed |
|
528 | + */ |
|
529 | + public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
530 | + { |
|
531 | + $tag = "<button type='button' {classes} data-toggle='dropdown'> |
|
532 | 532 | {title} <span class='caret'></span> |
533 | 533 | </button> |
534 | 534 | <ul class='dropdown-menu' role='menu'>"; |
535 | 535 | |
536 | - $output = $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
537 | - |
|
538 | - $output .= $this->runClosure($c); |
|
539 | - |
|
540 | - $output .= "</ul>\n"; |
|
541 | - |
|
542 | - return $output; |
|
543 | - } |
|
544 | - |
|
545 | - //-------------------------------------------------------------------- |
|
546 | - |
|
547 | - //-------------------------------------------------------------------- |
|
548 | - // Notices |
|
549 | - //-------------------------------------------------------------------- |
|
550 | - |
|
551 | - /** |
|
552 | - * Creates an 'alert-box' style of notice grid. |
|
553 | - * |
|
554 | - * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
555 | - * |
|
556 | - * @param $content |
|
557 | - * @param string $style |
|
558 | - * @param bool $closable |
|
559 | - * @return mixed |
|
560 | - */ |
|
561 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
562 | - { |
|
563 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
|
564 | - |
|
565 | - // Styles |
|
566 | - switch ($style) |
|
567 | - { |
|
568 | - case 'success': |
|
569 | - $classes .= ' alert-success '; |
|
570 | - break; |
|
571 | - case 'info': |
|
572 | - $classes .= ' alert-info '; |
|
573 | - break; |
|
574 | - case 'warning': |
|
575 | - $classes .= ' alert-warning '; |
|
576 | - break; |
|
577 | - case 'danger': |
|
578 | - $classes .= ' alert-danger '; |
|
579 | - break; |
|
580 | - case 'default': |
|
581 | - $classes .= ' text-muted '; |
|
582 | - break; |
|
583 | - } |
|
584 | - |
|
585 | - $output = "<div class='{$classes}'>\n"; |
|
586 | - |
|
587 | - $output .= "\t$content\n"; |
|
588 | - |
|
589 | - if ($closable) |
|
590 | - { |
|
591 | - $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
592 | - } |
|
593 | - |
|
594 | - $output .= "</div>\n"; |
|
595 | - |
|
596 | - return $output; |
|
597 | - } |
|
598 | - |
|
599 | - //-------------------------------------------------------------------- |
|
536 | + $output = $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
537 | + |
|
538 | + $output .= $this->runClosure($c); |
|
539 | + |
|
540 | + $output .= "</ul>\n"; |
|
541 | + |
|
542 | + return $output; |
|
543 | + } |
|
544 | + |
|
545 | + //-------------------------------------------------------------------- |
|
546 | + |
|
547 | + //-------------------------------------------------------------------- |
|
548 | + // Notices |
|
549 | + //-------------------------------------------------------------------- |
|
550 | + |
|
551 | + /** |
|
552 | + * Creates an 'alert-box' style of notice grid. |
|
553 | + * |
|
554 | + * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
555 | + * |
|
556 | + * @param $content |
|
557 | + * @param string $style |
|
558 | + * @param bool $closable |
|
559 | + * @return mixed |
|
560 | + */ |
|
561 | + public function notice($content, $style='success', $closable=true, $options=[]) |
|
562 | + { |
|
563 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
|
564 | + |
|
565 | + // Styles |
|
566 | + switch ($style) |
|
567 | + { |
|
568 | + case 'success': |
|
569 | + $classes .= ' alert-success '; |
|
570 | + break; |
|
571 | + case 'info': |
|
572 | + $classes .= ' alert-info '; |
|
573 | + break; |
|
574 | + case 'warning': |
|
575 | + $classes .= ' alert-warning '; |
|
576 | + break; |
|
577 | + case 'danger': |
|
578 | + $classes .= ' alert-danger '; |
|
579 | + break; |
|
580 | + case 'default': |
|
581 | + $classes .= ' text-muted '; |
|
582 | + break; |
|
583 | + } |
|
584 | + |
|
585 | + $output = "<div class='{$classes}'>\n"; |
|
586 | + |
|
587 | + $output .= "\t$content\n"; |
|
588 | + |
|
589 | + if ($closable) |
|
590 | + { |
|
591 | + $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
592 | + } |
|
593 | + |
|
594 | + $output .= "</div>\n"; |
|
595 | + |
|
596 | + return $output; |
|
597 | + } |
|
598 | + |
|
599 | + //-------------------------------------------------------------------- |
|
600 | 600 | |
601 | 601 | //-------------------------------------------------------------------- |
602 | 602 | // Forms |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * approach to rows and columns than the reference Bootstrap and Foundation. |
57 | 57 | * |
58 | 58 | * @param array $options |
59 | - * @return mixed |
|
59 | + * @return string |
|
60 | 60 | */ |
61 | 61 | public function row($options=[], \Closure $c) |
62 | 62 | { |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
88 | 88 | * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
89 | 89 | * |
90 | - * @param array $attributes |
|
91 | - * @return mixed |
|
90 | + * @return string |
|
92 | 91 | */ |
93 | 92 | public function column($options=[], \Closure $c) |
94 | 93 | { |
@@ -152,7 +151,7 @@ discard block |
||
152 | 151 | * top of a page. |
153 | 152 | * |
154 | 153 | * @param array $options |
155 | - * @param callable $c |
|
154 | + * @param \Closure $c |
|
156 | 155 | * @return string |
157 | 156 | */ |
158 | 157 | public function navbar($options=[], \Closure $c) |
@@ -224,7 +223,7 @@ discard block |
||
224 | 223 | * 'class' - An additional class to add |
225 | 224 | * |
226 | 225 | * @param array $options |
227 | - * @param callable $c |
|
226 | + * @param \Closure $c |
|
228 | 227 | * @return string |
229 | 228 | */ |
230 | 229 | public function navbarRight($options=[], \Closure $c) |
@@ -263,7 +262,7 @@ discard block |
||
263 | 262 | * 'class' - An additional class to add |
264 | 263 | * |
265 | 264 | * @param array $options |
266 | - * @param callable $c |
|
265 | + * @param \Closure $c |
|
267 | 266 | * @return string |
268 | 267 | */ |
269 | 268 | public function navbarLeft($options=[], \Closure $c) |
@@ -331,7 +330,7 @@ discard block |
||
331 | 330 | * |
332 | 331 | * @param $title |
333 | 332 | * @param array $options |
334 | - * @param callable $c |
|
333 | + * @param \Closure $c |
|
335 | 334 | */ |
336 | 335 | public function navDropdown($title,$options=[], \Closure $c) |
337 | 336 | { |
@@ -389,8 +388,8 @@ discard block |
||
389 | 388 | * Creates a list of nav items to function as breadcrumbs for a site. |
390 | 389 | * |
391 | 390 | * @param array $options |
392 | - * @param callable $c |
|
393 | - * @return mixed |
|
391 | + * @param \Closure $c |
|
392 | + * @return string |
|
394 | 393 | */ |
395 | 394 | public function breadcrumb($options=[], \Closure $c) |
396 | 395 | { |
@@ -470,8 +469,8 @@ discard block |
||
470 | 469 | * Helper method to render out our buttons in a DRY manner. |
471 | 470 | * |
472 | 471 | * @param $title |
473 | - * @param $style |
|
474 | - * @param $size |
|
472 | + * @param string $style |
|
473 | + * @param string $size |
|
475 | 474 | * @param $tag |
476 | 475 | */ |
477 | 476 | protected function renderButtonElement($title, $style, $size, $options, $tag) |
@@ -547,8 +546,8 @@ discard block |
||
547 | 546 | * Creates button groups wrapping HTML. |
548 | 547 | * |
549 | 548 | * @param $options |
550 | - * @param callable $c |
|
551 | - * @return mixed |
|
549 | + * @param \Closure $c |
|
550 | + * @return string |
|
552 | 551 | */ |
553 | 552 | public function buttonGroup($options, \Closure $c) |
554 | 553 | { |
@@ -573,8 +572,8 @@ discard block |
||
573 | 572 | * Creates the button bar wrapping HTML. |
574 | 573 | * |
575 | 574 | * @param $options |
576 | - * @param callable $c |
|
577 | - * @return mixed |
|
575 | + * @param \Closure $c |
|
576 | + * @return string |
|
578 | 577 | */ |
579 | 578 | public function buttonBar($options, \Closure $c) |
580 | 579 | { |
@@ -599,8 +598,8 @@ discard block |
||
599 | 598 | * @param string $style |
600 | 599 | * @param string $size |
601 | 600 | * @param array $options |
602 | - * @param callable $c |
|
603 | - * @return mixed |
|
601 | + * @param \Closure $c |
|
602 | + * @return string |
|
604 | 603 | */ |
605 | 604 | public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
606 | 605 | { |
@@ -630,7 +629,7 @@ discard block |
||
630 | 629 | * @param $content |
631 | 630 | * @param string $style |
632 | 631 | * @param bool $closable |
633 | - * @return mixed |
|
632 | + * @return string |
|
634 | 633 | */ |
635 | 634 | public function notice($content, $style='success', $closable=true, $options=[]) |
636 | 635 | { |
@@ -37,639 +37,639 @@ |
||
37 | 37 | */ |
38 | 38 | class Foundation extends BaseUIKit { |
39 | 39 | |
40 | - //-------------------------------------------------------------------- |
|
41 | - |
|
42 | - public function name() |
|
43 | - { |
|
44 | - return 'Foundation5UIKit'; |
|
45 | - } |
|
46 | - |
|
47 | - //-------------------------------------------------------------------- |
|
48 | - |
|
49 | - //-------------------------------------------------------------------- |
|
50 | - // Grid |
|
51 | - //-------------------------------------------------------------------- |
|
52 | - |
|
53 | - /** |
|
54 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
55 | - * the class for it, but some frameworks use a completely different |
|
56 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
57 | - * |
|
58 | - * @param array $options |
|
59 | - * @return mixed |
|
60 | - */ |
|
61 | - public function row($options=[], \Closure $c) |
|
62 | - { |
|
63 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
64 | - |
|
65 | - $output = "<div {$classes} {$id} {$attributes}>"; |
|
66 | - |
|
67 | - $output .= $this->runClosure($c); |
|
68 | - |
|
69 | - $output .= "</div>"; |
|
70 | - |
|
71 | - return $output; |
|
72 | - } |
|
73 | - |
|
74 | - //-------------------------------------------------------------------- |
|
75 | - |
|
76 | - /** |
|
77 | - * Creates the CSS for a column in a grid. |
|
78 | - * |
|
79 | - * The attribute array is made up of key/value pairs with the |
|
80 | - * key being the size, and the value being the number of columns/offset |
|
81 | - * in a 12-column grid. |
|
82 | - * |
|
83 | - * Note that we currently DO NOT support offset columns. |
|
84 | - * |
|
85 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
86 | - * |
|
87 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
88 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
89 | - * |
|
90 | - * @param array $attributes |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - public function column($options=[], \Closure $c) |
|
94 | - { |
|
95 | - // Build our classes |
|
96 | - $classes = ''; |
|
97 | - |
|
98 | - foreach ($options['sizes'] as $size => $value) |
|
99 | - { |
|
100 | - switch ($size) |
|
101 | - { |
|
102 | - case 's': |
|
103 | - $classes .= ' small-'. $value; |
|
104 | - break; |
|
105 | - case 'm': |
|
106 | - $classes .= ' medium-'. $value; |
|
107 | - break; |
|
108 | - case 'l': |
|
109 | - $classes .= ' large-'. $value; |
|
110 | - break; |
|
111 | - case 'xl': |
|
112 | - $classes .= ' large-'. $value; |
|
113 | - break; |
|
114 | - case 's-offset': |
|
115 | - $classes .= ' small-offset-'. $value; |
|
116 | - break; |
|
117 | - case 'm-offset': |
|
118 | - $classes .= ' medium-offset-'. $value; |
|
119 | - break; |
|
120 | - case 'l-offset': |
|
121 | - $classes .= ' large-offset-'. $value; |
|
122 | - break; |
|
123 | - case 'xl-offset': |
|
124 | - $classes .= ' large-offset-'. $value; |
|
125 | - break; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - $classes = $this->buildClassString($classes .' columns', $options, true); |
|
130 | - |
|
131 | - $id = $this->buildIdFromOptions($options); |
|
132 | - |
|
133 | - $attributes = $this->buildAttributesFromOptions($options); |
|
134 | - |
|
135 | - $output = "<div {$classes} {$id} {$attributes}>"; |
|
136 | - |
|
137 | - $output .= $this->runClosure($c); |
|
138 | - |
|
139 | - $output .= "</div>"; |
|
140 | - |
|
141 | - return $output; |
|
142 | - } |
|
143 | - |
|
144 | - //-------------------------------------------------------------------- |
|
145 | - |
|
146 | - //-------------------------------------------------------------------- |
|
147 | - // Navigation |
|
148 | - //-------------------------------------------------------------------- |
|
149 | - |
|
150 | - /** |
|
151 | - * Generates the container code for a navbar, typically used along the |
|
152 | - * top of a page. |
|
153 | - * |
|
154 | - * @param array $options |
|
155 | - * @param callable $c |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function navbar($options=[], \Closure $c) |
|
159 | - { |
|
160 | - $output = ''; |
|
161 | - |
|
162 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'top-bar ', true); |
|
163 | - |
|
164 | - foreach ($options as $option) |
|
165 | - { |
|
166 | - switch ($option) |
|
167 | - { |
|
168 | - case 'sticky-top': |
|
169 | - $classes .= " navbar-static-top"; |
|
170 | - break; |
|
171 | - case 'fixed': |
|
172 | - $classes .= " navbar-fixed-top"; |
|
173 | - break; |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - $output .= "<nav {$classes} {$id} {$attributes} data-topbar>"; |
|
178 | - |
|
179 | - /* |
|
40 | + //-------------------------------------------------------------------- |
|
41 | + |
|
42 | + public function name() |
|
43 | + { |
|
44 | + return 'Foundation5UIKit'; |
|
45 | + } |
|
46 | + |
|
47 | + //-------------------------------------------------------------------- |
|
48 | + |
|
49 | + //-------------------------------------------------------------------- |
|
50 | + // Grid |
|
51 | + //-------------------------------------------------------------------- |
|
52 | + |
|
53 | + /** |
|
54 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
55 | + * the class for it, but some frameworks use a completely different |
|
56 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
57 | + * |
|
58 | + * @param array $options |
|
59 | + * @return mixed |
|
60 | + */ |
|
61 | + public function row($options=[], \Closure $c) |
|
62 | + { |
|
63 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
64 | + |
|
65 | + $output = "<div {$classes} {$id} {$attributes}>"; |
|
66 | + |
|
67 | + $output .= $this->runClosure($c); |
|
68 | + |
|
69 | + $output .= "</div>"; |
|
70 | + |
|
71 | + return $output; |
|
72 | + } |
|
73 | + |
|
74 | + //-------------------------------------------------------------------- |
|
75 | + |
|
76 | + /** |
|
77 | + * Creates the CSS for a column in a grid. |
|
78 | + * |
|
79 | + * The attribute array is made up of key/value pairs with the |
|
80 | + * key being the size, and the value being the number of columns/offset |
|
81 | + * in a 12-column grid. |
|
82 | + * |
|
83 | + * Note that we currently DO NOT support offset columns. |
|
84 | + * |
|
85 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
86 | + * |
|
87 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
88 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
89 | + * |
|
90 | + * @param array $attributes |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + public function column($options=[], \Closure $c) |
|
94 | + { |
|
95 | + // Build our classes |
|
96 | + $classes = ''; |
|
97 | + |
|
98 | + foreach ($options['sizes'] as $size => $value) |
|
99 | + { |
|
100 | + switch ($size) |
|
101 | + { |
|
102 | + case 's': |
|
103 | + $classes .= ' small-'. $value; |
|
104 | + break; |
|
105 | + case 'm': |
|
106 | + $classes .= ' medium-'. $value; |
|
107 | + break; |
|
108 | + case 'l': |
|
109 | + $classes .= ' large-'. $value; |
|
110 | + break; |
|
111 | + case 'xl': |
|
112 | + $classes .= ' large-'. $value; |
|
113 | + break; |
|
114 | + case 's-offset': |
|
115 | + $classes .= ' small-offset-'. $value; |
|
116 | + break; |
|
117 | + case 'm-offset': |
|
118 | + $classes .= ' medium-offset-'. $value; |
|
119 | + break; |
|
120 | + case 'l-offset': |
|
121 | + $classes .= ' large-offset-'. $value; |
|
122 | + break; |
|
123 | + case 'xl-offset': |
|
124 | + $classes .= ' large-offset-'. $value; |
|
125 | + break; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + $classes = $this->buildClassString($classes .' columns', $options, true); |
|
130 | + |
|
131 | + $id = $this->buildIdFromOptions($options); |
|
132 | + |
|
133 | + $attributes = $this->buildAttributesFromOptions($options); |
|
134 | + |
|
135 | + $output = "<div {$classes} {$id} {$attributes}>"; |
|
136 | + |
|
137 | + $output .= $this->runClosure($c); |
|
138 | + |
|
139 | + $output .= "</div>"; |
|
140 | + |
|
141 | + return $output; |
|
142 | + } |
|
143 | + |
|
144 | + //-------------------------------------------------------------------- |
|
145 | + |
|
146 | + //-------------------------------------------------------------------- |
|
147 | + // Navigation |
|
148 | + //-------------------------------------------------------------------- |
|
149 | + |
|
150 | + /** |
|
151 | + * Generates the container code for a navbar, typically used along the |
|
152 | + * top of a page. |
|
153 | + * |
|
154 | + * @param array $options |
|
155 | + * @param callable $c |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function navbar($options=[], \Closure $c) |
|
159 | + { |
|
160 | + $output = ''; |
|
161 | + |
|
162 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'top-bar ', true); |
|
163 | + |
|
164 | + foreach ($options as $option) |
|
165 | + { |
|
166 | + switch ($option) |
|
167 | + { |
|
168 | + case 'sticky-top': |
|
169 | + $classes .= " navbar-static-top"; |
|
170 | + break; |
|
171 | + case 'fixed': |
|
172 | + $classes .= " navbar-fixed-top"; |
|
173 | + break; |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + $output .= "<nav {$classes} {$id} {$attributes} data-topbar>"; |
|
178 | + |
|
179 | + /* |
|
180 | 180 | * Do any user content inside the bar |
181 | 181 | */ |
182 | - $output .= $this->runClosure($c); |
|
182 | + $output .= $this->runClosure($c); |
|
183 | 183 | |
184 | - if (isset($this->states['nav-section-open'])) |
|
185 | - { |
|
186 | - $output .= "</section>"; |
|
187 | - unset($this->states['nav-section-open']); |
|
188 | - } |
|
184 | + if (isset($this->states['nav-section-open'])) |
|
185 | + { |
|
186 | + $output .= "</section>"; |
|
187 | + unset($this->states['nav-section-open']); |
|
188 | + } |
|
189 | 189 | |
190 | - /* |
|
190 | + /* |
|
191 | 191 | * Close out the navbar |
192 | 192 | */ |
193 | - $output .= '</nav>'; |
|
194 | - |
|
195 | - return $output; |
|
196 | - } |
|
197 | - |
|
198 | - //-------------------------------------------------------------------- |
|
199 | - |
|
200 | - /** |
|
201 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
202 | - * includes the code for the hamburger menu on small resolutions. |
|
203 | - * |
|
204 | - * @param $title |
|
205 | - * @param string $url |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function navbarTitle($title, $url='#') |
|
209 | - { |
|
210 | - return "<ul class='title-area'> |
|
193 | + $output .= '</nav>'; |
|
194 | + |
|
195 | + return $output; |
|
196 | + } |
|
197 | + |
|
198 | + //-------------------------------------------------------------------- |
|
199 | + |
|
200 | + /** |
|
201 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
202 | + * includes the code for the hamburger menu on small resolutions. |
|
203 | + * |
|
204 | + * @param $title |
|
205 | + * @param string $url |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function navbarTitle($title, $url='#') |
|
209 | + { |
|
210 | + return "<ul class='title-area'> |
|
211 | 211 | <li class='name'> |
212 | 212 | <h1><a href='{$url}'>{$title}</a></h1> |
213 | 213 | </li> |
214 | 214 | <li class='toggle-topbar menu-icon'><a href='#'><span>Menu</span></a></li> |
215 | 215 | </ul>"; |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - //-------------------------------------------------------------------- |
|
218 | + //-------------------------------------------------------------------- |
|
219 | 219 | |
220 | - /** |
|
221 | - * Creates a UL meant to pull to the right within the navbar. |
|
222 | - * |
|
223 | - * Available options: |
|
224 | - * 'class' - An additional class to add |
|
225 | - * |
|
226 | - * @param array $options |
|
227 | - * @param callable $c |
|
228 | - * @return string |
|
229 | - */ |
|
230 | - public function navbarRight($options=[], \Closure $c) |
|
231 | - { |
|
232 | - $output = ''; |
|
220 | + /** |
|
221 | + * Creates a UL meant to pull to the right within the navbar. |
|
222 | + * |
|
223 | + * Available options: |
|
224 | + * 'class' - An additional class to add |
|
225 | + * |
|
226 | + * @param array $options |
|
227 | + * @param callable $c |
|
228 | + * @return string |
|
229 | + */ |
|
230 | + public function navbarRight($options=[], \Closure $c) |
|
231 | + { |
|
232 | + $output = ''; |
|
233 | 233 | |
234 | - if (! isset($this->states['nav-section-open'])) |
|
235 | - { |
|
236 | - $output .= "<section class='top-bar-section'>\n"; |
|
237 | - $this->states['nav-section-open'] = true; |
|
238 | - } |
|
234 | + if (! isset($this->states['nav-section-open'])) |
|
235 | + { |
|
236 | + $output .= "<section class='top-bar-section'>\n"; |
|
237 | + $this->states['nav-section-open'] = true; |
|
238 | + } |
|
239 | 239 | |
240 | - // Class |
|
241 | - $classes = $this->buildClassString('right', $options); |
|
240 | + // Class |
|
241 | + $classes = $this->buildClassString('right', $options); |
|
242 | 242 | |
243 | - // ID |
|
244 | - $id = $this->buildIdFromOptions($options); |
|
243 | + // ID |
|
244 | + $id = $this->buildIdFromOptions($options); |
|
245 | 245 | |
246 | - $attributes = $this->buildAttributesFromOptions($options); |
|
246 | + $attributes = $this->buildAttributesFromOptions($options); |
|
247 | 247 | |
248 | - $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
248 | + $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
249 | 249 | |
250 | - $output .= $this->runClosure($c); |
|
250 | + $output .= $this->runClosure($c); |
|
251 | 251 | |
252 | - $output .= "</ul>\n"; |
|
252 | + $output .= "</ul>\n"; |
|
253 | 253 | |
254 | - return $output; |
|
255 | - } |
|
254 | + return $output; |
|
255 | + } |
|
256 | 256 | |
257 | - //-------------------------------------------------------------------- |
|
257 | + //-------------------------------------------------------------------- |
|
258 | 258 | |
259 | - /** |
|
260 | - * Creates a UL meant to pull to the left within the navbar. |
|
261 | - * |
|
262 | - * Available options: |
|
263 | - * 'class' - An additional class to add |
|
264 | - * |
|
265 | - * @param array $options |
|
266 | - * @param callable $c |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function navbarLeft($options=[], \Closure $c) |
|
270 | - { |
|
271 | - $output = ''; |
|
259 | + /** |
|
260 | + * Creates a UL meant to pull to the left within the navbar. |
|
261 | + * |
|
262 | + * Available options: |
|
263 | + * 'class' - An additional class to add |
|
264 | + * |
|
265 | + * @param array $options |
|
266 | + * @param callable $c |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function navbarLeft($options=[], \Closure $c) |
|
270 | + { |
|
271 | + $output = ''; |
|
272 | 272 | |
273 | - if (! isset($this->states['nav-section-open'])) |
|
274 | - { |
|
275 | - $output .= "<section class='top-bar-section'>\n"; |
|
276 | - $this->states['nav-section-open'] = true; |
|
277 | - } |
|
273 | + if (! isset($this->states['nav-section-open'])) |
|
274 | + { |
|
275 | + $output .= "<section class='top-bar-section'>\n"; |
|
276 | + $this->states['nav-section-open'] = true; |
|
277 | + } |
|
278 | 278 | |
279 | - // Class |
|
280 | - $classes = $this->buildClassString('left', $options); |
|
279 | + // Class |
|
280 | + $classes = $this->buildClassString('left', $options); |
|
281 | 281 | |
282 | - // ID |
|
283 | - $id = $this->buildIdFromOptions($options); |
|
282 | + // ID |
|
283 | + $id = $this->buildIdFromOptions($options); |
|
284 | 284 | |
285 | - $attributes = $this->buildAttributesFromOptions($options); |
|
285 | + $attributes = $this->buildAttributesFromOptions($options); |
|
286 | 286 | |
287 | - $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
287 | + $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
288 | 288 | |
289 | - $output .= $this->runClosure($c); |
|
289 | + $output .= $this->runClosure($c); |
|
290 | 290 | |
291 | - $output .= "</ul>\n"; |
|
291 | + $output .= "</ul>\n"; |
|
292 | 292 | |
293 | - return $output; |
|
294 | - } |
|
293 | + return $output; |
|
294 | + } |
|
295 | 295 | |
296 | - //-------------------------------------------------------------------- |
|
296 | + //-------------------------------------------------------------------- |
|
297 | 297 | |
298 | - public function nav() |
|
299 | - { |
|
298 | + public function nav() |
|
299 | + { |
|
300 | 300 | |
301 | - } |
|
301 | + } |
|
302 | 302 | |
303 | - //-------------------------------------------------------------------- |
|
303 | + //-------------------------------------------------------------------- |
|
304 | 304 | |
305 | 305 | |
306 | - /** |
|
307 | - * Creates a single list item for use within a nav section. |
|
308 | - * |
|
309 | - * @param $title |
|
310 | - * @param $url |
|
311 | - * @param array $options |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function navItem($title, $url='#', $options=[], $active=false) |
|
315 | - { |
|
316 | - $options['active'] = $active; |
|
306 | + /** |
|
307 | + * Creates a single list item for use within a nav section. |
|
308 | + * |
|
309 | + * @param $title |
|
310 | + * @param $url |
|
311 | + * @param array $options |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function navItem($title, $url='#', $options=[], $active=false) |
|
315 | + { |
|
316 | + $options['active'] = $active; |
|
317 | 317 | |
318 | - $classes = $this->buildClassString('', $options, true); |
|
318 | + $classes = $this->buildClassString('', $options, true); |
|
319 | 319 | |
320 | - $id = $this->buildIdFromOptions($options); |
|
320 | + $id = $this->buildIdFromOptions($options); |
|
321 | 321 | |
322 | - $attributes = $this->buildAttributesFromOptions($options); |
|
322 | + $attributes = $this->buildAttributesFromOptions($options); |
|
323 | 323 | |
324 | - return "\t<li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>"; |
|
325 | - } |
|
324 | + return "\t<li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>"; |
|
325 | + } |
|
326 | 326 | |
327 | - //-------------------------------------------------------------------- |
|
327 | + //-------------------------------------------------------------------- |
|
328 | 328 | |
329 | - /** |
|
330 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
331 | - * |
|
332 | - * @param $title |
|
333 | - * @param array $options |
|
334 | - * @param callable $c |
|
335 | - */ |
|
336 | - public function navDropdown($title,$options=[], \Closure $c) |
|
337 | - { |
|
338 | - $classes = $this->buildClassString('has-dropdown', $options, true); |
|
329 | + /** |
|
330 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
331 | + * |
|
332 | + * @param $title |
|
333 | + * @param array $options |
|
334 | + * @param callable $c |
|
335 | + */ |
|
336 | + public function navDropdown($title,$options=[], \Closure $c) |
|
337 | + { |
|
338 | + $classes = $this->buildClassString('has-dropdown', $options, true); |
|
339 | 339 | |
340 | - $id = $this->buildIdFromOptions($options); |
|
340 | + $id = $this->buildIdFromOptions($options); |
|
341 | 341 | |
342 | - $attributes = $this->buildAttributesFromOptions($options); |
|
342 | + $attributes = $this->buildAttributesFromOptions($options); |
|
343 | 343 | |
344 | - $output = "\t<li {$classes} {$id} {$attributes}> |
|
344 | + $output = "\t<li {$classes} {$id} {$attributes}> |
|
345 | 345 | <a href='#'>{$title}</a> |
346 | 346 | <ul class='dropdown'>"; |
347 | 347 | |
348 | - $output .= $this->runClosure($c); |
|
348 | + $output .= $this->runClosure($c); |
|
349 | 349 | |
350 | - $output .= "\t</ul></li>"; |
|
350 | + $output .= "\t</ul></li>"; |
|
351 | 351 | |
352 | - return $output; |
|
353 | - } |
|
352 | + return $output; |
|
353 | + } |
|
354 | 354 | |
355 | - //-------------------------------------------------------------------- |
|
355 | + //-------------------------------------------------------------------- |
|
356 | 356 | |
357 | - /** |
|
358 | - * Creates a divider for use within a nav list. |
|
359 | - * |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - public function navDivider() |
|
363 | - { |
|
364 | - return '<li class="divider"></li>'; |
|
365 | - } |
|
357 | + /** |
|
358 | + * Creates a divider for use within a nav list. |
|
359 | + * |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + public function navDivider() |
|
363 | + { |
|
364 | + return '<li class="divider"></li>'; |
|
365 | + } |
|
366 | 366 | |
367 | - //-------------------------------------------------------------------- |
|
367 | + //-------------------------------------------------------------------- |
|
368 | 368 | |
369 | - public function sideNav($options=[], \Closure $c) |
|
370 | - { |
|
371 | - $classes = $this->buildClassString('side-nav', $options, true); |
|
369 | + public function sideNav($options=[], \Closure $c) |
|
370 | + { |
|
371 | + $classes = $this->buildClassString('side-nav', $options, true); |
|
372 | 372 | |
373 | - $id = $this->buildIdFromOptions($options); |
|
373 | + $id = $this->buildIdFromOptions($options); |
|
374 | 374 | |
375 | - $attributes = $this->buildAttributesFromOptions($options); |
|
375 | + $attributes = $this->buildAttributesFromOptions($options); |
|
376 | 376 | |
377 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
378 | - |
|
379 | - $output .= $this->runClosure($c); |
|
380 | - |
|
381 | - $output .= "</ul>\n"; |
|
382 | - |
|
383 | - return $output; |
|
384 | - } |
|
385 | - |
|
386 | - //-------------------------------------------------------------------- |
|
387 | - |
|
388 | - /** |
|
389 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
390 | - * |
|
391 | - * @param array $options |
|
392 | - * @param callable $c |
|
393 | - * @return mixed |
|
394 | - */ |
|
395 | - public function breadcrumb($options=[], \Closure $c) |
|
396 | - { |
|
397 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
|
398 | - |
|
399 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
400 | - |
|
401 | - $output .= $this->runClosure($c); |
|
402 | - |
|
403 | - $output .= "</ul>\n"; |
|
404 | - |
|
405 | - return $output; |
|
406 | - } |
|
407 | - |
|
408 | - //-------------------------------------------------------------------- |
|
409 | - |
|
410 | - //-------------------------------------------------------------------- |
|
411 | - // Tables |
|
412 | - //-------------------------------------------------------------------- |
|
413 | - |
|
414 | - public function table() |
|
415 | - { |
|
416 | - return 'table'; |
|
417 | - } |
|
418 | - |
|
419 | - //-------------------------------------------------------------------- |
|
420 | - |
|
421 | - //-------------------------------------------------------------------- |
|
422 | - // Buttons |
|
423 | - //-------------------------------------------------------------------- |
|
424 | - |
|
425 | - /** |
|
426 | - * Creates a simple button. |
|
427 | - * |
|
428 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
429 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
430 | - * |
|
431 | - * @param $title |
|
432 | - * @param string $style |
|
433 | - * @param array $options |
|
434 | - * @return mixed |
|
435 | - */ |
|
436 | - public function button($title, $style='default', $size='default', $options=[]) |
|
437 | - { |
|
438 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
439 | - |
|
440 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
441 | - } |
|
442 | - |
|
443 | - //-------------------------------------------------------------------- |
|
444 | - |
|
445 | - /** |
|
446 | - * Creates a simple link styled as a button. |
|
447 | - * |
|
448 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
449 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
450 | - * |
|
451 | - * @param $title |
|
452 | - * @param string $url |
|
453 | - * @param string $style |
|
454 | - * @param array $options |
|
455 | - * @return mixed |
|
456 | - */ |
|
457 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
458 | - { |
|
459 | - $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
460 | - $options['class'] = $class; |
|
461 | - |
|
462 | - $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
463 | - |
|
464 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
465 | - } |
|
466 | - |
|
467 | - //-------------------------------------------------------------------- |
|
468 | - |
|
469 | - /** |
|
470 | - * Helper method to render out our buttons in a DRY manner. |
|
471 | - * |
|
472 | - * @param $title |
|
473 | - * @param $style |
|
474 | - * @param $size |
|
475 | - * @param $tag |
|
476 | - */ |
|
477 | - protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
478 | - { |
|
479 | - $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
480 | - $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
481 | - |
|
482 | - if (! in_array($style, $valid_styles)) |
|
483 | - { |
|
484 | - $style = 'default'; |
|
485 | - $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
486 | - } |
|
487 | - |
|
488 | - $classes = 'btn '; |
|
489 | - |
|
490 | - // Sizes |
|
491 | - switch($size) |
|
492 | - { |
|
493 | - case 'small': |
|
494 | - $classes .= 'small '; |
|
495 | - break; |
|
496 | - case 'xsmall': |
|
497 | - $classes .= 'tiny '; |
|
498 | - break; |
|
499 | - case 'large': |
|
500 | - $classes .= 'large '; |
|
501 | - break; |
|
502 | - default: |
|
503 | - break; |
|
504 | - } |
|
505 | - |
|
506 | - // Styles |
|
507 | - switch ($style) |
|
508 | - { |
|
509 | - case 'primary': |
|
510 | - $classes .= ''; |
|
511 | - break; |
|
512 | - case 'success': |
|
513 | - $classes .= 'success '; |
|
514 | - break; |
|
515 | - case 'info': |
|
516 | - $classes .= 'secondary '; |
|
517 | - break; |
|
518 | - case 'warning': |
|
519 | - $classes .= 'alert '; |
|
520 | - break; |
|
521 | - case 'danger': |
|
522 | - $classes .= 'alert '; |
|
523 | - break; |
|
524 | - case 'default': |
|
525 | - $classes .= 'secondary '; |
|
526 | - break; |
|
527 | - } |
|
528 | - |
|
529 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
530 | - |
|
531 | - $tag = str_replace('{classes}', $classes, $tag); |
|
532 | - $tag = str_replace('{id}', $id, $tag); |
|
533 | - $tag = str_replace('{attributes}', $attributes, $tag); |
|
534 | - $tag = str_replace('{title}', $title, $tag); |
|
535 | - |
|
536 | - // If we're in a button group we need to wrap each item in li tags. |
|
537 | - if (isset($this->states['inButtonGroup'])) |
|
538 | - { |
|
539 | - $tag = '<li>'. $tag .'</li>'; |
|
540 | - } |
|
541 | - return $tag; |
|
542 | - } |
|
543 | - |
|
544 | - //-------------------------------------------------------------------- |
|
545 | - |
|
546 | - /** |
|
547 | - * Creates button groups wrapping HTML. |
|
548 | - * |
|
549 | - * @param $options |
|
550 | - * @param callable $c |
|
551 | - * @return mixed |
|
552 | - */ |
|
553 | - public function buttonGroup($options, \Closure $c) |
|
554 | - { |
|
555 | - $this->states['inButtonGroup'] = true; |
|
556 | - |
|
557 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-group', true); |
|
558 | - |
|
559 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
560 | - |
|
561 | - $output .= $this->runClosure($c); |
|
562 | - |
|
563 | - $output .= "</ul>\n"; |
|
564 | - |
|
565 | - unset($this->states['inButtonGroup']); |
|
566 | - |
|
567 | - return $output; |
|
568 | - } |
|
569 | - |
|
570 | - //-------------------------------------------------------------------- |
|
571 | - |
|
572 | - /** |
|
573 | - * Creates the button bar wrapping HTML. |
|
574 | - * |
|
575 | - * @param $options |
|
576 | - * @param callable $c |
|
577 | - * @return mixed |
|
578 | - */ |
|
579 | - public function buttonBar($options, \Closure $c) |
|
580 | - { |
|
581 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-bar', true); |
|
582 | - |
|
583 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
584 | - |
|
585 | - $output .= $this->runClosure($c); |
|
586 | - |
|
587 | - $output .= "</div>\n"; |
|
588 | - |
|
589 | - return $output; |
|
590 | - } |
|
591 | - |
|
592 | - //-------------------------------------------------------------------- |
|
593 | - |
|
594 | - /** |
|
595 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
596 | - * by some frameworks. |
|
597 | - * |
|
598 | - * @param $title |
|
599 | - * @param string $style |
|
600 | - * @param string $size |
|
601 | - * @param array $options |
|
602 | - * @param callable $c |
|
603 | - * @return mixed |
|
604 | - */ |
|
605 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
606 | - { |
|
607 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
|
608 | - |
|
609 | - $output = "<a href='#' {$classes} {$id} {$attributes}>{$title} <span data-dropdown='drop'></span></a><br>\n |
|
377 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
378 | + |
|
379 | + $output .= $this->runClosure($c); |
|
380 | + |
|
381 | + $output .= "</ul>\n"; |
|
382 | + |
|
383 | + return $output; |
|
384 | + } |
|
385 | + |
|
386 | + //-------------------------------------------------------------------- |
|
387 | + |
|
388 | + /** |
|
389 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
390 | + * |
|
391 | + * @param array $options |
|
392 | + * @param callable $c |
|
393 | + * @return mixed |
|
394 | + */ |
|
395 | + public function breadcrumb($options=[], \Closure $c) |
|
396 | + { |
|
397 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
|
398 | + |
|
399 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
400 | + |
|
401 | + $output .= $this->runClosure($c); |
|
402 | + |
|
403 | + $output .= "</ul>\n"; |
|
404 | + |
|
405 | + return $output; |
|
406 | + } |
|
407 | + |
|
408 | + //-------------------------------------------------------------------- |
|
409 | + |
|
410 | + //-------------------------------------------------------------------- |
|
411 | + // Tables |
|
412 | + //-------------------------------------------------------------------- |
|
413 | + |
|
414 | + public function table() |
|
415 | + { |
|
416 | + return 'table'; |
|
417 | + } |
|
418 | + |
|
419 | + //-------------------------------------------------------------------- |
|
420 | + |
|
421 | + //-------------------------------------------------------------------- |
|
422 | + // Buttons |
|
423 | + //-------------------------------------------------------------------- |
|
424 | + |
|
425 | + /** |
|
426 | + * Creates a simple button. |
|
427 | + * |
|
428 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
429 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
430 | + * |
|
431 | + * @param $title |
|
432 | + * @param string $style |
|
433 | + * @param array $options |
|
434 | + * @return mixed |
|
435 | + */ |
|
436 | + public function button($title, $style='default', $size='default', $options=[]) |
|
437 | + { |
|
438 | + $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
439 | + |
|
440 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
441 | + } |
|
442 | + |
|
443 | + //-------------------------------------------------------------------- |
|
444 | + |
|
445 | + /** |
|
446 | + * Creates a simple link styled as a button. |
|
447 | + * |
|
448 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
449 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
450 | + * |
|
451 | + * @param $title |
|
452 | + * @param string $url |
|
453 | + * @param string $style |
|
454 | + * @param array $options |
|
455 | + * @return mixed |
|
456 | + */ |
|
457 | + public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
458 | + { |
|
459 | + $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
460 | + $options['class'] = $class; |
|
461 | + |
|
462 | + $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
463 | + |
|
464 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
465 | + } |
|
466 | + |
|
467 | + //-------------------------------------------------------------------- |
|
468 | + |
|
469 | + /** |
|
470 | + * Helper method to render out our buttons in a DRY manner. |
|
471 | + * |
|
472 | + * @param $title |
|
473 | + * @param $style |
|
474 | + * @param $size |
|
475 | + * @param $tag |
|
476 | + */ |
|
477 | + protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
478 | + { |
|
479 | + $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
480 | + $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
481 | + |
|
482 | + if (! in_array($style, $valid_styles)) |
|
483 | + { |
|
484 | + $style = 'default'; |
|
485 | + $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
486 | + } |
|
487 | + |
|
488 | + $classes = 'btn '; |
|
489 | + |
|
490 | + // Sizes |
|
491 | + switch($size) |
|
492 | + { |
|
493 | + case 'small': |
|
494 | + $classes .= 'small '; |
|
495 | + break; |
|
496 | + case 'xsmall': |
|
497 | + $classes .= 'tiny '; |
|
498 | + break; |
|
499 | + case 'large': |
|
500 | + $classes .= 'large '; |
|
501 | + break; |
|
502 | + default: |
|
503 | + break; |
|
504 | + } |
|
505 | + |
|
506 | + // Styles |
|
507 | + switch ($style) |
|
508 | + { |
|
509 | + case 'primary': |
|
510 | + $classes .= ''; |
|
511 | + break; |
|
512 | + case 'success': |
|
513 | + $classes .= 'success '; |
|
514 | + break; |
|
515 | + case 'info': |
|
516 | + $classes .= 'secondary '; |
|
517 | + break; |
|
518 | + case 'warning': |
|
519 | + $classes .= 'alert '; |
|
520 | + break; |
|
521 | + case 'danger': |
|
522 | + $classes .= 'alert '; |
|
523 | + break; |
|
524 | + case 'default': |
|
525 | + $classes .= 'secondary '; |
|
526 | + break; |
|
527 | + } |
|
528 | + |
|
529 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
530 | + |
|
531 | + $tag = str_replace('{classes}', $classes, $tag); |
|
532 | + $tag = str_replace('{id}', $id, $tag); |
|
533 | + $tag = str_replace('{attributes}', $attributes, $tag); |
|
534 | + $tag = str_replace('{title}', $title, $tag); |
|
535 | + |
|
536 | + // If we're in a button group we need to wrap each item in li tags. |
|
537 | + if (isset($this->states['inButtonGroup'])) |
|
538 | + { |
|
539 | + $tag = '<li>'. $tag .'</li>'; |
|
540 | + } |
|
541 | + return $tag; |
|
542 | + } |
|
543 | + |
|
544 | + //-------------------------------------------------------------------- |
|
545 | + |
|
546 | + /** |
|
547 | + * Creates button groups wrapping HTML. |
|
548 | + * |
|
549 | + * @param $options |
|
550 | + * @param callable $c |
|
551 | + * @return mixed |
|
552 | + */ |
|
553 | + public function buttonGroup($options, \Closure $c) |
|
554 | + { |
|
555 | + $this->states['inButtonGroup'] = true; |
|
556 | + |
|
557 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-group', true); |
|
558 | + |
|
559 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
560 | + |
|
561 | + $output .= $this->runClosure($c); |
|
562 | + |
|
563 | + $output .= "</ul>\n"; |
|
564 | + |
|
565 | + unset($this->states['inButtonGroup']); |
|
566 | + |
|
567 | + return $output; |
|
568 | + } |
|
569 | + |
|
570 | + //-------------------------------------------------------------------- |
|
571 | + |
|
572 | + /** |
|
573 | + * Creates the button bar wrapping HTML. |
|
574 | + * |
|
575 | + * @param $options |
|
576 | + * @param callable $c |
|
577 | + * @return mixed |
|
578 | + */ |
|
579 | + public function buttonBar($options, \Closure $c) |
|
580 | + { |
|
581 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-bar', true); |
|
582 | + |
|
583 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
584 | + |
|
585 | + $output .= $this->runClosure($c); |
|
586 | + |
|
587 | + $output .= "</div>\n"; |
|
588 | + |
|
589 | + return $output; |
|
590 | + } |
|
591 | + |
|
592 | + //-------------------------------------------------------------------- |
|
593 | + |
|
594 | + /** |
|
595 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
596 | + * by some frameworks. |
|
597 | + * |
|
598 | + * @param $title |
|
599 | + * @param string $style |
|
600 | + * @param string $size |
|
601 | + * @param array $options |
|
602 | + * @param callable $c |
|
603 | + * @return mixed |
|
604 | + */ |
|
605 | + public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
606 | + { |
|
607 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
|
608 | + |
|
609 | + $output = "<a href='#' {$classes} {$id} {$attributes}>{$title} <span data-dropdown='drop'></span></a><br>\n |
|
610 | 610 | <ul id='drop' class='f-dropdown' data-dropdown-content>\n"; |
611 | 611 | |
612 | - $output .= $this->runClosure($c); |
|
613 | - |
|
614 | - $output .= "</ul>\n"; |
|
615 | - |
|
616 | - return $output; |
|
617 | - } |
|
618 | - |
|
619 | - //-------------------------------------------------------------------- |
|
620 | - |
|
621 | - //-------------------------------------------------------------------- |
|
622 | - // Notices |
|
623 | - //-------------------------------------------------------------------- |
|
624 | - |
|
625 | - /** |
|
626 | - * Creates an 'alert-box' style of notice grid. |
|
627 | - * |
|
628 | - * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
629 | - * |
|
630 | - * @param $content |
|
631 | - * @param string $style |
|
632 | - * @param bool $closable |
|
633 | - * @return mixed |
|
634 | - */ |
|
635 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
636 | - { |
|
637 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
|
638 | - |
|
639 | - // Styles |
|
640 | - switch ($style) |
|
641 | - { |
|
642 | - case 'success': |
|
643 | - $classes .= ' success '; |
|
644 | - break; |
|
645 | - case 'info': |
|
646 | - $classes .= ' secondary '; |
|
647 | - break; |
|
648 | - case 'warning': |
|
649 | - $classes .= ' alert '; |
|
650 | - break; |
|
651 | - case 'danger': |
|
652 | - $classes .= ' alert '; |
|
653 | - break; |
|
654 | - case 'default': |
|
655 | - $classes .= ' secondary '; |
|
656 | - break; |
|
657 | - } |
|
658 | - |
|
659 | - $output = "<div data-alert class='{$classes}'>\n"; |
|
660 | - |
|
661 | - $output .= "\t$content\n"; |
|
662 | - |
|
663 | - if ($closable) |
|
664 | - { |
|
665 | - $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
666 | - } |
|
667 | - |
|
668 | - $output .= "</div>\n"; |
|
669 | - |
|
670 | - return $output; |
|
671 | - } |
|
672 | - |
|
673 | - //-------------------------------------------------------------------- |
|
612 | + $output .= $this->runClosure($c); |
|
613 | + |
|
614 | + $output .= "</ul>\n"; |
|
615 | + |
|
616 | + return $output; |
|
617 | + } |
|
618 | + |
|
619 | + //-------------------------------------------------------------------- |
|
620 | + |
|
621 | + //-------------------------------------------------------------------- |
|
622 | + // Notices |
|
623 | + //-------------------------------------------------------------------- |
|
624 | + |
|
625 | + /** |
|
626 | + * Creates an 'alert-box' style of notice grid. |
|
627 | + * |
|
628 | + * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
629 | + * |
|
630 | + * @param $content |
|
631 | + * @param string $style |
|
632 | + * @param bool $closable |
|
633 | + * @return mixed |
|
634 | + */ |
|
635 | + public function notice($content, $style='success', $closable=true, $options=[]) |
|
636 | + { |
|
637 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
|
638 | + |
|
639 | + // Styles |
|
640 | + switch ($style) |
|
641 | + { |
|
642 | + case 'success': |
|
643 | + $classes .= ' success '; |
|
644 | + break; |
|
645 | + case 'info': |
|
646 | + $classes .= ' secondary '; |
|
647 | + break; |
|
648 | + case 'warning': |
|
649 | + $classes .= ' alert '; |
|
650 | + break; |
|
651 | + case 'danger': |
|
652 | + $classes .= ' alert '; |
|
653 | + break; |
|
654 | + case 'default': |
|
655 | + $classes .= ' secondary '; |
|
656 | + break; |
|
657 | + } |
|
658 | + |
|
659 | + $output = "<div data-alert class='{$classes}'>\n"; |
|
660 | + |
|
661 | + $output .= "\t$content\n"; |
|
662 | + |
|
663 | + if ($closable) |
|
664 | + { |
|
665 | + $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
666 | + } |
|
667 | + |
|
668 | + $output .= "</div>\n"; |
|
669 | + |
|
670 | + return $output; |
|
671 | + } |
|
672 | + |
|
673 | + //-------------------------------------------------------------------- |
|
674 | 674 | |
675 | 675 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param array $options |
59 | 59 | * @return mixed |
60 | 60 | */ |
61 | - public function row($options=[], \Closure $c) |
|
61 | + public function row($options = [], \Closure $c) |
|
62 | 62 | { |
63 | 63 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
64 | 64 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param array $attributes |
91 | 91 | * @return mixed |
92 | 92 | */ |
93 | - public function column($options=[], \Closure $c) |
|
93 | + public function column($options = [], \Closure $c) |
|
94 | 94 | { |
95 | 95 | // Build our classes |
96 | 96 | $classes = ''; |
@@ -100,33 +100,33 @@ discard block |
||
100 | 100 | switch ($size) |
101 | 101 | { |
102 | 102 | case 's': |
103 | - $classes .= ' small-'. $value; |
|
103 | + $classes .= ' small-'.$value; |
|
104 | 104 | break; |
105 | 105 | case 'm': |
106 | - $classes .= ' medium-'. $value; |
|
106 | + $classes .= ' medium-'.$value; |
|
107 | 107 | break; |
108 | 108 | case 'l': |
109 | - $classes .= ' large-'. $value; |
|
109 | + $classes .= ' large-'.$value; |
|
110 | 110 | break; |
111 | 111 | case 'xl': |
112 | - $classes .= ' large-'. $value; |
|
112 | + $classes .= ' large-'.$value; |
|
113 | 113 | break; |
114 | 114 | case 's-offset': |
115 | - $classes .= ' small-offset-'. $value; |
|
115 | + $classes .= ' small-offset-'.$value; |
|
116 | 116 | break; |
117 | 117 | case 'm-offset': |
118 | - $classes .= ' medium-offset-'. $value; |
|
118 | + $classes .= ' medium-offset-'.$value; |
|
119 | 119 | break; |
120 | 120 | case 'l-offset': |
121 | - $classes .= ' large-offset-'. $value; |
|
121 | + $classes .= ' large-offset-'.$value; |
|
122 | 122 | break; |
123 | 123 | case 'xl-offset': |
124 | - $classes .= ' large-offset-'. $value; |
|
124 | + $classes .= ' large-offset-'.$value; |
|
125 | 125 | break; |
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
129 | - $classes = $this->buildClassString($classes .' columns', $options, true); |
|
129 | + $classes = $this->buildClassString($classes.' columns', $options, true); |
|
130 | 130 | |
131 | 131 | $id = $this->buildIdFromOptions($options); |
132 | 132 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param callable $c |
156 | 156 | * @return string |
157 | 157 | */ |
158 | - public function navbar($options=[], \Closure $c) |
|
158 | + public function navbar($options = [], \Closure $c) |
|
159 | 159 | { |
160 | 160 | $output = ''; |
161 | 161 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @param string $url |
206 | 206 | * @return string |
207 | 207 | */ |
208 | - public function navbarTitle($title, $url='#') |
|
208 | + public function navbarTitle($title, $url = '#') |
|
209 | 209 | { |
210 | 210 | return "<ul class='title-area'> |
211 | 211 | <li class='name'> |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | * @param callable $c |
228 | 228 | * @return string |
229 | 229 | */ |
230 | - public function navbarRight($options=[], \Closure $c) |
|
230 | + public function navbarRight($options = [], \Closure $c) |
|
231 | 231 | { |
232 | 232 | $output = ''; |
233 | 233 | |
234 | - if (! isset($this->states['nav-section-open'])) |
|
234 | + if ( ! isset($this->states['nav-section-open'])) |
|
235 | 235 | { |
236 | 236 | $output .= "<section class='top-bar-section'>\n"; |
237 | 237 | $this->states['nav-section-open'] = true; |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | * @param callable $c |
267 | 267 | * @return string |
268 | 268 | */ |
269 | - public function navbarLeft($options=[], \Closure $c) |
|
269 | + public function navbarLeft($options = [], \Closure $c) |
|
270 | 270 | { |
271 | 271 | $output = ''; |
272 | 272 | |
273 | - if (! isset($this->states['nav-section-open'])) |
|
273 | + if ( ! isset($this->states['nav-section-open'])) |
|
274 | 274 | { |
275 | 275 | $output .= "<section class='top-bar-section'>\n"; |
276 | 276 | $this->states['nav-section-open'] = true; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param array $options |
312 | 312 | * @return string |
313 | 313 | */ |
314 | - public function navItem($title, $url='#', $options=[], $active=false) |
|
314 | + public function navItem($title, $url = '#', $options = [], $active = false) |
|
315 | 315 | { |
316 | 316 | $options['active'] = $active; |
317 | 317 | |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @param array $options |
334 | 334 | * @param callable $c |
335 | 335 | */ |
336 | - public function navDropdown($title,$options=[], \Closure $c) |
|
336 | + public function navDropdown($title, $options = [], \Closure $c) |
|
337 | 337 | { |
338 | 338 | $classes = $this->buildClassString('has-dropdown', $options, true); |
339 | 339 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | |
367 | 367 | //-------------------------------------------------------------------- |
368 | 368 | |
369 | - public function sideNav($options=[], \Closure $c) |
|
369 | + public function sideNav($options = [], \Closure $c) |
|
370 | 370 | { |
371 | 371 | $classes = $this->buildClassString('side-nav', $options, true); |
372 | 372 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @param callable $c |
393 | 393 | * @return mixed |
394 | 394 | */ |
395 | - public function breadcrumb($options=[], \Closure $c) |
|
395 | + public function breadcrumb($options = [], \Closure $c) |
|
396 | 396 | { |
397 | 397 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
398 | 398 | |
@@ -433,9 +433,9 @@ discard block |
||
433 | 433 | * @param array $options |
434 | 434 | * @return mixed |
435 | 435 | */ |
436 | - public function button($title, $style='default', $size='default', $options=[]) |
|
436 | + public function button($title, $style = 'default', $size = 'default', $options = []) |
|
437 | 437 | { |
438 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
438 | + $tag = "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
439 | 439 | |
440 | 440 | return $this->renderButtonElement($title, $style, $size, $options, $tag); |
441 | 441 | } |
@@ -454,9 +454,9 @@ discard block |
||
454 | 454 | * @param array $options |
455 | 455 | * @return mixed |
456 | 456 | */ |
457 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
457 | + public function buttonLink($title, $url = '#', $style = 'default', $size = 'default', $options = []) |
|
458 | 458 | { |
459 | - $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
459 | + $class = isset($options['class']) ? $options['class'].' button' : 'button'; |
|
460 | 460 | $options['class'] = $class; |
461 | 461 | |
462 | 462 | $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
480 | 480 | $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
481 | 481 | |
482 | - if (! in_array($style, $valid_styles)) |
|
482 | + if ( ! in_array($style, $valid_styles)) |
|
483 | 483 | { |
484 | 484 | $style = 'default'; |
485 | 485 | $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | $classes = 'btn '; |
489 | 489 | |
490 | 490 | // Sizes |
491 | - switch($size) |
|
491 | + switch ($size) |
|
492 | 492 | { |
493 | 493 | case 'small': |
494 | 494 | $classes .= 'small '; |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | // If we're in a button group we need to wrap each item in li tags. |
537 | 537 | if (isset($this->states['inButtonGroup'])) |
538 | 538 | { |
539 | - $tag = '<li>'. $tag .'</li>'; |
|
539 | + $tag = '<li>'.$tag.'</li>'; |
|
540 | 540 | } |
541 | 541 | return $tag; |
542 | 542 | } |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | * @param callable $c |
603 | 603 | * @return mixed |
604 | 604 | */ |
605 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
605 | + public function buttonDropdown($title, $style = 'default', $size = 'default', $options = [], \Closure $c) |
|
606 | 606 | { |
607 | 607 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
608 | 608 | |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | * @param bool $closable |
633 | 633 | * @return mixed |
634 | 634 | */ |
635 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
635 | + public function notice($content, $style = 'success', $closable = true, $options = []) |
|
636 | 636 | { |
637 | 637 | list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
638 | 638 |
@@ -57,6 +57,7 @@ discard block |
||
57 | 57 | * Determines if the current version of PHP is equal to or greater than the supplied value |
58 | 58 | * |
59 | 59 | * @param string |
60 | + * @param string $version |
|
60 | 61 | * @return bool TRUE if the current version is $version or higher |
61 | 62 | */ |
62 | 63 | function is_php($version) |
@@ -288,6 +289,7 @@ discard block |
||
288 | 289 | * Returns the specified config item |
289 | 290 | * |
290 | 291 | * @param string |
292 | + * @param string $item |
|
291 | 293 | * @return mixed |
292 | 294 | */ |
293 | 295 | function config_item($item) |
@@ -463,6 +465,7 @@ discard block |
||
463 | 465 | * |
464 | 466 | * @param string the error level: 'error', 'debug' or 'info' |
465 | 467 | * @param string the error message |
468 | + * @param string $level |
|
466 | 469 | * @return void |
467 | 470 | */ |
468 | 471 | function log_message($level, $message) |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | if (empty($_config)) |
298 | 298 | { |
299 | 299 | // references cannot be directly assigned to static variables, so we use an array |
300 | - $_config[0] =& get_config(); |
|
300 | + $_config[0] = & get_config(); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | return isset($_config[0][$item]) ? $_config[0][$item] : NULL; |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | $exit_status = 1; // EXIT_ERROR |
423 | 423 | } |
424 | 424 | |
425 | - $_error =& load_class('Exceptions', 'core'); |
|
425 | + $_error = & load_class('Exceptions', 'core'); |
|
426 | 426 | echo $_error->show_error($heading, $message, 'error_general', $status_code); |
427 | 427 | exit($exit_status); |
428 | 428 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | */ |
446 | 446 | function show_404($page = '', $log_error = TRUE) |
447 | 447 | { |
448 | - $_error =& load_class('Exceptions', 'core'); |
|
448 | + $_error = & load_class('Exceptions', 'core'); |
|
449 | 449 | $_error->show_404($page, $log_error); |
450 | 450 | exit(4); // EXIT_UNKNOWN_FILE |
451 | 451 | } |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | if ($_log === NULL) |
473 | 473 | { |
474 | 474 | // references cannot be directly assigned to static variables, so we use an array |
475 | - $_log[0] =& load_class('Log', 'core'); |
|
475 | + $_log[0] = & load_class('Log', 'core'); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | $_log[0]->write_log($level, $message); |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | return; |
619 | 619 | } |
620 | 620 | |
621 | - $_error =& load_class('Exceptions', 'core'); |
|
621 | + $_error = & load_class('Exceptions', 'core'); |
|
622 | 622 | $_error->log_exception($severity, $message, $filepath, $line); |
623 | 623 | |
624 | 624 | // Should we display the error? |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | */ |
654 | 654 | function _exception_handler($exception) |
655 | 655 | { |
656 | - $_error =& load_class('Exceptions', 'core'); |
|
656 | + $_error = & load_class('Exceptions', 'core'); |
|
657 | 657 | $_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine()); |
658 | 658 | |
659 | 659 | // Should we display the error? |
@@ -716,11 +716,11 @@ discard block |
||
716 | 716 | // carriage return (dec 13) and horizontal tab (dec 09) |
717 | 717 | if ($url_encoded) |
718 | 718 | { |
719 | - $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 |
|
720 | - $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 |
|
719 | + $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 |
|
720 | + $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 |
|
721 | 721 | } |
722 | 722 | |
723 | - $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 |
|
723 | + $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 |
|
724 | 724 | |
725 | 725 | do |
726 | 726 | { |
@@ -111,8 +111,7 @@ discard block |
||
111 | 111 | @chmod($file, 0777); |
112 | 112 | @unlink($file); |
113 | 113 | return TRUE; |
114 | - } |
|
115 | - elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE) |
|
114 | + } elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE) |
|
116 | 115 | { |
117 | 116 | return FALSE; |
118 | 117 | } |
@@ -253,8 +252,7 @@ discard block |
||
253 | 252 | if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) |
254 | 253 | { |
255 | 254 | require($file_path); |
256 | - } |
|
257 | - elseif ( ! $found) |
|
255 | + } elseif ( ! $found) |
|
258 | 256 | { |
259 | 257 | set_status_header(503); |
260 | 258 | echo 'The configuration file does not exist.'; |
@@ -322,12 +320,10 @@ discard block |
||
322 | 320 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) |
323 | 321 | { |
324 | 322 | $_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); |
325 | - } |
|
326 | - elseif (file_exists(APPPATH.'config/mimes.php')) |
|
323 | + } elseif (file_exists(APPPATH.'config/mimes.php')) |
|
327 | 324 | { |
328 | 325 | $_mimes = include(APPPATH.'config/mimes.php'); |
329 | - } |
|
330 | - else |
|
326 | + } else |
|
331 | 327 | { |
332 | 328 | $_mimes = array(); |
333 | 329 | } |
@@ -354,12 +350,10 @@ discard block |
||
354 | 350 | if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') |
355 | 351 | { |
356 | 352 | return TRUE; |
357 | - } |
|
358 | - elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') |
|
353 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') |
|
359 | 354 | { |
360 | 355 | return TRUE; |
361 | - } |
|
362 | - elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') |
|
356 | + } elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') |
|
363 | 357 | { |
364 | 358 | return TRUE; |
365 | 359 | } |
@@ -410,14 +404,16 @@ discard block |
||
410 | 404 | if ($status_code < 100) |
411 | 405 | { |
412 | 406 | $exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN |
413 | - if ($exit_status > 125) // 125 is EXIT__AUTO_MAX |
|
407 | + if ($exit_status > 125) { |
|
408 | + // 125 is EXIT__AUTO_MAX |
|
414 | 409 | { |
415 | - $exit_status = 1; // EXIT_ERROR |
|
410 | + $exit_status = 1; |
|
411 | + } |
|
412 | + // EXIT_ERROR |
|
416 | 413 | } |
417 | 414 | |
418 | 415 | $status_code = 500; |
419 | - } |
|
420 | - else |
|
416 | + } else |
|
421 | 417 | { |
422 | 418 | $exit_status = 1; // EXIT_ERROR |
423 | 419 | } |
@@ -556,8 +552,7 @@ discard block |
||
556 | 552 | if (isset($stati[$code])) |
557 | 553 | { |
558 | 554 | $text = $stati[$code]; |
559 | - } |
|
560 | - else |
|
555 | + } else |
|
561 | 556 | { |
562 | 557 | show_error('No status text available. Please check your status code number or supply your own message text.', 500); |
563 | 558 | } |
@@ -566,8 +561,7 @@ discard block |
||
566 | 561 | if (strpos(PHP_SAPI, 'cgi') === 0) |
567 | 562 | { |
568 | 563 | header('Status: '.$code.' '.$text, TRUE); |
569 | - } |
|
570 | - else |
|
564 | + } else |
|
571 | 565 | { |
572 | 566 | $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
573 | 567 | header($server_protocol.' '.$code.' '.$text, TRUE, $code); |
@@ -121,7 +121,7 @@ |
||
121 | 121 | * @param string $file Configuration file name |
122 | 122 | * @param bool $use_sections Whether configuration values should be loaded into their own section |
123 | 123 | * @param bool $fail_gracefully Whether to just return FALSE or display an error message |
124 | - * @return bool TRUE if the file was loaded correctly or FALSE on failure |
|
124 | + * @return boolean|null TRUE if the file was loaded correctly or FALSE on failure |
|
125 | 125 | */ |
126 | 126 | public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) |
127 | 127 | { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @var array |
64 | 64 | */ |
65 | - public $is_loaded = array(); |
|
65 | + public $is_loaded = array(); |
|
66 | 66 | |
67 | 67 | /** |
68 | 68 | * List of paths to search when trying to load a config file. |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @used-by CI_Loader |
71 | 71 | * @var array |
72 | 72 | */ |
73 | - public $_config_paths = array(APPPATH); |
|
73 | + public $_config_paths = array(APPPATH); |
|
74 | 74 | |
75 | 75 | // -------------------------------------------------------------------- |
76 | 76 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function __construct() |
85 | 85 | { |
86 | - $this->config =& get_config(); |
|
86 | + $this->config = & get_config(); |
|
87 | 87 | |
88 | 88 | // Set the base_url automatically if none was provided |
89 | 89 | if (empty($this->config['base_url'])) |
@@ -93,16 +93,14 @@ discard block |
||
93 | 93 | if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) |
94 | 94 | { |
95 | 95 | $server_addr = '['.$_SERVER['SERVER_ADDR'].']'; |
96 | - } |
|
97 | - else |
|
96 | + } else |
|
98 | 97 | { |
99 | 98 | $server_addr = $_SERVER['SERVER_ADDR']; |
100 | 99 | } |
101 | 100 | |
102 | 101 | $base_url = (is_https() ? 'https' : 'http').'://'.$server_addr |
103 | 102 | .substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
104 | - } |
|
105 | - else |
|
103 | + } else |
|
106 | 104 | { |
107 | 105 | $base_url = 'http://localhost/'; |
108 | 106 | } |
@@ -160,8 +158,7 @@ discard block |
||
160 | 158 | $this->config[$file] = isset($this->config[$file]) |
161 | 159 | ? array_merge($this->config[$file], $config) |
162 | 160 | : $config; |
163 | - } |
|
164 | - else |
|
161 | + } else |
|
165 | 162 | { |
166 | 163 | $this->config = array_merge($this->config, $config); |
167 | 164 | } |
@@ -176,8 +173,7 @@ discard block |
||
176 | 173 | if ($loaded === TRUE) |
177 | 174 | { |
178 | 175 | return TRUE; |
179 | - } |
|
180 | - elseif ($fail_gracefully === TRUE) |
|
176 | + } elseif ($fail_gracefully === TRUE) |
|
181 | 177 | { |
182 | 178 | return FALSE; |
183 | 179 | } |
@@ -217,8 +213,7 @@ discard block |
||
217 | 213 | if ( ! isset($this->config[$item])) |
218 | 214 | { |
219 | 215 | return NULL; |
220 | - } |
|
221 | - elseif (trim($this->config[$item]) === '') |
|
216 | + } elseif (trim($this->config[$item]) === '') |
|
222 | 217 | { |
223 | 218 | return ''; |
224 | 219 | } |
@@ -249,8 +244,7 @@ discard block |
||
249 | 244 | if ($protocol === '') |
250 | 245 | { |
251 | 246 | $base_url = substr($base_url, strpos($base_url, '//')); |
252 | - } |
|
253 | - else |
|
247 | + } else |
|
254 | 248 | { |
255 | 249 | $base_url = $protocol.substr($base_url, strpos($base_url, '://')); |
256 | 250 | } |
@@ -272,16 +266,14 @@ discard block |
||
272 | 266 | if (($offset = strpos($uri, '?')) !== FALSE) |
273 | 267 | { |
274 | 268 | $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset); |
275 | - } |
|
276 | - else |
|
269 | + } else |
|
277 | 270 | { |
278 | 271 | $uri .= $suffix; |
279 | 272 | } |
280 | 273 | } |
281 | 274 | |
282 | 275 | return $base_url.$this->slash_item('index_page').$uri; |
283 | - } |
|
284 | - elseif (strpos($uri, '?') === FALSE) |
|
276 | + } elseif (strpos($uri, '?') === FALSE) |
|
285 | 277 | { |
286 | 278 | $uri = '?'.$uri; |
287 | 279 | } |
@@ -312,8 +304,7 @@ discard block |
||
312 | 304 | if ($protocol === '') |
313 | 305 | { |
314 | 306 | $base_url = substr($base_url, strpos($base_url, '//')); |
315 | - } |
|
316 | - else |
|
307 | + } else |
|
317 | 308 | { |
318 | 309 | $base_url = $protocol.substr($base_url, strpos($base_url, '://')); |
319 | 310 | } |
@@ -342,8 +333,7 @@ discard block |
||
342 | 333 | $uri = implode('/', $uri); |
343 | 334 | } |
344 | 335 | return trim($uri, '/'); |
345 | - } |
|
346 | - elseif (is_array($uri)) |
|
336 | + } elseif (is_array($uri)) |
|
347 | 337 | { |
348 | 338 | return http_build_query($uri); |
349 | 339 | } |