@@ -185,7 +185,7 @@ |
||
185 | 185 | elseif ( ! class_exists('CI_DB', FALSE)) |
186 | 186 | { |
187 | 187 | /** |
188 | - * @ignore |
|
188 | + * @ignore |
|
189 | 189 | */ |
190 | 190 | class CI_DB extends CI_DB_driver { } |
191 | 191 | } |
@@ -32,40 +32,40 @@ |
||
32 | 32 | |
33 | 33 | interface DocSearchInterface { |
34 | 34 | |
35 | - /** |
|
36 | - * The entry point for performing a search of the documentation. |
|
37 | - * |
|
38 | - * @param null $terms |
|
39 | - * @param array $folders |
|
40 | - * |
|
41 | - * @return array|null |
|
42 | - */ |
|
43 | - public function search($terms = null, $folders = []); |
|
35 | + /** |
|
36 | + * The entry point for performing a search of the documentation. |
|
37 | + * |
|
38 | + * @param null $terms |
|
39 | + * @param array $folders |
|
40 | + * |
|
41 | + * @return array|null |
|
42 | + */ |
|
43 | + public function search($terms = null, $folders = []); |
|
44 | 44 | |
45 | - //-------------------------------------------------------------------- |
|
45 | + //-------------------------------------------------------------------- |
|
46 | 46 | |
47 | - /** |
|
48 | - * Stores the name of the callback method to run to convert the source |
|
49 | - * files to viewable files. By default, this should be used to register |
|
50 | - * a Mardown Extended formatter with the system, but could be used to |
|
51 | - * extend the |
|
52 | - * |
|
53 | - * @param string $callback_name |
|
54 | - * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
55 | - * @return $this |
|
56 | - */ |
|
57 | - public function registerFormatter($callback_name='', $cascade=false); |
|
47 | + /** |
|
48 | + * Stores the name of the callback method to run to convert the source |
|
49 | + * files to viewable files. By default, this should be used to register |
|
50 | + * a Mardown Extended formatter with the system, but could be used to |
|
51 | + * extend the |
|
52 | + * |
|
53 | + * @param string $callback_name |
|
54 | + * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
55 | + * @return $this |
|
56 | + */ |
|
57 | + public function registerFormatter($callback_name='', $cascade=false); |
|
58 | 58 | |
59 | - //-------------------------------------------------------------------- |
|
59 | + //-------------------------------------------------------------------- |
|
60 | 60 | |
61 | - /** |
|
62 | - * Runs the text through the registered formatters. |
|
63 | - * |
|
64 | - * @param $str |
|
65 | - * @return mixed |
|
66 | - */ |
|
67 | - public function format($str); |
|
61 | + /** |
|
62 | + * Runs the text through the registered formatters. |
|
63 | + * |
|
64 | + * @param $str |
|
65 | + * @return mixed |
|
66 | + */ |
|
67 | + public function format($str); |
|
68 | 68 | |
69 | - //-------------------------------------------------------------------- |
|
69 | + //-------------------------------------------------------------------- |
|
70 | 70 | |
71 | 71 | } |
@@ -30,506 +30,506 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class CLI { |
32 | 32 | |
33 | - public static $readline_support = false; |
|
33 | + public static $readline_support = false; |
|
34 | 34 | |
35 | - public static $wait_msg = 'Press any key to continue...'; |
|
35 | + public static $wait_msg = 'Press any key to continue...'; |
|
36 | 36 | |
37 | - public static $segments = []; |
|
37 | + public static $segments = []; |
|
38 | 38 | |
39 | 39 | protected static $options = []; |
40 | 40 | |
41 | 41 | protected static $initialized = false; |
42 | 42 | |
43 | - // Used by progress bar |
|
44 | - protected static $inProgress = false; |
|
45 | - |
|
46 | - protected static $foreground_colors = array( |
|
47 | - 'black' => '0;30', |
|
48 | - 'dark_gray' => '1;30', |
|
49 | - 'blue' => '0;34', |
|
50 | - 'dark_blue' => '1;34', |
|
51 | - 'light_blue' => '1;34', |
|
52 | - 'green' => '0;32', |
|
53 | - 'light_green' => '1;32', |
|
54 | - 'cyan' => '0;36', |
|
55 | - 'light_cyan' => '1;36', |
|
56 | - 'red' => '0;31', |
|
57 | - 'light_red' => '1;31', |
|
58 | - 'purple' => '0;35', |
|
59 | - 'light_purple' => '1;35', |
|
60 | - 'light_yellow' => '0;33', |
|
61 | - 'yellow' => '1;33', |
|
62 | - 'light_gray' => '0;37', |
|
63 | - 'white' => '1;37', |
|
64 | - ); |
|
65 | - |
|
66 | - protected static $background_colors = array( |
|
67 | - 'black' => '40', |
|
68 | - 'red' => '41', |
|
69 | - 'green' => '42', |
|
70 | - 'yellow' => '43', |
|
71 | - 'blue' => '44', |
|
72 | - 'magenta' => '45', |
|
73 | - 'cyan' => '46', |
|
74 | - 'light_gray' => '47', |
|
75 | - ); |
|
76 | - |
|
77 | - //-------------------------------------------------------------------- |
|
78 | - |
|
79 | - /** |
|
80 | - * Static constructor. Parses all the CLI params. |
|
81 | - */ |
|
82 | - public static function _init() |
|
83 | - { |
|
84 | - if (static::$initialized === true) |
|
85 | - { |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - if ( ! (PHP_SAPI === 'cli' || defined('STDIN')) ) |
|
90 | - { |
|
91 | - throw new \Exception('Cli class cannot be used outside of the command line.'); |
|
92 | - } |
|
93 | - |
|
94 | - self::parseCommand(); |
|
95 | - |
|
96 | - // Readline is an extension for PHP that makes interactive with PHP much more bash-like |
|
97 | - // http://www.php.net/manual/en/readline.installation.php |
|
98 | - static::$readline_support = extension_loaded('readline'); |
|
99 | - |
|
100 | - static::$initialized = true; |
|
101 | - } |
|
102 | - |
|
103 | - //-------------------------------------------------------------------- |
|
104 | - |
|
105 | - /** |
|
106 | - * Grabs an individual |
|
107 | - * |
|
108 | - * @param $index |
|
109 | - * @return null |
|
110 | - */ |
|
111 | - public static function segment($index) |
|
112 | - { |
|
113 | - if (! isset(static::$segments[$index - 1])) |
|
114 | - { |
|
115 | - return null; |
|
116 | - } |
|
117 | - |
|
118 | - return static::$segments[$index - 1]; |
|
119 | - } |
|
120 | - |
|
121 | - //-------------------------------------------------------------------- |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns the command string portion of the arguments. Used |
|
125 | - * by the 'sprint' CLI script to grab the portion of the arguments |
|
126 | - * that is used to call the CodeIgniter application. |
|
127 | - * |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public static function cli_string() |
|
131 | - { |
|
132 | - return implode(' ', static::$segments); |
|
133 | - } |
|
134 | - |
|
135 | - //-------------------------------------------------------------------- |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Get input from the shell, using readline or the standard STDIN |
|
141 | - * |
|
142 | - * Named options must be in the following formats: |
|
143 | - * php index.php user -v --v -name=John --name=John |
|
144 | - * |
|
145 | - * @param string|int $name the name of the option (int if unnamed) |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public static function input($prefix = '') |
|
149 | - { |
|
150 | - if (static::$readline_support) |
|
151 | - { |
|
152 | - return readline($prefix); |
|
153 | - } |
|
154 | - |
|
155 | - echo $prefix; |
|
156 | - return fgets(STDIN); |
|
157 | - } |
|
158 | - |
|
159 | - //-------------------------------------------------------------------- |
|
160 | - |
|
161 | - /** |
|
162 | - * Asks the user for input. This can have either 1 or 2 arguments. |
|
163 | - * |
|
164 | - * Usage: |
|
165 | - * |
|
166 | - * // Waits for any key press |
|
167 | - * CLI::prompt(); |
|
168 | - * |
|
169 | - * // Takes any input |
|
170 | - * $color = CLI::prompt('What is your favorite color?'); |
|
171 | - * |
|
172 | - * // Takes any input, but offers default |
|
173 | - * $color = CLI::prompt('What is your favourite color?', 'white'); |
|
174 | - * |
|
175 | - * // Will only accept the options in the array |
|
176 | - * $ready = CLI::prompt('Are you ready?', array('y','n')); |
|
177 | - * |
|
178 | - * @return string the user input |
|
179 | - */ |
|
180 | - public static function prompt() |
|
181 | - { |
|
182 | - $args = func_get_args(); |
|
183 | - |
|
184 | - $options = array(); |
|
185 | - $output = ''; |
|
186 | - $default = null; |
|
187 | - |
|
188 | - // How many we got |
|
189 | - $arg_count = count($args); |
|
190 | - |
|
191 | - // Is the last argument a boolean? True means required |
|
192 | - $required = end($args) === true; |
|
193 | - |
|
194 | - // Reduce the argument count if required was passed, we don't care about that anymore |
|
195 | - $required === true and --$arg_count; |
|
196 | - |
|
197 | - // This method can take a few crazy combinations of arguments, so lets work it out |
|
198 | - switch ($arg_count) |
|
199 | - { |
|
200 | - case 2: |
|
201 | - |
|
202 | - // E.g: $ready = CLI::prompt('Are you ready?', array('y','n')); |
|
203 | - if (is_array($args[1])) |
|
204 | - { |
|
205 | - list($output, $options)=$args; |
|
206 | - } |
|
207 | - |
|
208 | - // E.g: $color = CLI::prompt('What is your favourite color?', 'white'); |
|
209 | - elseif (is_string($args[1])) |
|
210 | - { |
|
211 | - list($output, $default)=$args; |
|
212 | - } |
|
213 | - |
|
214 | - break; |
|
215 | - |
|
216 | - case 1: |
|
217 | - |
|
218 | - // No question (probably been asked already) so just show options |
|
219 | - // E.g: $ready = CLI::prompt(array('y','n')); |
|
220 | - if (is_array($args[0])) |
|
221 | - { |
|
222 | - $options = $args[0]; |
|
223 | - } |
|
224 | - |
|
225 | - // Question without options |
|
226 | - // E.g: $ready = CLI::prompt('What did you do today?'); |
|
227 | - elseif (is_string($args[0])) |
|
228 | - { |
|
229 | - $output = $args[0]; |
|
230 | - } |
|
231 | - |
|
232 | - break; |
|
233 | - } |
|
234 | - |
|
235 | - // If a question has been asked with the read |
|
236 | - if ($output !== '') |
|
237 | - { |
|
238 | - $extra_output = ''; |
|
239 | - |
|
240 | - if ($default !== null) |
|
241 | - { |
|
242 | - $extra_output = ' [ Default: "'.$default.'" ]'; |
|
243 | - } |
|
244 | - |
|
245 | - elseif ($options !== array()) |
|
246 | - { |
|
247 | - $extra_output = ' [ '.implode(', ', $options).' ]'; |
|
248 | - } |
|
249 | - |
|
250 | - fwrite(STDOUT, $output.$extra_output.': '); |
|
251 | - } |
|
252 | - |
|
253 | - // Read the input from keyboard. |
|
254 | - $input = trim(static::input()) ?: $default; |
|
255 | - |
|
256 | - // No input provided and we require one (default will stop this being called) |
|
257 | - if (empty($input) and $required === true) |
|
258 | - { |
|
259 | - static::write('This is required.'); |
|
260 | - static::new_line(); |
|
261 | - |
|
262 | - $input = forward_static_call_array(array(__CLASS__, 'prompt'), $args); |
|
263 | - } |
|
264 | - |
|
265 | - // If options are provided and the choice is not in the array, tell them to try again |
|
266 | - if ( ! empty($options) and ! in_array($input, $options)) |
|
267 | - { |
|
268 | - static::write('This is not a valid option. Please try again.'); |
|
269 | - static::new_line(); |
|
270 | - |
|
271 | - $input = forward_static_call_array(array(__CLASS__, 'prompt'), $args); |
|
272 | - } |
|
273 | - |
|
274 | - return $input; |
|
275 | - } |
|
276 | - |
|
277 | - //-------------------------------------------------------------------- |
|
278 | - |
|
279 | - /** |
|
280 | - * Outputs a string to the cli. If you send an array it will implode them |
|
281 | - * with a line break. |
|
282 | - * |
|
283 | - * @param string|array $text the text to output, or array of lines |
|
284 | - */ |
|
285 | - public static function write($text = '', $foreground = null, $background = null) |
|
286 | - { |
|
287 | - if (is_array($text)) |
|
288 | - { |
|
289 | - $text = implode(PHP_EOL, $text); |
|
290 | - } |
|
291 | - |
|
292 | - if ($foreground or $background) |
|
293 | - { |
|
294 | - $text = static::color($text, $foreground, $background); |
|
295 | - } |
|
296 | - |
|
297 | - fwrite(STDOUT, $text.PHP_EOL); |
|
298 | - } |
|
299 | - |
|
300 | - //-------------------------------------------------------------------- |
|
301 | - |
|
302 | - /** |
|
303 | - * Outputs an error to the CLI using STDERR instead of STDOUT |
|
304 | - * |
|
305 | - * @param string|array $text the text to output, or array of errors |
|
306 | - */ |
|
307 | - public static function error($text = '', $foreground = 'light_red', $background = null) |
|
308 | - { |
|
309 | - if (is_array($text)) |
|
310 | - { |
|
311 | - $text = implode(PHP_EOL, $text); |
|
312 | - } |
|
313 | - |
|
314 | - if ($foreground OR $background) |
|
315 | - { |
|
316 | - $text = static::color($text, $foreground, $background); |
|
317 | - } |
|
318 | - |
|
319 | - fwrite(STDERR, $text.PHP_EOL); |
|
320 | - } |
|
321 | - |
|
322 | - //-------------------------------------------------------------------- |
|
323 | - |
|
324 | - /** |
|
325 | - * Beeps a certain number of times. |
|
326 | - * |
|
327 | - * @param int $num the number of times to beep |
|
328 | - */ |
|
329 | - public static function beep($num = 1) |
|
330 | - { |
|
331 | - echo str_repeat("\x07", $num); |
|
332 | - } |
|
333 | - |
|
334 | - //-------------------------------------------------------------------- |
|
335 | - |
|
336 | - /** |
|
337 | - * Waits a certain number of seconds, optionally showing a wait message and |
|
338 | - * waiting for a key press. |
|
339 | - * |
|
340 | - * @param int $seconds number of seconds |
|
341 | - * @param bool $countdown show a countdown or not |
|
342 | - */ |
|
343 | - public static function wait($seconds = 0, $countdown = false) |
|
344 | - { |
|
345 | - if ($countdown === true) |
|
346 | - { |
|
347 | - $time = $seconds; |
|
348 | - |
|
349 | - while ($time > 0) |
|
350 | - { |
|
351 | - fwrite(STDOUT, $time.'... '); |
|
352 | - sleep(1); |
|
353 | - $time--; |
|
354 | - } |
|
355 | - static::write(); |
|
356 | - } |
|
357 | - |
|
358 | - else |
|
359 | - { |
|
360 | - if ($seconds > 0) |
|
361 | - { |
|
362 | - sleep($seconds); |
|
363 | - } |
|
364 | - else |
|
365 | - { |
|
366 | - static::write(static::$wait_msg); |
|
367 | - static::input(); |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - //-------------------------------------------------------------------- |
|
374 | - |
|
375 | - /** |
|
376 | - * if operating system === windows |
|
377 | - */ |
|
378 | - public static function is_windows() |
|
379 | - { |
|
380 | - return 'win' === strtolower(substr(php_uname("s"), 0, 3)); |
|
381 | - } |
|
382 | - |
|
383 | - //-------------------------------------------------------------------- |
|
384 | - |
|
385 | - /** |
|
386 | - * Enter a number of empty lines |
|
387 | - * |
|
388 | - * @param integer Number of lines to output |
|
389 | - * @return void |
|
390 | - */ |
|
391 | - public static function new_line($num = 1) |
|
392 | - { |
|
393 | - // Do it once or more, write with empty string gives us a new line |
|
394 | - for($i = 0; $i < $num; $i++) |
|
395 | - { |
|
396 | - static::write(); |
|
397 | - } |
|
398 | - } |
|
399 | - |
|
400 | - //-------------------------------------------------------------------- |
|
401 | - |
|
402 | - /** |
|
403 | - * Clears the screen of output |
|
404 | - * |
|
405 | - * @return void |
|
406 | - */ |
|
407 | - public static function clear_screen() |
|
408 | - { |
|
409 | - static::is_windows() |
|
410 | - |
|
411 | - // Windows is a bit crap at this, but their terminal is tiny so shove this in |
|
412 | - ? static::new_line(40) |
|
413 | - |
|
414 | - // Anything with a flair of Unix will handle these magic characters |
|
415 | - : fwrite(STDOUT, chr(27)."[H".chr(27)."[2J"); |
|
416 | - } |
|
417 | - |
|
418 | - //-------------------------------------------------------------------- |
|
419 | - |
|
420 | - /** |
|
421 | - * Returns the given text with the correct color codes for a foreground and |
|
422 | - * optionally a background color. |
|
423 | - * |
|
424 | - * @param string $text the text to color |
|
425 | - * @param string $foreground the foreground color |
|
426 | - * @param string $background the background color |
|
427 | - * @param string $format other formatting to apply. Currently only 'underline' is understood |
|
428 | - * @return string the color coded string |
|
429 | - */ |
|
430 | - public static function color($text, $foreground, $background = null, $format=null) |
|
431 | - { |
|
432 | - if (static::is_windows() and ! isset($_SERVER['ANSICON'])) |
|
433 | - { |
|
434 | - return $text; |
|
435 | - } |
|
436 | - |
|
437 | - if ( ! array_key_exists($foreground, static::$foreground_colors)) |
|
438 | - { |
|
439 | - throw new \RuntimeException('Invalid CLI foreground color: '.$foreground); |
|
440 | - } |
|
441 | - |
|
442 | - if ( $background !== null and ! array_key_exists($background, static::$background_colors)) |
|
443 | - { |
|
444 | - throw new \RuntimeException('Invalid CLI background color: '.$background); |
|
445 | - } |
|
446 | - |
|
447 | - $string = "\033[".static::$foreground_colors[$foreground]."m"; |
|
448 | - |
|
449 | - if ($background !== null) |
|
450 | - { |
|
451 | - $string .= "\033[".static::$background_colors[$background]."m"; |
|
452 | - } |
|
453 | - |
|
454 | - if ($format === 'underline') |
|
455 | - { |
|
456 | - $string .= "\033[4m"; |
|
457 | - } |
|
458 | - |
|
459 | - $string .= $text."\033[0m"; |
|
460 | - |
|
461 | - return $string; |
|
462 | - } |
|
463 | - |
|
464 | - //-------------------------------------------------------------------- |
|
465 | - |
|
466 | - public static function getWidth($default=80) |
|
467 | - { |
|
468 | - if (static::is_windows()) |
|
469 | - { |
|
470 | - return $default; |
|
471 | - } |
|
472 | - |
|
473 | - return (int)shell_exec('tput cols'); |
|
474 | - } |
|
43 | + // Used by progress bar |
|
44 | + protected static $inProgress = false; |
|
45 | + |
|
46 | + protected static $foreground_colors = array( |
|
47 | + 'black' => '0;30', |
|
48 | + 'dark_gray' => '1;30', |
|
49 | + 'blue' => '0;34', |
|
50 | + 'dark_blue' => '1;34', |
|
51 | + 'light_blue' => '1;34', |
|
52 | + 'green' => '0;32', |
|
53 | + 'light_green' => '1;32', |
|
54 | + 'cyan' => '0;36', |
|
55 | + 'light_cyan' => '1;36', |
|
56 | + 'red' => '0;31', |
|
57 | + 'light_red' => '1;31', |
|
58 | + 'purple' => '0;35', |
|
59 | + 'light_purple' => '1;35', |
|
60 | + 'light_yellow' => '0;33', |
|
61 | + 'yellow' => '1;33', |
|
62 | + 'light_gray' => '0;37', |
|
63 | + 'white' => '1;37', |
|
64 | + ); |
|
65 | + |
|
66 | + protected static $background_colors = array( |
|
67 | + 'black' => '40', |
|
68 | + 'red' => '41', |
|
69 | + 'green' => '42', |
|
70 | + 'yellow' => '43', |
|
71 | + 'blue' => '44', |
|
72 | + 'magenta' => '45', |
|
73 | + 'cyan' => '46', |
|
74 | + 'light_gray' => '47', |
|
75 | + ); |
|
76 | + |
|
77 | + //-------------------------------------------------------------------- |
|
78 | + |
|
79 | + /** |
|
80 | + * Static constructor. Parses all the CLI params. |
|
81 | + */ |
|
82 | + public static function _init() |
|
83 | + { |
|
84 | + if (static::$initialized === true) |
|
85 | + { |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + if ( ! (PHP_SAPI === 'cli' || defined('STDIN')) ) |
|
90 | + { |
|
91 | + throw new \Exception('Cli class cannot be used outside of the command line.'); |
|
92 | + } |
|
93 | + |
|
94 | + self::parseCommand(); |
|
95 | + |
|
96 | + // Readline is an extension for PHP that makes interactive with PHP much more bash-like |
|
97 | + // http://www.php.net/manual/en/readline.installation.php |
|
98 | + static::$readline_support = extension_loaded('readline'); |
|
99 | + |
|
100 | + static::$initialized = true; |
|
101 | + } |
|
102 | + |
|
103 | + //-------------------------------------------------------------------- |
|
104 | + |
|
105 | + /** |
|
106 | + * Grabs an individual |
|
107 | + * |
|
108 | + * @param $index |
|
109 | + * @return null |
|
110 | + */ |
|
111 | + public static function segment($index) |
|
112 | + { |
|
113 | + if (! isset(static::$segments[$index - 1])) |
|
114 | + { |
|
115 | + return null; |
|
116 | + } |
|
117 | + |
|
118 | + return static::$segments[$index - 1]; |
|
119 | + } |
|
120 | + |
|
121 | + //-------------------------------------------------------------------- |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns the command string portion of the arguments. Used |
|
125 | + * by the 'sprint' CLI script to grab the portion of the arguments |
|
126 | + * that is used to call the CodeIgniter application. |
|
127 | + * |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public static function cli_string() |
|
131 | + { |
|
132 | + return implode(' ', static::$segments); |
|
133 | + } |
|
134 | + |
|
135 | + //-------------------------------------------------------------------- |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Get input from the shell, using readline or the standard STDIN |
|
141 | + * |
|
142 | + * Named options must be in the following formats: |
|
143 | + * php index.php user -v --v -name=John --name=John |
|
144 | + * |
|
145 | + * @param string|int $name the name of the option (int if unnamed) |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public static function input($prefix = '') |
|
149 | + { |
|
150 | + if (static::$readline_support) |
|
151 | + { |
|
152 | + return readline($prefix); |
|
153 | + } |
|
154 | + |
|
155 | + echo $prefix; |
|
156 | + return fgets(STDIN); |
|
157 | + } |
|
158 | + |
|
159 | + //-------------------------------------------------------------------- |
|
160 | + |
|
161 | + /** |
|
162 | + * Asks the user for input. This can have either 1 or 2 arguments. |
|
163 | + * |
|
164 | + * Usage: |
|
165 | + * |
|
166 | + * // Waits for any key press |
|
167 | + * CLI::prompt(); |
|
168 | + * |
|
169 | + * // Takes any input |
|
170 | + * $color = CLI::prompt('What is your favorite color?'); |
|
171 | + * |
|
172 | + * // Takes any input, but offers default |
|
173 | + * $color = CLI::prompt('What is your favourite color?', 'white'); |
|
174 | + * |
|
175 | + * // Will only accept the options in the array |
|
176 | + * $ready = CLI::prompt('Are you ready?', array('y','n')); |
|
177 | + * |
|
178 | + * @return string the user input |
|
179 | + */ |
|
180 | + public static function prompt() |
|
181 | + { |
|
182 | + $args = func_get_args(); |
|
183 | + |
|
184 | + $options = array(); |
|
185 | + $output = ''; |
|
186 | + $default = null; |
|
187 | + |
|
188 | + // How many we got |
|
189 | + $arg_count = count($args); |
|
190 | + |
|
191 | + // Is the last argument a boolean? True means required |
|
192 | + $required = end($args) === true; |
|
193 | + |
|
194 | + // Reduce the argument count if required was passed, we don't care about that anymore |
|
195 | + $required === true and --$arg_count; |
|
196 | + |
|
197 | + // This method can take a few crazy combinations of arguments, so lets work it out |
|
198 | + switch ($arg_count) |
|
199 | + { |
|
200 | + case 2: |
|
201 | + |
|
202 | + // E.g: $ready = CLI::prompt('Are you ready?', array('y','n')); |
|
203 | + if (is_array($args[1])) |
|
204 | + { |
|
205 | + list($output, $options)=$args; |
|
206 | + } |
|
207 | + |
|
208 | + // E.g: $color = CLI::prompt('What is your favourite color?', 'white'); |
|
209 | + elseif (is_string($args[1])) |
|
210 | + { |
|
211 | + list($output, $default)=$args; |
|
212 | + } |
|
213 | + |
|
214 | + break; |
|
215 | + |
|
216 | + case 1: |
|
217 | + |
|
218 | + // No question (probably been asked already) so just show options |
|
219 | + // E.g: $ready = CLI::prompt(array('y','n')); |
|
220 | + if (is_array($args[0])) |
|
221 | + { |
|
222 | + $options = $args[0]; |
|
223 | + } |
|
224 | + |
|
225 | + // Question without options |
|
226 | + // E.g: $ready = CLI::prompt('What did you do today?'); |
|
227 | + elseif (is_string($args[0])) |
|
228 | + { |
|
229 | + $output = $args[0]; |
|
230 | + } |
|
231 | + |
|
232 | + break; |
|
233 | + } |
|
234 | + |
|
235 | + // If a question has been asked with the read |
|
236 | + if ($output !== '') |
|
237 | + { |
|
238 | + $extra_output = ''; |
|
239 | + |
|
240 | + if ($default !== null) |
|
241 | + { |
|
242 | + $extra_output = ' [ Default: "'.$default.'" ]'; |
|
243 | + } |
|
244 | + |
|
245 | + elseif ($options !== array()) |
|
246 | + { |
|
247 | + $extra_output = ' [ '.implode(', ', $options).' ]'; |
|
248 | + } |
|
249 | + |
|
250 | + fwrite(STDOUT, $output.$extra_output.': '); |
|
251 | + } |
|
252 | + |
|
253 | + // Read the input from keyboard. |
|
254 | + $input = trim(static::input()) ?: $default; |
|
255 | + |
|
256 | + // No input provided and we require one (default will stop this being called) |
|
257 | + if (empty($input) and $required === true) |
|
258 | + { |
|
259 | + static::write('This is required.'); |
|
260 | + static::new_line(); |
|
261 | + |
|
262 | + $input = forward_static_call_array(array(__CLASS__, 'prompt'), $args); |
|
263 | + } |
|
264 | + |
|
265 | + // If options are provided and the choice is not in the array, tell them to try again |
|
266 | + if ( ! empty($options) and ! in_array($input, $options)) |
|
267 | + { |
|
268 | + static::write('This is not a valid option. Please try again.'); |
|
269 | + static::new_line(); |
|
270 | + |
|
271 | + $input = forward_static_call_array(array(__CLASS__, 'prompt'), $args); |
|
272 | + } |
|
273 | + |
|
274 | + return $input; |
|
275 | + } |
|
276 | + |
|
277 | + //-------------------------------------------------------------------- |
|
278 | + |
|
279 | + /** |
|
280 | + * Outputs a string to the cli. If you send an array it will implode them |
|
281 | + * with a line break. |
|
282 | + * |
|
283 | + * @param string|array $text the text to output, or array of lines |
|
284 | + */ |
|
285 | + public static function write($text = '', $foreground = null, $background = null) |
|
286 | + { |
|
287 | + if (is_array($text)) |
|
288 | + { |
|
289 | + $text = implode(PHP_EOL, $text); |
|
290 | + } |
|
291 | + |
|
292 | + if ($foreground or $background) |
|
293 | + { |
|
294 | + $text = static::color($text, $foreground, $background); |
|
295 | + } |
|
296 | + |
|
297 | + fwrite(STDOUT, $text.PHP_EOL); |
|
298 | + } |
|
299 | + |
|
300 | + //-------------------------------------------------------------------- |
|
301 | + |
|
302 | + /** |
|
303 | + * Outputs an error to the CLI using STDERR instead of STDOUT |
|
304 | + * |
|
305 | + * @param string|array $text the text to output, or array of errors |
|
306 | + */ |
|
307 | + public static function error($text = '', $foreground = 'light_red', $background = null) |
|
308 | + { |
|
309 | + if (is_array($text)) |
|
310 | + { |
|
311 | + $text = implode(PHP_EOL, $text); |
|
312 | + } |
|
313 | + |
|
314 | + if ($foreground OR $background) |
|
315 | + { |
|
316 | + $text = static::color($text, $foreground, $background); |
|
317 | + } |
|
318 | + |
|
319 | + fwrite(STDERR, $text.PHP_EOL); |
|
320 | + } |
|
321 | + |
|
322 | + //-------------------------------------------------------------------- |
|
323 | + |
|
324 | + /** |
|
325 | + * Beeps a certain number of times. |
|
326 | + * |
|
327 | + * @param int $num the number of times to beep |
|
328 | + */ |
|
329 | + public static function beep($num = 1) |
|
330 | + { |
|
331 | + echo str_repeat("\x07", $num); |
|
332 | + } |
|
333 | + |
|
334 | + //-------------------------------------------------------------------- |
|
335 | + |
|
336 | + /** |
|
337 | + * Waits a certain number of seconds, optionally showing a wait message and |
|
338 | + * waiting for a key press. |
|
339 | + * |
|
340 | + * @param int $seconds number of seconds |
|
341 | + * @param bool $countdown show a countdown or not |
|
342 | + */ |
|
343 | + public static function wait($seconds = 0, $countdown = false) |
|
344 | + { |
|
345 | + if ($countdown === true) |
|
346 | + { |
|
347 | + $time = $seconds; |
|
348 | + |
|
349 | + while ($time > 0) |
|
350 | + { |
|
351 | + fwrite(STDOUT, $time.'... '); |
|
352 | + sleep(1); |
|
353 | + $time--; |
|
354 | + } |
|
355 | + static::write(); |
|
356 | + } |
|
357 | + |
|
358 | + else |
|
359 | + { |
|
360 | + if ($seconds > 0) |
|
361 | + { |
|
362 | + sleep($seconds); |
|
363 | + } |
|
364 | + else |
|
365 | + { |
|
366 | + static::write(static::$wait_msg); |
|
367 | + static::input(); |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + //-------------------------------------------------------------------- |
|
374 | + |
|
375 | + /** |
|
376 | + * if operating system === windows |
|
377 | + */ |
|
378 | + public static function is_windows() |
|
379 | + { |
|
380 | + return 'win' === strtolower(substr(php_uname("s"), 0, 3)); |
|
381 | + } |
|
382 | + |
|
383 | + //-------------------------------------------------------------------- |
|
384 | + |
|
385 | + /** |
|
386 | + * Enter a number of empty lines |
|
387 | + * |
|
388 | + * @param integer Number of lines to output |
|
389 | + * @return void |
|
390 | + */ |
|
391 | + public static function new_line($num = 1) |
|
392 | + { |
|
393 | + // Do it once or more, write with empty string gives us a new line |
|
394 | + for($i = 0; $i < $num; $i++) |
|
395 | + { |
|
396 | + static::write(); |
|
397 | + } |
|
398 | + } |
|
399 | + |
|
400 | + //-------------------------------------------------------------------- |
|
401 | + |
|
402 | + /** |
|
403 | + * Clears the screen of output |
|
404 | + * |
|
405 | + * @return void |
|
406 | + */ |
|
407 | + public static function clear_screen() |
|
408 | + { |
|
409 | + static::is_windows() |
|
410 | + |
|
411 | + // Windows is a bit crap at this, but their terminal is tiny so shove this in |
|
412 | + ? static::new_line(40) |
|
413 | + |
|
414 | + // Anything with a flair of Unix will handle these magic characters |
|
415 | + : fwrite(STDOUT, chr(27)."[H".chr(27)."[2J"); |
|
416 | + } |
|
417 | + |
|
418 | + //-------------------------------------------------------------------- |
|
419 | + |
|
420 | + /** |
|
421 | + * Returns the given text with the correct color codes for a foreground and |
|
422 | + * optionally a background color. |
|
423 | + * |
|
424 | + * @param string $text the text to color |
|
425 | + * @param string $foreground the foreground color |
|
426 | + * @param string $background the background color |
|
427 | + * @param string $format other formatting to apply. Currently only 'underline' is understood |
|
428 | + * @return string the color coded string |
|
429 | + */ |
|
430 | + public static function color($text, $foreground, $background = null, $format=null) |
|
431 | + { |
|
432 | + if (static::is_windows() and ! isset($_SERVER['ANSICON'])) |
|
433 | + { |
|
434 | + return $text; |
|
435 | + } |
|
436 | + |
|
437 | + if ( ! array_key_exists($foreground, static::$foreground_colors)) |
|
438 | + { |
|
439 | + throw new \RuntimeException('Invalid CLI foreground color: '.$foreground); |
|
440 | + } |
|
441 | + |
|
442 | + if ( $background !== null and ! array_key_exists($background, static::$background_colors)) |
|
443 | + { |
|
444 | + throw new \RuntimeException('Invalid CLI background color: '.$background); |
|
445 | + } |
|
446 | + |
|
447 | + $string = "\033[".static::$foreground_colors[$foreground]."m"; |
|
448 | + |
|
449 | + if ($background !== null) |
|
450 | + { |
|
451 | + $string .= "\033[".static::$background_colors[$background]."m"; |
|
452 | + } |
|
453 | + |
|
454 | + if ($format === 'underline') |
|
455 | + { |
|
456 | + $string .= "\033[4m"; |
|
457 | + } |
|
458 | + |
|
459 | + $string .= $text."\033[0m"; |
|
460 | + |
|
461 | + return $string; |
|
462 | + } |
|
463 | + |
|
464 | + //-------------------------------------------------------------------- |
|
465 | + |
|
466 | + public static function getWidth($default=80) |
|
467 | + { |
|
468 | + if (static::is_windows()) |
|
469 | + { |
|
470 | + return $default; |
|
471 | + } |
|
472 | + |
|
473 | + return (int)shell_exec('tput cols'); |
|
474 | + } |
|
475 | 475 | |
476 | - //-------------------------------------------------------------------- |
|
477 | - |
|
478 | - public static function getHeight($default=32) |
|
479 | - { |
|
480 | - if (static::is_windows()) |
|
481 | - { |
|
482 | - return $default; |
|
483 | - } |
|
484 | - |
|
485 | - return (int)shell_exec('tput lines'); |
|
486 | - } |
|
487 | - |
|
488 | - //-------------------------------------------------------------------- |
|
489 | - |
|
490 | - /** |
|
491 | - * Displays a progress bar on the CLI. You must call it repeatedly |
|
492 | - * to update it. Set $thisStep = false to erase the progress bar. |
|
493 | - * |
|
494 | - * @param int $thisStep |
|
495 | - * @param int $totalSteps |
|
496 | - */ |
|
497 | - public static function showProgress($thisStep=1, $totalSteps=10) |
|
498 | - { |
|
499 | - // The first time through, save |
|
500 | - // our position so the script knows where to go |
|
501 | - // back to when writing the bar, and |
|
502 | - // at the end of the script. |
|
503 | - if (! static::$inProgress) { |
|
504 | - fwrite(STDOUT, "\0337"); |
|
505 | - static::$inProgress = true; |
|
506 | - } |
|
507 | - |
|
508 | - // Restore position |
|
509 | - fwrite(STDERR, "\0338"); |
|
510 | - |
|
511 | - if ($thisStep !== false) { |
|
512 | - // Don't allow div by zero or negative numbers.... |
|
513 | - $thisStep = abs($thisStep); |
|
514 | - $totalSteps = $totalSteps < 1 ? 1 : $totalSteps; |
|
515 | - |
|
516 | - $percent = intval( ($thisStep / $totalSteps) * 100 ); |
|
517 | - $step = (int)round($percent / 10); |
|
518 | - |
|
519 | - // Write the progress bar |
|
520 | - fwrite(STDOUT, "[\033[32m" . str_repeat('#', $step) . str_repeat('.', 10 - $step) . "\033[0m]"); |
|
521 | - // Textual representation... |
|
522 | - fwrite(STDOUT, " {$percent}% Complete" . PHP_EOL); |
|
523 | - // Move up, undo the PHP_EOL |
|
524 | - fwrite(STDOUT, "\033[1A"); |
|
525 | - } |
|
526 | - else |
|
527 | - { |
|
528 | - fwrite(STDERR, "\007"); |
|
529 | - } |
|
530 | - } |
|
531 | - |
|
532 | - //-------------------------------------------------------------------- |
|
476 | + //-------------------------------------------------------------------- |
|
477 | + |
|
478 | + public static function getHeight($default=32) |
|
479 | + { |
|
480 | + if (static::is_windows()) |
|
481 | + { |
|
482 | + return $default; |
|
483 | + } |
|
484 | + |
|
485 | + return (int)shell_exec('tput lines'); |
|
486 | + } |
|
487 | + |
|
488 | + //-------------------------------------------------------------------- |
|
489 | + |
|
490 | + /** |
|
491 | + * Displays a progress bar on the CLI. You must call it repeatedly |
|
492 | + * to update it. Set $thisStep = false to erase the progress bar. |
|
493 | + * |
|
494 | + * @param int $thisStep |
|
495 | + * @param int $totalSteps |
|
496 | + */ |
|
497 | + public static function showProgress($thisStep=1, $totalSteps=10) |
|
498 | + { |
|
499 | + // The first time through, save |
|
500 | + // our position so the script knows where to go |
|
501 | + // back to when writing the bar, and |
|
502 | + // at the end of the script. |
|
503 | + if (! static::$inProgress) { |
|
504 | + fwrite(STDOUT, "\0337"); |
|
505 | + static::$inProgress = true; |
|
506 | + } |
|
507 | + |
|
508 | + // Restore position |
|
509 | + fwrite(STDERR, "\0338"); |
|
510 | + |
|
511 | + if ($thisStep !== false) { |
|
512 | + // Don't allow div by zero or negative numbers.... |
|
513 | + $thisStep = abs($thisStep); |
|
514 | + $totalSteps = $totalSteps < 1 ? 1 : $totalSteps; |
|
515 | + |
|
516 | + $percent = intval( ($thisStep / $totalSteps) * 100 ); |
|
517 | + $step = (int)round($percent / 10); |
|
518 | + |
|
519 | + // Write the progress bar |
|
520 | + fwrite(STDOUT, "[\033[32m" . str_repeat('#', $step) . str_repeat('.', 10 - $step) . "\033[0m]"); |
|
521 | + // Textual representation... |
|
522 | + fwrite(STDOUT, " {$percent}% Complete" . PHP_EOL); |
|
523 | + // Move up, undo the PHP_EOL |
|
524 | + fwrite(STDOUT, "\033[1A"); |
|
525 | + } |
|
526 | + else |
|
527 | + { |
|
528 | + fwrite(STDERR, "\007"); |
|
529 | + } |
|
530 | + } |
|
531 | + |
|
532 | + //-------------------------------------------------------------------- |
|
533 | 533 | |
534 | 534 | /** |
535 | 535 | * Checks to see if an option was passed to us on the CLI and returns |
@@ -541,11 +541,11 @@ discard block |
||
541 | 541 | */ |
542 | 542 | public static function option($name) |
543 | 543 | { |
544 | - if (array_key_exists($name, self::$options)) |
|
545 | - { |
|
546 | - $val = self::$options[$name] === null ? true : self::$options[$name]; |
|
547 | - return $val; |
|
548 | - } |
|
544 | + if (array_key_exists($name, self::$options)) |
|
545 | + { |
|
546 | + $val = self::$options[$name] === null ? true : self::$options[$name]; |
|
547 | + return $val; |
|
548 | + } |
|
549 | 549 | |
550 | 550 | return null; |
551 | 551 | } |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | */ |
560 | 560 | public static function getOptions() |
561 | 561 | { |
562 | - return self::$options; |
|
562 | + return self::$options; |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | //-------------------------------------------------------------------- |
@@ -615,10 +615,10 @@ discard block |
||
615 | 615 | return ''; |
616 | 616 | } |
617 | 617 | |
618 | - if ($max == 0) |
|
619 | - { |
|
620 | - $max = CLI::getWidth(); |
|
621 | - } |
|
618 | + if ($max == 0) |
|
619 | + { |
|
620 | + $max = CLI::getWidth(); |
|
621 | + } |
|
622 | 622 | |
623 | 623 | if (CLI::getWidth() < $max) |
624 | 624 | { |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | */ |
44 | 44 | abstract class BaseGenerator extends CLIController { |
45 | 45 | |
46 | - /** |
|
47 | - * Instance of the active themer. |
|
48 | - * @var null |
|
49 | - */ |
|
50 | - protected $themer = null; |
|
46 | + /** |
|
47 | + * Instance of the active themer. |
|
48 | + * @var null |
|
49 | + */ |
|
50 | + protected $themer = null; |
|
51 | 51 | |
52 | - protected $gen_path = null; |
|
52 | + protected $gen_path = null; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * The name of the module being used, if any. |
@@ -62,254 +62,254 @@ discard block |
||
62 | 62 | |
63 | 63 | protected $overwrite = false; |
64 | 64 | |
65 | - //-------------------------------------------------------------------- |
|
65 | + //-------------------------------------------------------------------- |
|
66 | 66 | |
67 | - public function __construct() |
|
68 | - { |
|
69 | - parent::__construct(); |
|
67 | + public function __construct() |
|
68 | + { |
|
69 | + parent::__construct(); |
|
70 | 70 | |
71 | - $this->load->config('forge'); |
|
71 | + $this->load->config('forge'); |
|
72 | 72 | |
73 | - // Detect if we're genning in a module |
|
74 | - if ($module = CLI::option('module')) |
|
75 | - { |
|
76 | - $this->module = $module; |
|
73 | + // Detect if we're genning in a module |
|
74 | + if ($module = CLI::option('module')) |
|
75 | + { |
|
76 | + $this->module = $module; |
|
77 | 77 | |
78 | - $folders = config_item('modules_locations'); |
|
78 | + $folders = config_item('modules_locations'); |
|
79 | 79 | |
80 | - if (is_array($folders)) |
|
81 | - { |
|
82 | - $this->module_path = $folders[0] . strtolower($module) .'/'; |
|
83 | - } |
|
80 | + if (is_array($folders)) |
|
81 | + { |
|
82 | + $this->module_path = $folders[0] . strtolower($module) .'/'; |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | |
86 | - // Should we overwrite files? |
|
87 | - if (CLI::option('overwrite')) |
|
88 | - { |
|
89 | - $this->overwrite = true; |
|
90 | - } |
|
91 | - } |
|
86 | + // Should we overwrite files? |
|
87 | + if (CLI::option('overwrite')) |
|
88 | + { |
|
89 | + $this->overwrite = true; |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - //-------------------------------------------------------------------- |
|
93 | + //-------------------------------------------------------------------- |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * The method called by the main generator script. This must be |
|
98 | - * overridden by child classes to implement the actual logic used. |
|
99 | - * |
|
100 | - * @param array $segments |
|
101 | - * @param bool $quiet If true, models should accept default values. |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - abstract function run($segments=[], $quiet=false); |
|
96 | + /** |
|
97 | + * The method called by the main generator script. This must be |
|
98 | + * overridden by child classes to implement the actual logic used. |
|
99 | + * |
|
100 | + * @param array $segments |
|
101 | + * @param bool $quiet If true, models should accept default values. |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + abstract function run($segments=[], $quiet=false); |
|
105 | 105 | |
106 | - //-------------------------------------------------------------------- |
|
106 | + //-------------------------------------------------------------------- |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Creates a file at the specified path with the given contents. |
|
111 | - * |
|
112 | - * @param $path |
|
113 | - * @param null $contents |
|
114 | - * |
|
115 | - * @return bool |
|
116 | - */ |
|
117 | - public function createFile($path, $contents=null, $overwrite=false, $perms=0644) |
|
118 | - { |
|
119 | - $path = $this->sandbox($path); |
|
109 | + /** |
|
110 | + * Creates a file at the specified path with the given contents. |
|
111 | + * |
|
112 | + * @param $path |
|
113 | + * @param null $contents |
|
114 | + * |
|
115 | + * @return bool |
|
116 | + */ |
|
117 | + public function createFile($path, $contents=null, $overwrite=false, $perms=0644) |
|
118 | + { |
|
119 | + $path = $this->sandbox($path); |
|
120 | 120 | |
121 | - $file_exists = is_file($path); |
|
121 | + $file_exists = is_file($path); |
|
122 | 122 | |
123 | - // Does file already exist? |
|
124 | - if ($file_exists) |
|
125 | - { |
|
126 | - if (! $overwrite) { |
|
127 | - CLI::write( CLI::color("\t". strtolower(lang('exists')) .": ", 'blue') . str_replace(APPPATH, '', $path ) ); |
|
128 | - return true; |
|
129 | - } |
|
123 | + // Does file already exist? |
|
124 | + if ($file_exists) |
|
125 | + { |
|
126 | + if (! $overwrite) { |
|
127 | + CLI::write( CLI::color("\t". strtolower(lang('exists')) .": ", 'blue') . str_replace(APPPATH, '', $path ) ); |
|
128 | + return true; |
|
129 | + } |
|
130 | 130 | |
131 | - unlink($path); |
|
132 | - } |
|
131 | + unlink($path); |
|
132 | + } |
|
133 | 133 | |
134 | - // Do we need to create the directory? |
|
135 | - $segments = explode('/', $path); |
|
134 | + // Do we need to create the directory? |
|
135 | + $segments = explode('/', $path); |
|
136 | 136 | array_pop($segments); |
137 | 137 | $folder = implode('/', $segments); |
138 | 138 | |
139 | - if (! is_dir($folder)) |
|
140 | - { |
|
141 | - $this->createDirectory($folder); |
|
142 | - } |
|
139 | + if (! is_dir($folder)) |
|
140 | + { |
|
141 | + $this->createDirectory($folder); |
|
142 | + } |
|
143 | 143 | |
144 | - get_instance()->load->helper('file'); |
|
144 | + get_instance()->load->helper('file'); |
|
145 | 145 | |
146 | - if (! write_file($path, $contents)) |
|
147 | - { |
|
148 | - throw new \RuntimeException( sprintf( lang('errors.writing_file'), $path) ); |
|
149 | - } |
|
146 | + if (! write_file($path, $contents)) |
|
147 | + { |
|
148 | + throw new \RuntimeException( sprintf( lang('errors.writing_file'), $path) ); |
|
149 | + } |
|
150 | 150 | |
151 | - chmod($path, $perms); |
|
151 | + chmod($path, $perms); |
|
152 | 152 | |
153 | - if ($overwrite && $file_exists) |
|
154 | - { |
|
155 | - CLI::write( CLI::color("\t". strtolower( lang('overwrote') ) ." ", 'light_red') . str_replace(APPPATH, '', $path ) ); |
|
156 | - } |
|
157 | - else |
|
158 | - { |
|
159 | - CLI::write( CLI::color("\t". strtolower( lang('created') ) ." ", 'yellow') . str_replace(APPPATH, '', $path ) ); |
|
160 | - } |
|
153 | + if ($overwrite && $file_exists) |
|
154 | + { |
|
155 | + CLI::write( CLI::color("\t". strtolower( lang('overwrote') ) ." ", 'light_red') . str_replace(APPPATH, '', $path ) ); |
|
156 | + } |
|
157 | + else |
|
158 | + { |
|
159 | + CLI::write( CLI::color("\t". strtolower( lang('created') ) ." ", 'yellow') . str_replace(APPPATH, '', $path ) ); |
|
160 | + } |
|
161 | 161 | |
162 | - return $this; |
|
163 | - } |
|
162 | + return $this; |
|
163 | + } |
|
164 | 164 | |
165 | - //-------------------------------------------------------------------- |
|
166 | - |
|
167 | - /** |
|
168 | - * Creates a new directory at the specified path. |
|
169 | - * |
|
170 | - * @param $path |
|
171 | - * @param int|string $perms |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function createDirectory($path, $perms=0755) |
|
176 | - { |
|
177 | - $path = $this->sandbox($path); |
|
178 | - |
|
179 | - if (is_dir($path)) |
|
180 | - { |
|
181 | - return $this; |
|
182 | - } |
|
183 | - |
|
184 | - if (! mkdir($path, $perms, true) ) |
|
185 | - { |
|
186 | - throw new \RuntimeException( sprintf( lang('errors.creating_dir'), $path) ); |
|
187 | - } |
|
188 | - |
|
189 | - return $this; |
|
190 | - } |
|
191 | - |
|
192 | - //-------------------------------------------------------------------- |
|
193 | - |
|
194 | - /** |
|
195 | - * Copies a file from the current template group to the destination. |
|
196 | - * |
|
197 | - * @param $source |
|
198 | - * @param $destination |
|
199 | - * @param bool $overwrite |
|
200 | - * |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function copyFile($source, $destination, $overwrite=false) |
|
204 | - { |
|
205 | - $source = $this->sandbox($source); |
|
206 | - |
|
207 | - if (! file_exists($source)) |
|
208 | - { |
|
209 | - return null; |
|
210 | - } |
|
211 | - |
|
212 | - $content = file_get_contents($source); |
|
213 | - |
|
214 | - return $this->createFile($destination, $content, $overwrite); |
|
215 | - } |
|
216 | - |
|
217 | - //-------------------------------------------------------------------- |
|
218 | - |
|
219 | - /** |
|
220 | - * Attempts to locate a template within the current template group, |
|
221 | - * parses it with the passed in data, and writes to the new location. |
|
222 | - * |
|
223 | - * @param $template |
|
224 | - * @param $destination |
|
225 | - * @param array $data |
|
226 | - * @param bool $overwrite |
|
227 | - * |
|
228 | - * @return $this |
|
229 | - */ |
|
230 | - public function copyTemplate($template, $destination, $data=[], $overwrite=false) |
|
231 | - { |
|
232 | - if (! is_array($data)) |
|
233 | - { |
|
234 | - $data = array($data); |
|
235 | - } |
|
236 | - |
|
237 | - $content = $this->render($template, $data); |
|
238 | - |
|
239 | - return $this->createFile($destination, $content, $overwrite); |
|
240 | - } |
|
241 | - |
|
242 | - //-------------------------------------------------------------------- |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Injects a block of code into an existing file. Using options |
|
247 | - * you can specify where the code should be inserted. Available options |
|
248 | - * are: |
|
249 | - * prepend - Place at beginning of file |
|
250 | - * append - Place at end of file |
|
251 | - * before => '' - Insert just prior to this line of text (don't forget the line ending "\n") |
|
252 | - * after => '' - Insert just after this line of text (don't forget the line ending "\n") |
|
253 | - * replace => '' - a simple string to be replaced. All locations will be replaced. |
|
254 | - * regex => '' - a pregex pattern to use to replace all locations. |
|
255 | - * |
|
256 | - * @param $path |
|
257 | - * @param $content |
|
258 | - * @param array $options |
|
259 | - * |
|
260 | - * @return $this |
|
261 | - */ |
|
262 | - public function injectIntoFile($path, $content, $options='append') |
|
263 | - { |
|
264 | - $kit = new FileKit(); |
|
265 | - |
|
266 | - if (is_string($options)) |
|
267 | - { |
|
268 | - $action = $options; |
|
269 | - } |
|
270 | - else if (is_array($options) && count($options)) |
|
271 | - { |
|
272 | - $keys = array_keys($options); |
|
273 | - $action = array_shift( $keys ); |
|
274 | - $param = $options[$action]; |
|
275 | - } |
|
276 | - |
|
277 | - switch ( strtolower($action) ) |
|
278 | - { |
|
279 | - case 'prepend': |
|
280 | - $success = $kit->prepend($path, $content); |
|
281 | - break; |
|
282 | - case 'before': |
|
283 | - $success = $kit->before($path, $param, $content); |
|
284 | - break; |
|
285 | - case 'after': |
|
286 | - $success = $kit->after($path, $param, $content); |
|
287 | - break; |
|
288 | - case 'replace': |
|
289 | - $success = $kit->replaceIn($path, $param, $content); |
|
290 | - break; |
|
291 | - case 'regex': |
|
292 | - $success = $kit->replaceWithRegex($path, $param, $content); |
|
293 | - break; |
|
294 | - case 'append': |
|
295 | - default: |
|
296 | - $success = $kit->append($path, $content); |
|
297 | - break; |
|
298 | - } |
|
299 | - |
|
300 | - if ($success) |
|
301 | - { |
|
302 | - CLI::write( CLI::color("\t". strtolower( lang('modified') ) ." ", 'cyan') . str_replace(APPPATH, '', $path ) ); |
|
303 | - } |
|
304 | - else |
|
305 | - { |
|
306 | - CLI::write( CLI::color("\t". strtolower( lang('error') ) ." ", 'light_red') . str_replace(APPPATH, '', $path ) ); |
|
307 | - } |
|
308 | - |
|
309 | - return $this; |
|
310 | - } |
|
165 | + //-------------------------------------------------------------------- |
|
166 | + |
|
167 | + /** |
|
168 | + * Creates a new directory at the specified path. |
|
169 | + * |
|
170 | + * @param $path |
|
171 | + * @param int|string $perms |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function createDirectory($path, $perms=0755) |
|
176 | + { |
|
177 | + $path = $this->sandbox($path); |
|
178 | + |
|
179 | + if (is_dir($path)) |
|
180 | + { |
|
181 | + return $this; |
|
182 | + } |
|
183 | + |
|
184 | + if (! mkdir($path, $perms, true) ) |
|
185 | + { |
|
186 | + throw new \RuntimeException( sprintf( lang('errors.creating_dir'), $path) ); |
|
187 | + } |
|
188 | + |
|
189 | + return $this; |
|
190 | + } |
|
191 | + |
|
192 | + //-------------------------------------------------------------------- |
|
193 | + |
|
194 | + /** |
|
195 | + * Copies a file from the current template group to the destination. |
|
196 | + * |
|
197 | + * @param $source |
|
198 | + * @param $destination |
|
199 | + * @param bool $overwrite |
|
200 | + * |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function copyFile($source, $destination, $overwrite=false) |
|
204 | + { |
|
205 | + $source = $this->sandbox($source); |
|
206 | + |
|
207 | + if (! file_exists($source)) |
|
208 | + { |
|
209 | + return null; |
|
210 | + } |
|
211 | + |
|
212 | + $content = file_get_contents($source); |
|
213 | + |
|
214 | + return $this->createFile($destination, $content, $overwrite); |
|
215 | + } |
|
216 | + |
|
217 | + //-------------------------------------------------------------------- |
|
218 | + |
|
219 | + /** |
|
220 | + * Attempts to locate a template within the current template group, |
|
221 | + * parses it with the passed in data, and writes to the new location. |
|
222 | + * |
|
223 | + * @param $template |
|
224 | + * @param $destination |
|
225 | + * @param array $data |
|
226 | + * @param bool $overwrite |
|
227 | + * |
|
228 | + * @return $this |
|
229 | + */ |
|
230 | + public function copyTemplate($template, $destination, $data=[], $overwrite=false) |
|
231 | + { |
|
232 | + if (! is_array($data)) |
|
233 | + { |
|
234 | + $data = array($data); |
|
235 | + } |
|
236 | + |
|
237 | + $content = $this->render($template, $data); |
|
238 | + |
|
239 | + return $this->createFile($destination, $content, $overwrite); |
|
240 | + } |
|
241 | + |
|
242 | + //-------------------------------------------------------------------- |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Injects a block of code into an existing file. Using options |
|
247 | + * you can specify where the code should be inserted. Available options |
|
248 | + * are: |
|
249 | + * prepend - Place at beginning of file |
|
250 | + * append - Place at end of file |
|
251 | + * before => '' - Insert just prior to this line of text (don't forget the line ending "\n") |
|
252 | + * after => '' - Insert just after this line of text (don't forget the line ending "\n") |
|
253 | + * replace => '' - a simple string to be replaced. All locations will be replaced. |
|
254 | + * regex => '' - a pregex pattern to use to replace all locations. |
|
255 | + * |
|
256 | + * @param $path |
|
257 | + * @param $content |
|
258 | + * @param array $options |
|
259 | + * |
|
260 | + * @return $this |
|
261 | + */ |
|
262 | + public function injectIntoFile($path, $content, $options='append') |
|
263 | + { |
|
264 | + $kit = new FileKit(); |
|
265 | + |
|
266 | + if (is_string($options)) |
|
267 | + { |
|
268 | + $action = $options; |
|
269 | + } |
|
270 | + else if (is_array($options) && count($options)) |
|
271 | + { |
|
272 | + $keys = array_keys($options); |
|
273 | + $action = array_shift( $keys ); |
|
274 | + $param = $options[$action]; |
|
275 | + } |
|
276 | + |
|
277 | + switch ( strtolower($action) ) |
|
278 | + { |
|
279 | + case 'prepend': |
|
280 | + $success = $kit->prepend($path, $content); |
|
281 | + break; |
|
282 | + case 'before': |
|
283 | + $success = $kit->before($path, $param, $content); |
|
284 | + break; |
|
285 | + case 'after': |
|
286 | + $success = $kit->after($path, $param, $content); |
|
287 | + break; |
|
288 | + case 'replace': |
|
289 | + $success = $kit->replaceIn($path, $param, $content); |
|
290 | + break; |
|
291 | + case 'regex': |
|
292 | + $success = $kit->replaceWithRegex($path, $param, $content); |
|
293 | + break; |
|
294 | + case 'append': |
|
295 | + default: |
|
296 | + $success = $kit->append($path, $content); |
|
297 | + break; |
|
298 | + } |
|
299 | + |
|
300 | + if ($success) |
|
301 | + { |
|
302 | + CLI::write( CLI::color("\t". strtolower( lang('modified') ) ." ", 'cyan') . str_replace(APPPATH, '', $path ) ); |
|
303 | + } |
|
304 | + else |
|
305 | + { |
|
306 | + CLI::write( CLI::color("\t". strtolower( lang('error') ) ." ", 'light_red') . str_replace(APPPATH, '', $path ) ); |
|
307 | + } |
|
308 | + |
|
309 | + return $this; |
|
310 | + } |
|
311 | 311 | |
312 | - //-------------------------------------------------------------------- |
|
312 | + //-------------------------------------------------------------------- |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Runs another generator. The first parameter is the name of the |
@@ -320,130 +320,130 @@ discard block |
||
320 | 320 | * @param $command |
321 | 321 | * @param null $options |
322 | 322 | */ |
323 | - public function generate($command, $options = '', $quiet=false) |
|
324 | - { |
|
323 | + public function generate($command, $options = '', $quiet=false) |
|
324 | + { |
|
325 | 325 | $orig_options = CLI::optionString(); |
326 | - $options = $orig_options .' '. $options; |
|
327 | - |
|
328 | - if ($quiet === true) |
|
329 | - { |
|
330 | - $options .= ' -quiet'; |
|
331 | - } |
|
332 | - |
|
333 | - if ($this->overwrite === true) |
|
334 | - { |
|
335 | - $options .= ' -overwrite'; |
|
336 | - } |
|
337 | - |
|
338 | - passthru( "php sprint forge {$command} {$options}" ); |
|
339 | - } |
|
340 | - |
|
341 | - //-------------------------------------------------------------------- |
|
342 | - |
|
343 | - /** |
|
344 | - * Adds a new route to the application's route file. |
|
345 | - * |
|
346 | - * @param $left |
|
347 | - * @param $right |
|
348 | - * |
|
349 | - * @return \Myth\Forge\BaseGenerator |
|
350 | - */ |
|
351 | - public function route($left, $right, $options=[], $method='any') |
|
352 | - { |
|
353 | - $option_str = '['; |
|
354 | - |
|
355 | - foreach ($options as $key => $value) |
|
356 | - { |
|
357 | - $option_str .= ""; |
|
358 | - } |
|
359 | - |
|
360 | - $option_str .= ']'; |
|
361 | - |
|
362 | - $content = "\$routes->{$method}('{$left}', '{$right}', {$option_str});\n"; |
|
363 | - |
|
364 | - return $this->injectIntoFile(APPPATH .'config/routes.php', $content, ['after' => "// Auto-generated routes go here\n"]); |
|
365 | - } |
|
326 | + $options = $orig_options .' '. $options; |
|
327 | + |
|
328 | + if ($quiet === true) |
|
329 | + { |
|
330 | + $options .= ' -quiet'; |
|
331 | + } |
|
332 | + |
|
333 | + if ($this->overwrite === true) |
|
334 | + { |
|
335 | + $options .= ' -overwrite'; |
|
336 | + } |
|
337 | + |
|
338 | + passthru( "php sprint forge {$command} {$options}" ); |
|
339 | + } |
|
340 | + |
|
341 | + //-------------------------------------------------------------------- |
|
342 | + |
|
343 | + /** |
|
344 | + * Adds a new route to the application's route file. |
|
345 | + * |
|
346 | + * @param $left |
|
347 | + * @param $right |
|
348 | + * |
|
349 | + * @return \Myth\Forge\BaseGenerator |
|
350 | + */ |
|
351 | + public function route($left, $right, $options=[], $method='any') |
|
352 | + { |
|
353 | + $option_str = '['; |
|
354 | + |
|
355 | + foreach ($options as $key => $value) |
|
356 | + { |
|
357 | + $option_str .= ""; |
|
358 | + } |
|
359 | + |
|
360 | + $option_str .= ']'; |
|
361 | + |
|
362 | + $content = "\$routes->{$method}('{$left}', '{$right}', {$option_str});\n"; |
|
363 | + |
|
364 | + return $this->injectIntoFile(APPPATH .'config/routes.php', $content, ['after' => "// Auto-generated routes go here\n"]); |
|
365 | + } |
|
366 | 366 | |
367 | - //-------------------------------------------------------------------- |
|
367 | + //-------------------------------------------------------------------- |
|
368 | 368 | |
369 | - /** |
|
370 | - * Outputs the contents of the file in the template's source path. |
|
371 | - */ |
|
372 | - public function readme($file='readme.txt') |
|
373 | - { |
|
374 | - $name = str_replace('Generator', '', get_class($this)); |
|
369 | + /** |
|
370 | + * Outputs the contents of the file in the template's source path. |
|
371 | + */ |
|
372 | + public function readme($file='readme.txt') |
|
373 | + { |
|
374 | + $name = str_replace('Generator', '', get_class($this)); |
|
375 | 375 | |
376 | - $path = $this->locateGenerator($name); |
|
376 | + $path = $this->locateGenerator($name); |
|
377 | 377 | |
378 | - if (! file_exists($path . $file)) |
|
379 | - { |
|
380 | - CLI::error(sprintf( lang('forge.cant_find_readme'), $file) ); |
|
381 | - } |
|
378 | + if (! file_exists($path . $file)) |
|
379 | + { |
|
380 | + CLI::error(sprintf( lang('forge.cant_find_readme'), $file) ); |
|
381 | + } |
|
382 | 382 | |
383 | - $contents = file_get_contents($path . $file); |
|
383 | + $contents = file_get_contents($path . $file); |
|
384 | 384 | |
385 | - CLI::new_line(2); |
|
386 | - CLI::write( CLI::wrap($contents), 'green' ); |
|
387 | - CLI::new_line(); |
|
388 | - } |
|
385 | + CLI::new_line(2); |
|
386 | + CLI::write( CLI::wrap($contents), 'green' ); |
|
387 | + CLI::new_line(); |
|
388 | + } |
|
389 | 389 | |
390 | - //-------------------------------------------------------------------- |
|
390 | + //-------------------------------------------------------------------- |
|
391 | 391 | |
392 | - /** |
|
393 | - * Renders a single generator template. The file must be in a folder |
|
394 | - * under the template group named the same as $this->generator_name. |
|
395 | - * The file must have a '.tpl.php' file extension. |
|
396 | - * |
|
397 | - * @param $template_name |
|
398 | - * @param array $data |
|
399 | - * |
|
400 | - * @return string The rendered template |
|
401 | - */ |
|
402 | - public function render($template_name, $data=[], $folder=null) |
|
403 | - { |
|
404 | - if (empty($this->themer)) |
|
405 | - { |
|
406 | - $this->setupThemer(); |
|
407 | - } |
|
392 | + /** |
|
393 | + * Renders a single generator template. The file must be in a folder |
|
394 | + * under the template group named the same as $this->generator_name. |
|
395 | + * The file must have a '.tpl.php' file extension. |
|
396 | + * |
|
397 | + * @param $template_name |
|
398 | + * @param array $data |
|
399 | + * |
|
400 | + * @return string The rendered template |
|
401 | + */ |
|
402 | + public function render($template_name, $data=[], $folder=null) |
|
403 | + { |
|
404 | + if (empty($this->themer)) |
|
405 | + { |
|
406 | + $this->setupThemer(); |
|
407 | + } |
|
408 | 408 | |
409 | - $data['uikit'] = $this->loadUIKit(); |
|
409 | + $data['uikit'] = $this->loadUIKit(); |
|
410 | 410 | |
411 | - $output = null; |
|
411 | + $output = null; |
|
412 | 412 | |
413 | - $view = $template_name .'.tpl'; |
|
413 | + $view = $template_name .'.tpl'; |
|
414 | 414 | |
415 | - $groups = config_item('forge.collections'); |
|
415 | + $groups = config_item('forge.collections'); |
|
416 | 416 | |
417 | - $name = str_replace('Generator', '', get_class($this) ); |
|
417 | + $name = str_replace('Generator', '', get_class($this) ); |
|
418 | 418 | |
419 | - foreach ($groups as $group => $path) |
|
420 | - { |
|
421 | - $path = rtrim($path, '/ ') .'/'; |
|
422 | - $folders = scandir($path); |
|
419 | + foreach ($groups as $group => $path) |
|
420 | + { |
|
421 | + $path = rtrim($path, '/ ') .'/'; |
|
422 | + $folders = scandir($path); |
|
423 | 423 | |
424 | - if (! $i = array_search(ucfirst($name), $folders)) |
|
425 | - { |
|
426 | - continue; |
|
427 | - } |
|
424 | + if (! $i = array_search(ucfirst($name), $folders)) |
|
425 | + { |
|
426 | + continue; |
|
427 | + } |
|
428 | 428 | |
429 | - $view = $folders[$i] . '/'. $view; |
|
429 | + $view = $folders[$i] . '/'. $view; |
|
430 | 430 | |
431 | - if (realpath($path . $view .'.php')) |
|
432 | - { |
|
433 | - $output = $this->themer->display($group .':'. $view, $data); |
|
434 | - break; |
|
435 | - } |
|
436 | - } |
|
431 | + if (realpath($path . $view .'.php')) |
|
432 | + { |
|
433 | + $output = $this->themer->display($group .':'. $view, $data); |
|
434 | + break; |
|
435 | + } |
|
436 | + } |
|
437 | 437 | |
438 | - // To allow for including any PHP code in the templates, |
|
439 | - // replace any '@php' and '@=' tags with their correct PHP syntax. |
|
440 | - $output = str_replace('@php', '<?php', $output); |
|
441 | - $output = str_replace('@=', '<?=', $output); |
|
438 | + // To allow for including any PHP code in the templates, |
|
439 | + // replace any '@php' and '@=' tags with their correct PHP syntax. |
|
440 | + $output = str_replace('@php', '<?php', $output); |
|
441 | + $output = str_replace('@=', '<?=', $output); |
|
442 | 442 | |
443 | - return $output; |
|
444 | - } |
|
443 | + return $output; |
|
444 | + } |
|
445 | 445 | |
446 | - //-------------------------------------------------------------------- |
|
446 | + //-------------------------------------------------------------------- |
|
447 | 447 | |
448 | 448 | /** |
449 | 449 | * Forces a path to exist within the current application's folder. |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | */ |
459 | 459 | public function sandbox($path) |
460 | 460 | { |
461 | - $path = $this->normalizePath($path); |
|
461 | + $path = $this->normalizePath($path); |
|
462 | 462 | |
463 | 463 | // If it's writing to BASEPATH - FIX IT |
464 | 464 | if (strpos($path, $this->normalizePath(BASEPATH) ) === 0) |
@@ -478,37 +478,37 @@ discard block |
||
478 | 478 | return $path; |
479 | 479 | } |
480 | 480 | |
481 | - return APPPATH . $path; |
|
481 | + return APPPATH . $path; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | //-------------------------------------------------------------------- |
485 | 485 | |
486 | 486 | |
487 | 487 | |
488 | - //-------------------------------------------------------------------- |
|
489 | - // Private Methods |
|
490 | - //-------------------------------------------------------------------- |
|
488 | + //-------------------------------------------------------------------- |
|
489 | + // Private Methods |
|
490 | + //-------------------------------------------------------------------- |
|
491 | 491 | |
492 | - protected function setupThemer() |
|
493 | - { |
|
494 | - $themer_name = config_item('forge.themer'); |
|
492 | + protected function setupThemer() |
|
493 | + { |
|
494 | + $themer_name = config_item('forge.themer'); |
|
495 | 495 | |
496 | - if (! $themer_name) |
|
497 | - { |
|
498 | - throw new \RuntimeException( lang('forge.no_themer') ); |
|
499 | - } |
|
496 | + if (! $themer_name) |
|
497 | + { |
|
498 | + throw new \RuntimeException( lang('forge.no_themer') ); |
|
499 | + } |
|
500 | 500 | |
501 | - $this->themer = new $themer_name( get_instance() ); |
|
501 | + $this->themer = new $themer_name( get_instance() ); |
|
502 | 502 | |
503 | - // Register our paths with the themer |
|
504 | - $paths = config_item('forge.collections'); |
|
503 | + // Register our paths with the themer |
|
504 | + $paths = config_item('forge.collections'); |
|
505 | 505 | |
506 | - foreach ($paths as $key => $path) { |
|
507 | - $this->themer->addThemePath($key, $path); |
|
508 | - } |
|
509 | - } |
|
506 | + foreach ($paths as $key => $path) { |
|
507 | + $this->themer->addThemePath($key, $path); |
|
508 | + } |
|
509 | + } |
|
510 | 510 | |
511 | - //-------------------------------------------------------------------- |
|
511 | + //-------------------------------------------------------------------- |
|
512 | 512 | |
513 | 513 | public function loadUIKit() |
514 | 514 | { |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | |
522 | 522 | $uikit = new $kit_name(); |
523 | 523 | |
524 | - return $uikit; |
|
524 | + return $uikit; |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | //-------------------------------------------------------------------- |
@@ -639,66 +639,66 @@ discard block |
||
639 | 639 | |
640 | 640 | //-------------------------------------------------------------------- |
641 | 641 | |
642 | - /** |
|
643 | - * Normalizes a path and cleans it up for healthy use within |
|
644 | - * realpath() and helps to mitigate changes between Windows and *nix |
|
645 | - * operating systems. |
|
646 | - * |
|
647 | - * Found at http://php.net/manual/en/function.realpath.php#112367 |
|
648 | - * |
|
649 | - * @param $path |
|
650 | - * |
|
651 | - * @return string |
|
652 | - */ |
|
653 | - protected function normalizePath($path) |
|
654 | - { |
|
655 | - // Array to build a new path from the good parts |
|
656 | - $parts = array(); |
|
657 | - |
|
658 | - // Replace backslashes with forward slashes |
|
659 | - $path = str_replace('\\', '/', $path); |
|
660 | - |
|
661 | - // Combine multiple slashes into a single slash |
|
662 | - $path = preg_replace('/\/+/', '/', $path); |
|
663 | - |
|
664 | - // Collect path segments |
|
665 | - $segments = explode('/', $path); |
|
666 | - |
|
667 | - // Initialize testing variable |
|
668 | - $test = ''; |
|
669 | - |
|
670 | - foreach($segments as $segment) |
|
671 | - { |
|
672 | - if($segment != '.') |
|
673 | - { |
|
674 | - $test = array_pop($parts); |
|
675 | - |
|
676 | - if(is_null($test)) |
|
677 | - { |
|
678 | - $parts[] = $segment; |
|
679 | - } |
|
680 | - else if ($segment == '..') |
|
681 | - { |
|
682 | - if ($test == '..') |
|
683 | - { |
|
684 | - $parts[] = $test; |
|
685 | - } |
|
686 | - |
|
687 | - if ($test == '..' || $test == '') |
|
688 | - { |
|
689 | - $parts[] = $segment; |
|
690 | - } |
|
691 | - } |
|
692 | - else |
|
693 | - { |
|
694 | - $parts[] = $test; |
|
695 | - $parts[] = $segment; |
|
696 | - } |
|
697 | - } |
|
698 | - } |
|
699 | - return implode('/', $parts); |
|
700 | - } |
|
701 | - |
|
702 | - //-------------------------------------------------------------------- |
|
642 | + /** |
|
643 | + * Normalizes a path and cleans it up for healthy use within |
|
644 | + * realpath() and helps to mitigate changes between Windows and *nix |
|
645 | + * operating systems. |
|
646 | + * |
|
647 | + * Found at http://php.net/manual/en/function.realpath.php#112367 |
|
648 | + * |
|
649 | + * @param $path |
|
650 | + * |
|
651 | + * @return string |
|
652 | + */ |
|
653 | + protected function normalizePath($path) |
|
654 | + { |
|
655 | + // Array to build a new path from the good parts |
|
656 | + $parts = array(); |
|
657 | + |
|
658 | + // Replace backslashes with forward slashes |
|
659 | + $path = str_replace('\\', '/', $path); |
|
660 | + |
|
661 | + // Combine multiple slashes into a single slash |
|
662 | + $path = preg_replace('/\/+/', '/', $path); |
|
663 | + |
|
664 | + // Collect path segments |
|
665 | + $segments = explode('/', $path); |
|
666 | + |
|
667 | + // Initialize testing variable |
|
668 | + $test = ''; |
|
669 | + |
|
670 | + foreach($segments as $segment) |
|
671 | + { |
|
672 | + if($segment != '.') |
|
673 | + { |
|
674 | + $test = array_pop($parts); |
|
675 | + |
|
676 | + if(is_null($test)) |
|
677 | + { |
|
678 | + $parts[] = $segment; |
|
679 | + } |
|
680 | + else if ($segment == '..') |
|
681 | + { |
|
682 | + if ($test == '..') |
|
683 | + { |
|
684 | + $parts[] = $test; |
|
685 | + } |
|
686 | + |
|
687 | + if ($test == '..' || $test == '') |
|
688 | + { |
|
689 | + $parts[] = $segment; |
|
690 | + } |
|
691 | + } |
|
692 | + else |
|
693 | + { |
|
694 | + $parts[] = $test; |
|
695 | + $parts[] = $segment; |
|
696 | + } |
|
697 | + } |
|
698 | + } |
|
699 | + return implode('/', $parts); |
|
700 | + } |
|
701 | + |
|
702 | + //-------------------------------------------------------------------- |
|
703 | 703 | |
704 | 704 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function detectAction($name) |
165 | 165 | { |
166 | - $segments = explode('_', $name); |
|
166 | + $segments = explode('_', $name); |
|
167 | 167 | |
168 | 168 | $action = trim(strtolower(array_shift($segments))); |
169 | 169 | |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function parseFields($str) |
238 | 238 | { |
239 | - if (empty($str)) |
|
240 | - { |
|
241 | - return; |
|
242 | - } |
|
239 | + if (empty($str)) |
|
240 | + { |
|
241 | + return; |
|
242 | + } |
|
243 | 243 | |
244 | 244 | $fields = []; |
245 | 245 | $segments = explode(' ', $str); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function restrict($uri=null, $return_only=false) |
60 | 60 | { |
61 | - $this->setupAuthClasses(); |
|
61 | + $this->setupAuthClasses(); |
|
62 | 62 | |
63 | 63 | if ($this->authenticate->isLoggedIn()) |
64 | 64 | { |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function restrictToGroups($groups, $uri='') |
110 | 110 | { |
111 | - $this->setupAuthClasses(); |
|
111 | + $this->setupAuthClasses(); |
|
112 | 112 | |
113 | 113 | if ($this->authenticate->isLoggedIn()) |
114 | 114 | { |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function restrictWithPermissions($permissions, $uri='') |
151 | 151 | { |
152 | - $this->setupAuthClasses(); |
|
152 | + $this->setupAuthClasses(); |
|
153 | 153 | |
154 | 154 | if ($this->authenticate->isLoggedIn()) |
155 | 155 | { |
@@ -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 |
@@ -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 | } |
@@ -32,183 +32,183 @@ |
||
32 | 32 | |
33 | 33 | class DatabaseStore implements SettingsStoreInterface { |
34 | 34 | |
35 | - protected $ci; |
|
36 | - |
|
37 | - protected $db; |
|
38 | - |
|
39 | - //-------------------------------------------------------------------- |
|
40 | - |
|
41 | - public function __construct( $ci=null ) |
|
42 | - { |
|
43 | - if (is_object($ci)) |
|
44 | - { |
|
45 | - $this->ci =& $ci; |
|
46 | - } |
|
47 | - else { |
|
48 | - $this->ci =& get_instance(); |
|
49 | - } |
|
50 | - |
|
51 | - // Ensure that the database is loaded. |
|
52 | - if (empty($this->ci->db)) |
|
53 | - { |
|
54 | - $this->ci->load->database(); |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - //-------------------------------------------------------------------- |
|
59 | - |
|
60 | - /** |
|
61 | - * Inserts or Replaces an setting value. |
|
62 | - * |
|
63 | - * @param $key |
|
64 | - * @param null $value |
|
65 | - * @param string $group |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function save($key, $value=null, $group='app') |
|
69 | - { |
|
70 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
71 | - { |
|
72 | - return false; |
|
73 | - } |
|
74 | - |
|
75 | - $where = [ |
|
76 | - 'name' => $key, |
|
77 | - 'group' => $group |
|
78 | - ]; |
|
79 | - $this->ci->db->delete('settings', $where); |
|
80 | - |
|
81 | - if (is_array($value) || is_object($value)) |
|
82 | - { |
|
83 | - $value = serialize($value); |
|
84 | - } |
|
85 | - |
|
86 | - $data = [ |
|
87 | - 'name' => $key, |
|
88 | - 'value' => $value, |
|
89 | - 'group' => $group |
|
90 | - ]; |
|
91 | - return $this->ci->db->insert('settings', $data); |
|
92 | - } |
|
93 | - |
|
94 | - //-------------------------------------------------------------------- |
|
95 | - |
|
96 | - /** |
|
97 | - * Retrieves a single item. |
|
98 | - * |
|
99 | - * @param $key |
|
100 | - * @param string $group |
|
101 | - * @return mixed |
|
102 | - */ |
|
103 | - public function get($key, $group='app') |
|
104 | - { |
|
105 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
106 | - { |
|
107 | - return false; |
|
108 | - } |
|
109 | - |
|
110 | - $where = [ |
|
111 | - 'name' => $key, |
|
112 | - 'group' => $group |
|
113 | - ]; |
|
114 | - |
|
115 | - $query = $this->ci->db->where($where) |
|
116 | - ->get('settings'); |
|
117 | - |
|
118 | - if (! $query->num_rows()) |
|
119 | - { |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - $value = $query->row()->value; |
|
124 | - |
|
125 | - // Check to see if it needs to be unserialized |
|
126 | - $data = @unserialize($value); // We don't need to issue an E_NOTICE here... |
|
127 | - |
|
128 | - // Check for a value of false or |
|
129 | - if ($value === 'b:0;' || $data !== false) |
|
130 | - { |
|
131 | - $value = $data; |
|
132 | - } |
|
133 | - |
|
134 | - return $value; |
|
135 | - } |
|
136 | - |
|
137 | - //-------------------------------------------------------------------- |
|
138 | - |
|
139 | - /** |
|
140 | - * Deletes a single item. |
|
141 | - * |
|
142 | - * @param $key |
|
143 | - * @param $group |
|
144 | - * @return mixed |
|
145 | - */ |
|
146 | - public function delete($key, $group='app') |
|
147 | - { |
|
148 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
149 | - { |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - $where = [ |
|
154 | - 'name' => $key, |
|
155 | - 'group' => $group |
|
156 | - ]; |
|
157 | - |
|
158 | - return $this->ci->db->delete('settings', $where); |
|
159 | - } |
|
160 | - |
|
161 | - //-------------------------------------------------------------------- |
|
162 | - |
|
163 | - /** |
|
164 | - * Searches the store for any items with $field = $value. |
|
165 | - * |
|
166 | - * @param $field |
|
167 | - * @param $value |
|
168 | - * @return mixed |
|
169 | - */ |
|
170 | - public function findBy($field, $value) |
|
171 | - { |
|
172 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
173 | - { |
|
174 | - return false; |
|
175 | - } |
|
176 | - |
|
177 | - $query = $this->ci->db->where($field, $value) |
|
178 | - ->get('settings'); |
|
179 | - |
|
180 | - if (! $query->num_rows()) |
|
181 | - { |
|
182 | - return false; |
|
183 | - } |
|
184 | - |
|
185 | - return $query->result_array(); |
|
186 | - } |
|
187 | - |
|
188 | - //-------------------------------------------------------------------- |
|
189 | - |
|
190 | - /** |
|
191 | - * Retrieves all items in the store either globally or for a single group. |
|
192 | - * |
|
193 | - * @param string $group |
|
194 | - * @return mixed |
|
195 | - */ |
|
196 | - public function all($group=null) |
|
197 | - { |
|
198 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
199 | - { |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - $query = $this->ci->db->get('settings'); |
|
204 | - |
|
205 | - if (! $query->num_rows()) |
|
206 | - { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - return $query->result_array(); |
|
211 | - } |
|
212 | - |
|
213 | - //-------------------------------------------------------------------- |
|
35 | + protected $ci; |
|
36 | + |
|
37 | + protected $db; |
|
38 | + |
|
39 | + //-------------------------------------------------------------------- |
|
40 | + |
|
41 | + public function __construct( $ci=null ) |
|
42 | + { |
|
43 | + if (is_object($ci)) |
|
44 | + { |
|
45 | + $this->ci =& $ci; |
|
46 | + } |
|
47 | + else { |
|
48 | + $this->ci =& get_instance(); |
|
49 | + } |
|
50 | + |
|
51 | + // Ensure that the database is loaded. |
|
52 | + if (empty($this->ci->db)) |
|
53 | + { |
|
54 | + $this->ci->load->database(); |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + //-------------------------------------------------------------------- |
|
59 | + |
|
60 | + /** |
|
61 | + * Inserts or Replaces an setting value. |
|
62 | + * |
|
63 | + * @param $key |
|
64 | + * @param null $value |
|
65 | + * @param string $group |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function save($key, $value=null, $group='app') |
|
69 | + { |
|
70 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
71 | + { |
|
72 | + return false; |
|
73 | + } |
|
74 | + |
|
75 | + $where = [ |
|
76 | + 'name' => $key, |
|
77 | + 'group' => $group |
|
78 | + ]; |
|
79 | + $this->ci->db->delete('settings', $where); |
|
80 | + |
|
81 | + if (is_array($value) || is_object($value)) |
|
82 | + { |
|
83 | + $value = serialize($value); |
|
84 | + } |
|
85 | + |
|
86 | + $data = [ |
|
87 | + 'name' => $key, |
|
88 | + 'value' => $value, |
|
89 | + 'group' => $group |
|
90 | + ]; |
|
91 | + return $this->ci->db->insert('settings', $data); |
|
92 | + } |
|
93 | + |
|
94 | + //-------------------------------------------------------------------- |
|
95 | + |
|
96 | + /** |
|
97 | + * Retrieves a single item. |
|
98 | + * |
|
99 | + * @param $key |
|
100 | + * @param string $group |
|
101 | + * @return mixed |
|
102 | + */ |
|
103 | + public function get($key, $group='app') |
|
104 | + { |
|
105 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
106 | + { |
|
107 | + return false; |
|
108 | + } |
|
109 | + |
|
110 | + $where = [ |
|
111 | + 'name' => $key, |
|
112 | + 'group' => $group |
|
113 | + ]; |
|
114 | + |
|
115 | + $query = $this->ci->db->where($where) |
|
116 | + ->get('settings'); |
|
117 | + |
|
118 | + if (! $query->num_rows()) |
|
119 | + { |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + $value = $query->row()->value; |
|
124 | + |
|
125 | + // Check to see if it needs to be unserialized |
|
126 | + $data = @unserialize($value); // We don't need to issue an E_NOTICE here... |
|
127 | + |
|
128 | + // Check for a value of false or |
|
129 | + if ($value === 'b:0;' || $data !== false) |
|
130 | + { |
|
131 | + $value = $data; |
|
132 | + } |
|
133 | + |
|
134 | + return $value; |
|
135 | + } |
|
136 | + |
|
137 | + //-------------------------------------------------------------------- |
|
138 | + |
|
139 | + /** |
|
140 | + * Deletes a single item. |
|
141 | + * |
|
142 | + * @param $key |
|
143 | + * @param $group |
|
144 | + * @return mixed |
|
145 | + */ |
|
146 | + public function delete($key, $group='app') |
|
147 | + { |
|
148 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
149 | + { |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + $where = [ |
|
154 | + 'name' => $key, |
|
155 | + 'group' => $group |
|
156 | + ]; |
|
157 | + |
|
158 | + return $this->ci->db->delete('settings', $where); |
|
159 | + } |
|
160 | + |
|
161 | + //-------------------------------------------------------------------- |
|
162 | + |
|
163 | + /** |
|
164 | + * Searches the store for any items with $field = $value. |
|
165 | + * |
|
166 | + * @param $field |
|
167 | + * @param $value |
|
168 | + * @return mixed |
|
169 | + */ |
|
170 | + public function findBy($field, $value) |
|
171 | + { |
|
172 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
173 | + { |
|
174 | + return false; |
|
175 | + } |
|
176 | + |
|
177 | + $query = $this->ci->db->where($field, $value) |
|
178 | + ->get('settings'); |
|
179 | + |
|
180 | + if (! $query->num_rows()) |
|
181 | + { |
|
182 | + return false; |
|
183 | + } |
|
184 | + |
|
185 | + return $query->result_array(); |
|
186 | + } |
|
187 | + |
|
188 | + //-------------------------------------------------------------------- |
|
189 | + |
|
190 | + /** |
|
191 | + * Retrieves all items in the store either globally or for a single group. |
|
192 | + * |
|
193 | + * @param string $group |
|
194 | + * @return mixed |
|
195 | + */ |
|
196 | + public function all($group=null) |
|
197 | + { |
|
198 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
199 | + { |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + $query = $this->ci->db->get('settings'); |
|
204 | + |
|
205 | + if (! $query->num_rows()) |
|
206 | + { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + return $query->result_array(); |
|
211 | + } |
|
212 | + |
|
213 | + //-------------------------------------------------------------------- |
|
214 | 214 | } |