@@ -4,79 +4,79 @@ |
||
4 | 4 | |
5 | 5 | if (! function_exists('esc')) |
6 | 6 | { |
7 | - /** |
|
8 | - * Escapes strings to make them safe for use |
|
9 | - * within HTML templates. Used by the auto-escaping |
|
10 | - * functionality in setVar() and available to |
|
11 | - * use within your views. |
|
12 | - * |
|
13 | - * Uses ZendFramework's Escaper to handle the actual escaping, |
|
14 | - * based on context. Valid contexts are: |
|
15 | - * - html |
|
16 | - * - htmlAttr |
|
17 | - * - js |
|
18 | - * - css |
|
19 | - * - url |
|
20 | - * |
|
21 | - * References: |
|
22 | - * - https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet |
|
23 | - * - http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html |
|
24 | - * |
|
25 | - * @param $data |
|
26 | - * @param $context |
|
27 | - * @param escaper // An instance of ZF's Escaper to avoid repeated class instantiation. |
|
28 | - * |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - function esc($data, $context='html', $escaper=null) |
|
32 | - { |
|
33 | - if (is_array($data)) |
|
34 | - { |
|
35 | - foreach ($data as $key => &$value) |
|
36 | - { |
|
37 | - $value = esc($value, $context); |
|
38 | - } |
|
39 | - } |
|
7 | + /** |
|
8 | + * Escapes strings to make them safe for use |
|
9 | + * within HTML templates. Used by the auto-escaping |
|
10 | + * functionality in setVar() and available to |
|
11 | + * use within your views. |
|
12 | + * |
|
13 | + * Uses ZendFramework's Escaper to handle the actual escaping, |
|
14 | + * based on context. Valid contexts are: |
|
15 | + * - html |
|
16 | + * - htmlAttr |
|
17 | + * - js |
|
18 | + * - css |
|
19 | + * - url |
|
20 | + * |
|
21 | + * References: |
|
22 | + * - https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet |
|
23 | + * - http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html |
|
24 | + * |
|
25 | + * @param $data |
|
26 | + * @param $context |
|
27 | + * @param escaper // An instance of ZF's Escaper to avoid repeated class instantiation. |
|
28 | + * |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + function esc($data, $context='html', $escaper=null) |
|
32 | + { |
|
33 | + if (is_array($data)) |
|
34 | + { |
|
35 | + foreach ($data as $key => &$value) |
|
36 | + { |
|
37 | + $value = esc($value, $context); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | - $context = strtolower($context); |
|
41 | + $context = strtolower($context); |
|
42 | 42 | |
43 | - if (! is_object($escaper)) |
|
44 | - { |
|
45 | - $escaper = new Escaper(config_item('charset')); |
|
46 | - } |
|
43 | + if (! is_object($escaper)) |
|
44 | + { |
|
45 | + $escaper = new Escaper(config_item('charset')); |
|
46 | + } |
|
47 | 47 | |
48 | - // Valid context? |
|
49 | - if (! in_array($context, ['html', 'htmlattr', 'js', 'css', 'url'])) |
|
50 | - { |
|
51 | - throw new \InvalidArgumentException('Invalid Context type: '. $context); |
|
52 | - } |
|
48 | + // Valid context? |
|
49 | + if (! in_array($context, ['html', 'htmlattr', 'js', 'css', 'url'])) |
|
50 | + { |
|
51 | + throw new \InvalidArgumentException('Invalid Context type: '. $context); |
|
52 | + } |
|
53 | 53 | |
54 | - if (! is_string($data)) |
|
55 | - { |
|
56 | - return $data; |
|
57 | - } |
|
54 | + if (! is_string($data)) |
|
55 | + { |
|
56 | + return $data; |
|
57 | + } |
|
58 | 58 | |
59 | - switch ($context) |
|
60 | - { |
|
61 | - case 'html': |
|
62 | - $data = $escaper->escapeHtml($data); |
|
63 | - break; |
|
64 | - case 'htmlattr': |
|
65 | - $data = $escaper->escapeHtmlAttr($data); |
|
66 | - break; |
|
67 | - case 'js': |
|
68 | - $data = $escaper->escapeJs($data); |
|
69 | - break; |
|
70 | - case 'css': |
|
71 | - $data = $escaper->escapeCss($data); |
|
72 | - break; |
|
73 | - case 'url': |
|
74 | - $data = $escaper->escapeUrl($data); |
|
75 | - break; |
|
76 | - default: |
|
77 | - break; |
|
78 | - } |
|
59 | + switch ($context) |
|
60 | + { |
|
61 | + case 'html': |
|
62 | + $data = $escaper->escapeHtml($data); |
|
63 | + break; |
|
64 | + case 'htmlattr': |
|
65 | + $data = $escaper->escapeHtmlAttr($data); |
|
66 | + break; |
|
67 | + case 'js': |
|
68 | + $data = $escaper->escapeJs($data); |
|
69 | + break; |
|
70 | + case 'css': |
|
71 | + $data = $escaper->escapeCss($data); |
|
72 | + break; |
|
73 | + case 'url': |
|
74 | + $data = $escaper->escapeUrl($data); |
|
75 | + break; |
|
76 | + default: |
|
77 | + break; |
|
78 | + } |
|
79 | 79 | |
80 | - return $data; |
|
81 | - } |
|
80 | + return $data; |
|
81 | + } |
|
82 | 82 | } |
83 | 83 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use Zend\Escaper\Escaper; |
4 | 4 | |
5 | -if (! function_exists('esc')) |
|
5 | +if ( ! function_exists('esc')) |
|
6 | 6 | { |
7 | 7 | /** |
8 | 8 | * Escapes strings to make them safe for use |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - function esc($data, $context='html', $escaper=null) |
|
31 | + function esc($data, $context = 'html', $escaper = null) |
|
32 | 32 | { |
33 | 33 | if (is_array($data)) |
34 | 34 | { |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | |
41 | 41 | $context = strtolower($context); |
42 | 42 | |
43 | - if (! is_object($escaper)) |
|
43 | + if ( ! is_object($escaper)) |
|
44 | 44 | { |
45 | 45 | $escaper = new Escaper(config_item('charset')); |
46 | 46 | } |
47 | 47 | |
48 | 48 | // Valid context? |
49 | - if (! in_array($context, ['html', 'htmlattr', 'js', 'css', 'url'])) |
|
49 | + if ( ! in_array($context, ['html', 'htmlattr', 'js', 'css', 'url'])) |
|
50 | 50 | { |
51 | - throw new \InvalidArgumentException('Invalid Context type: '. $context); |
|
51 | + throw new \InvalidArgumentException('Invalid Context type: '.$context); |
|
52 | 52 | } |
53 | 53 | |
54 | - if (! is_string($data)) |
|
54 | + if ( ! is_string($data)) |
|
55 | 55 | { |
56 | 56 | return $data; |
57 | 57 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | if (! empty($model) ) |
25 | 25 | { |
26 | - $index_method = <<<EOD |
|
26 | + $index_method = <<<EOD |
|
27 | 27 | \$this->load->library('table'); |
28 | 28 | |
29 | 29 | \$offset = \$this->uri->segment( \$this->uri->total_segments() ); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | if (! empty($model)) |
46 | 46 | { |
47 | - $create_method = <<<EOD |
|
47 | + $create_method = <<<EOD |
|
48 | 48 | \$this->load->helper('form'); |
49 | 49 | \$this->load->helper('inflector'); |
50 | 50 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | if (! empty($model)) |
74 | 74 | { |
75 | - $show_method = <<<EOD |
|
75 | + $show_method = <<<EOD |
|
76 | 76 | \$item = \$this->{$lower_model}->find(\$id); |
77 | 77 | |
78 | 78 | if (! \$item) |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | if (! empty($model)) |
96 | 96 | { |
97 | - $update_method = <<<EOD |
|
97 | + $update_method = <<<EOD |
|
98 | 98 | \$this->load->helper('form'); |
99 | 99 | \$this->load->helper('inflector'); |
100 | 100 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | if (! empty($model)) |
127 | 127 | { |
128 | - $delete_method = <<<EOD |
|
128 | + $delete_method = <<<EOD |
|
129 | 129 | if (\$this->{$lower_model}->delete(\$id)) |
130 | 130 | { |
131 | 131 | \$this->setMessage('Successfully deleted item.', 'success'); |
@@ -145,12 +145,12 @@ discard block |
||
145 | 145 | |
146 | 146 | if ($themed) |
147 | 147 | { |
148 | - $index_method .= "\$this->render();"; |
|
149 | - $create_method .= "\$this->render();"; |
|
150 | - $show_method .= "\$this->render();"; |
|
151 | - $update_method .= "\$this->render();"; |
|
148 | + $index_method .= "\$this->render();"; |
|
149 | + $create_method .= "\$this->render();"; |
|
150 | + $show_method .= "\$this->render();"; |
|
151 | + $update_method .= "\$this->render();"; |
|
152 | 152 | |
153 | - $fields = " |
|
153 | + $fields = " |
|
154 | 154 | /** |
155 | 155 | * Allows per-controller override of theme. |
156 | 156 | * @var null |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | //-------------------------------------------------------------------- |
6 | 6 | |
7 | 7 | $model_string = $model ? "'{$model}'" : 'null'; |
8 | -$lower_model = trim( strtolower($model_string), "' " ); |
|
8 | +$lower_model = trim(strtolower($model_string), "' "); |
|
9 | 9 | $lower_model_esc = strpos($lower_model, 'null') !== false ? 'null' : "'{$lower_model}'"; |
10 | -$lower_controller = strtolower($controller_name); |
|
10 | +$lower_controller = strtolower($controller_name); |
|
11 | 11 | |
12 | 12 | //-------------------------------------------------------------------- |
13 | 13 | // Build our Methods |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | $index_method = ''; |
23 | 23 | |
24 | -if (! empty($model) ) |
|
24 | +if ( ! empty($model)) |
|
25 | 25 | { |
26 | 26 | $index_method = <<<EOD |
27 | 27 | \$this->load->library('table'); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | $create_method = ''; |
44 | 44 | |
45 | -if (! empty($model)) |
|
45 | +if ( ! empty($model)) |
|
46 | 46 | { |
47 | 47 | $create_method = <<<EOD |
48 | 48 | \$this->load->helper('form'); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | $show_method = ''; |
72 | 72 | |
73 | -if (! empty($model)) |
|
73 | +if ( ! empty($model)) |
|
74 | 74 | { |
75 | 75 | $show_method = <<<EOD |
76 | 76 | \$item = \$this->{$lower_model}->find(\$id); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | $update_method = ''; |
94 | 94 | |
95 | -if (! empty($model)) |
|
95 | +if ( ! empty($model)) |
|
96 | 96 | { |
97 | 97 | $update_method = <<<EOD |
98 | 98 | \$this->load->helper('form'); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | $delete_method = ''; |
125 | 125 | |
126 | -if (! empty($model)) |
|
126 | +if ( ! empty($model)) |
|
127 | 127 | { |
128 | 128 | $delete_method = <<<EOD |
129 | 129 | if (\$this->{$lower_model}->delete(\$id)) |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | |
33 | 33 | $descriptions = [ |
34 | - 'controller' => ['controller <name> [<base>]', 'Creates a new controller file that extends from <base> or BaseController.'] |
|
34 | + 'controller' => ['controller <name> [<base>]', 'Creates a new controller file that extends from <base> or BaseController.'] |
|
35 | 35 | ]; |
36 | 36 | |
37 | 37 | $long_description = <<<EOT |
@@ -4,43 +4,43 @@ |
||
4 | 4 | |
5 | 5 | <?= $uikit->row([], function() use($uikit, $fields) { |
6 | 6 | |
7 | - $sizes = [ |
|
8 | - 's' => 12, |
|
9 | - 'm' => 6, |
|
10 | - 'l' => 4 |
|
11 | - ]; |
|
12 | - echo $uikit->column(['sizes' => $sizes], function() use($uikit, $fields) { |
|
13 | - |
|
14 | - foreach ($fields as $field) |
|
15 | - { |
|
16 | - echo $uikit->inputWrap( humanize($field['name']), null, function() use($uikit, $field) { |
|
17 | - |
|
18 | - switch ($field['type']) |
|
19 | - { |
|
20 | - case 'text': |
|
21 | - echo " <input type='text' class='form-control' name='{$field['name']}' />\n"; |
|
22 | - break; |
|
23 | - case 'number': |
|
24 | - echo " <input type='number' class='form-control' name='{$field['name']}' />\n"; |
|
25 | - break; |
|
26 | - case 'date': |
|
27 | - echo " <input type='date' class='form-control' name='{$field['name']}' />\n"; |
|
28 | - break; |
|
29 | - case 'datetime': |
|
30 | - echo " <input type='datetime' class='form-control' name='{$field['name']}' />\n"; |
|
31 | - break; |
|
32 | - case 'time': |
|
33 | - echo " <input type='time' class='form-control' name='{$field['name']}' />\n"; |
|
34 | - break; |
|
35 | - case 'textarea': |
|
36 | - echo " <textarea name='{$field['name']}' class='form-control'></textarea>\n"; |
|
37 | - break; |
|
38 | - } |
|
39 | - |
|
40 | - } ); |
|
41 | - } |
|
42 | - |
|
43 | - }); |
|
7 | + $sizes = [ |
|
8 | + 's' => 12, |
|
9 | + 'm' => 6, |
|
10 | + 'l' => 4 |
|
11 | + ]; |
|
12 | + echo $uikit->column(['sizes' => $sizes], function() use($uikit, $fields) { |
|
13 | + |
|
14 | + foreach ($fields as $field) |
|
15 | + { |
|
16 | + echo $uikit->inputWrap( humanize($field['name']), null, function() use($uikit, $field) { |
|
17 | + |
|
18 | + switch ($field['type']) |
|
19 | + { |
|
20 | + case 'text': |
|
21 | + echo " <input type='text' class='form-control' name='{$field['name']}' />\n"; |
|
22 | + break; |
|
23 | + case 'number': |
|
24 | + echo " <input type='number' class='form-control' name='{$field['name']}' />\n"; |
|
25 | + break; |
|
26 | + case 'date': |
|
27 | + echo " <input type='date' class='form-control' name='{$field['name']}' />\n"; |
|
28 | + break; |
|
29 | + case 'datetime': |
|
30 | + echo " <input type='datetime' class='form-control' name='{$field['name']}' />\n"; |
|
31 | + break; |
|
32 | + case 'time': |
|
33 | + echo " <input type='time' class='form-control' name='{$field['name']}' />\n"; |
|
34 | + break; |
|
35 | + case 'textarea': |
|
36 | + echo " <textarea name='{$field['name']}' class='form-control'></textarea>\n"; |
|
37 | + break; |
|
38 | + } |
|
39 | + |
|
40 | + } ); |
|
41 | + } |
|
42 | + |
|
43 | + }); |
|
44 | 44 | |
45 | 45 | }); ?> |
46 | 46 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | |
14 | 14 | foreach ($fields as $field) |
15 | 15 | { |
16 | - echo $uikit->inputWrap( humanize($field['name']), null, function() use($uikit, $field) { |
|
16 | + echo $uikit->inputWrap(humanize($field['name']), null, function() use($uikit, $field) { |
|
17 | 17 | |
18 | 18 | switch ($field['type']) |
19 | 19 | { |
@@ -12,21 +12,21 @@ discard block |
||
12 | 12 | */ |
13 | 13 | if ($action == 'create') |
14 | 14 | { |
15 | - $up = "\$fields = {$fields}; |
|
15 | + $up = "\$fields = {$fields}; |
|
16 | 16 | |
17 | 17 | \$this->dbforge->add_field(\$fields); |
18 | 18 | "; |
19 | 19 | |
20 | - if (! empty($primary_key)) |
|
21 | - { |
|
22 | - $up .= " \$this->dbforge->add_key('{$primary_key}', true); |
|
20 | + if (! empty($primary_key)) |
|
21 | + { |
|
22 | + $up .= " \$this->dbforge->add_key('{$primary_key}', true); |
|
23 | 23 | "; |
24 | - } |
|
24 | + } |
|
25 | 25 | |
26 | - $up .=" \$this->dbforge->create_table('{$table}', true, config_item('migration_create_table_attr') ); |
|
26 | + $up .=" \$this->dbforge->create_table('{$table}', true, config_item('migration_create_table_attr') ); |
|
27 | 27 | "; |
28 | 28 | |
29 | - $down = "\$this->dbforge->drop_table('{$table}');"; |
|
29 | + $down = "\$this->dbforge->drop_table('{$table}');"; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /* |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | */ |
35 | 35 | if ($action == 'add' && ! empty($column)) |
36 | 36 | { |
37 | - $up = "\$field = {$column_string}; |
|
37 | + $up = "\$field = {$column_string}; |
|
38 | 38 | \$this->dbforge->add_column('{$table}', \$field);"; |
39 | 39 | |
40 | - $down = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
40 | + $down = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /* |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | */ |
46 | 46 | if ($action == 'remove' && ! empty($column)) |
47 | 47 | { |
48 | - $up = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
48 | + $up = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
49 | 49 | |
50 | - $down = "\$field = {$column_string}; |
|
50 | + $down = "\$field = {$column_string}; |
|
51 | 51 | \$this->dbforge->add_column('{$table}', \$field);"; |
52 | 52 | } |
53 | 53 |
@@ -17,13 +17,13 @@ |
||
17 | 17 | \$this->dbforge->add_field(\$fields); |
18 | 18 | "; |
19 | 19 | |
20 | - if (! empty($primary_key)) |
|
20 | + if ( ! empty($primary_key)) |
|
21 | 21 | { |
22 | 22 | $up .= " \$this->dbforge->add_key('{$primary_key}', true); |
23 | 23 | "; |
24 | 24 | } |
25 | 25 | |
26 | - $up .=" \$this->dbforge->create_table('{$table}', true, config_item('migration_create_table_attr') ); |
|
26 | + $up .= " \$this->dbforge->create_table('{$table}', true, config_item('migration_create_table_attr') ); |
|
27 | 27 | "; |
28 | 28 | |
29 | 29 | $down = "\$this->dbforge->drop_table('{$table}');"; |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | |
33 | 33 | $descriptions = [ |
34 | - 'model' => ['model <name>', 'Creates a new model file that extends from CIDbModel.'] |
|
34 | + 'model' => ['model <name>', 'Creates a new model file that extends from CIDbModel.'] |
|
35 | 35 | ]; |
36 | 36 | |
37 | 37 | $long_description = <<<EOT |
@@ -35,7 +35,7 @@ |
||
35 | 35 | protected \$deleted_by_field = 'deleted_by'; |
36 | 36 | "; |
37 | 37 | |
38 | -$protect = "'". implode("', '", $protected) . "'"; |
|
38 | +$protect = "'".implode("', '", $protected)."'"; |
|
39 | 39 | |
40 | 40 | //-------------------------------------------------------------------- |
41 | 41 | // Create the full model |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | protected $model_name = ''; |
40 | 40 | |
41 | - protected $table_exists = false; |
|
41 | + protected $table_exists = false; |
|
42 | 42 | |
43 | 43 | //-------------------------------------------------------------------- |
44 | 44 | |
@@ -46,32 +46,32 @@ discard block |
||
46 | 46 | { |
47 | 47 | $name = array_shift( $segments ); |
48 | 48 | |
49 | - // If a table already exists then we don't need a migration |
|
50 | - $this->load->database(); |
|
51 | - if ($this->db->table_exists($name)) |
|
52 | - { |
|
53 | - $this->table_exists = true; |
|
54 | - } |
|
49 | + // If a table already exists then we don't need a migration |
|
50 | + $this->load->database(); |
|
51 | + if ($this->db->table_exists($name)) |
|
52 | + { |
|
53 | + $this->table_exists = true; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | // If we didn't attach any fields, then we |
57 | 57 | // need to generate the barebones here. |
58 | 58 | $this->fields = CLI::option('fields'); |
59 | 59 | |
60 | - // If we don't have any fields, and no model |
|
61 | - // exists, then we need to provide some default fields. |
|
62 | - if (empty($this->fields)) |
|
63 | - { |
|
64 | - if (! $this->table_exists) |
|
65 | - { |
|
66 | - $this->fields = "id:int id:id title:string created_on:datetime modified_on:datetime"; |
|
67 | - } |
|
68 | - } |
|
60 | + // If we don't have any fields, and no model |
|
61 | + // exists, then we need to provide some default fields. |
|
62 | + if (empty($this->fields)) |
|
63 | + { |
|
64 | + if (! $this->table_exists) |
|
65 | + { |
|
66 | + $this->fields = "id:int id:id title:string created_on:datetime modified_on:datetime"; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | // Perform the steps. |
71 | - if (! $this->table_exists) |
|
72 | - { |
|
73 | - $this->makeMigration( $name ); |
|
74 | - } |
|
71 | + if (! $this->table_exists) |
|
72 | + { |
|
73 | + $this->makeMigration( $name ); |
|
74 | + } |
|
75 | 75 | $this->makeSeed($name); |
76 | 76 | $this->makeModel($name); |
77 | 77 | $this->makeController($name); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | public function makeSeed($name) |
100 | 100 | { |
101 | - $this->generate("seed {$name}", null, true); |
|
101 | + $this->generate("seed {$name}", null, true); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | //-------------------------------------------------------------------- |
@@ -106,33 +106,33 @@ discard block |
||
106 | 106 | |
107 | 107 | public function makeModel($name) |
108 | 108 | { |
109 | - $this->load->helper('inflector'); |
|
109 | + $this->load->helper('inflector'); |
|
110 | 110 | |
111 | 111 | $name = singular($name); |
112 | 112 | $this->model_name = $name; |
113 | 113 | |
114 | - // If a table exists, we can build it from that |
|
115 | - if ($this->table_exists) |
|
116 | - { |
|
117 | - $this->generate( "model {$name}", "-table $name -primary_key id", TRUE ); |
|
118 | - } |
|
119 | - // Otherwise, we need to provide the fields to make the model out of. |
|
120 | - else |
|
121 | - { |
|
122 | - $this->generate( "model {$name}", "-fields '{$this->fields}'", TRUE ); |
|
123 | - } |
|
114 | + // If a table exists, we can build it from that |
|
115 | + if ($this->table_exists) |
|
116 | + { |
|
117 | + $this->generate( "model {$name}", "-table $name -primary_key id", TRUE ); |
|
118 | + } |
|
119 | + // Otherwise, we need to provide the fields to make the model out of. |
|
120 | + else |
|
121 | + { |
|
122 | + $this->generate( "model {$name}", "-fields '{$this->fields}'", TRUE ); |
|
123 | + } |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | //-------------------------------------------------------------------- |
127 | 127 | |
128 | 128 | public function makeController($name) |
129 | 129 | { |
130 | - $options = "-model {$this->model_name} -create_views"; |
|
130 | + $options = "-model {$this->model_name} -create_views"; |
|
131 | 131 | |
132 | - if (! empty($this->fields)) |
|
133 | - { |
|
134 | - $options .= " -fields '{$this->fields}'"; |
|
135 | - } |
|
132 | + if (! empty($this->fields)) |
|
133 | + { |
|
134 | + $options .= " -fields '{$this->fields}'"; |
|
135 | + } |
|
136 | 136 | |
137 | 137 | $this->generate("controller {$name}", $options, true); |
138 | 138 | } |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | |
43 | 43 | //-------------------------------------------------------------------- |
44 | 44 | |
45 | - public function run($segments = [ ], $quiet = false) |
|
45 | + public function run($segments = [], $quiet = false) |
|
46 | 46 | { |
47 | - $name = array_shift( $segments ); |
|
47 | + $name = array_shift($segments); |
|
48 | 48 | |
49 | 49 | // If a table already exists then we don't need a migration |
50 | 50 | $this->load->database(); |
@@ -61,16 +61,16 @@ discard block |
||
61 | 61 | // exists, then we need to provide some default fields. |
62 | 62 | if (empty($this->fields)) |
63 | 63 | { |
64 | - if (! $this->table_exists) |
|
64 | + if ( ! $this->table_exists) |
|
65 | 65 | { |
66 | 66 | $this->fields = "id:int id:id title:string created_on:datetime modified_on:datetime"; |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Perform the steps. |
71 | - if (! $this->table_exists) |
|
71 | + if ( ! $this->table_exists) |
|
72 | 72 | { |
73 | - $this->makeMigration( $name ); |
|
73 | + $this->makeMigration($name); |
|
74 | 74 | } |
75 | 75 | $this->makeSeed($name); |
76 | 76 | $this->makeModel($name); |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | // If a table exists, we can build it from that |
115 | 115 | if ($this->table_exists) |
116 | 116 | { |
117 | - $this->generate( "model {$name}", "-table $name -primary_key id", TRUE ); |
|
117 | + $this->generate("model {$name}", "-table $name -primary_key id", TRUE); |
|
118 | 118 | } |
119 | 119 | // Otherwise, we need to provide the fields to make the model out of. |
120 | 120 | else |
121 | 121 | { |
122 | - $this->generate( "model {$name}", "-fields '{$this->fields}'", TRUE ); |
|
122 | + $this->generate("model {$name}", "-fields '{$this->fields}'", TRUE); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | $options = "-model {$this->model_name} -create_views"; |
131 | 131 | |
132 | - if (! empty($this->fields)) |
|
132 | + if ( ! empty($this->fields)) |
|
133 | 133 | { |
134 | 134 | $options .= " -fields '{$this->fields}'"; |
135 | 135 | } |
@@ -34,36 +34,36 @@ |
||
34 | 34 | |
35 | 35 | class SeedGenerator extends \Myth\Forge\BaseGenerator { |
36 | 36 | |
37 | - public function run($segments=[], $quiet=false) |
|
37 | + public function run($segments = [], $quiet = false) |
|
38 | 38 | { |
39 | - $name = array_shift( $segments ); |
|
39 | + $name = array_shift($segments); |
|
40 | 40 | |
41 | - if ( empty( $name ) ) |
|
41 | + if (empty($name)) |
|
42 | 42 | { |
43 | - $name = CLI::prompt( 'Seed name' ); |
|
43 | + $name = CLI::prompt('Seed name'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | // Format to CI Standards |
47 | - $name = str_replace('.php', '', strtolower( $name ) ); |
|
48 | - if (substr( $name, -4) == 'seed') |
|
47 | + $name = str_replace('.php', '', strtolower($name)); |
|
48 | + if (substr($name, -4) == 'seed') |
|
49 | 49 | { |
50 | 50 | $name = substr($name, 0, strlen($name) - 4); |
51 | 51 | } |
52 | - $name = ucfirst($name) .'Seeder'; |
|
52 | + $name = ucfirst($name).'Seeder'; |
|
53 | 53 | |
54 | 54 | $data = [ |
55 | 55 | 'seed_name' => $name, |
56 | - 'today' => date( 'Y-m-d H:ia' ) |
|
56 | + 'today' => date('Y-m-d H:ia') |
|
57 | 57 | ]; |
58 | 58 | |
59 | - $destination = $this->determineOutputPath( 'database/seeds' ) . $name . '.php'; |
|
59 | + $destination = $this->determineOutputPath('database/seeds').$name.'.php'; |
|
60 | 60 | |
61 | 61 | if (strpos($destination, 'modules') !== false) |
62 | 62 | { |
63 | 63 | $destination = str_replace('database/', '', $destination); |
64 | 64 | } |
65 | 65 | |
66 | - if (! $this->copyTemplate( 'seed', $destination, $data, $this->overwrite) ) |
|
66 | + if ( ! $this->copyTemplate('seed', $destination, $data, $this->overwrite)) |
|
67 | 67 | { |
68 | 68 | CLI::error('Error creating seed file.'); |
69 | 69 | } |