@@ -19,7 +19,7 @@ public function controller($name)
1919 {
2020 $ name = ucfirst ($ name );
2121
22- if ( ! file_exists (APPPATH . "controllers/ {$ name }.php " ))
22+ if (file_exists (APPPATH . "controllers/ {$ name }.php " ) === FALSE )
2323 {
2424 $ template = read_file (APPPATH . 'templates/Controller.php ' );
2525 $ template = str_replace ('<controller> ' , $ name , $ template );
@@ -28,7 +28,39 @@ public function controller($name)
2828 }
2929 else
3030 {
31- echo "\n{$ name } controller already exists \n\n" ;
31+ echo "n \"{$ name }\" controller already exists \n\n" ;
32+ }
33+ }
34+
35+ public function config ($ name )
36+ {
37+ if (file_exists (APPPATH . "config/ {$ name }.php " ) === FALSE )
38+ {
39+ $ template = read_file (APPPATH . 'templates/Config.php ' );
40+
41+ write_file (APPPATH . "config/ {$ name }.php " , $ template );
42+ }
43+ else
44+ {
45+ $ name = ucfirst ($ name );
46+ echo "\n\"{$ name }\" config already exists \n\n" ;
47+ }
48+ }
49+
50+ public function core ($ name )
51+ {
52+ $ name = ucfirst ($ name );
53+
54+ if (file_exists (BASEPATH . "core/ {$ name }.php " ) === FALSE AND file_exists (APPPATH . "core/ {$ name }.php " ) === FALSE )
55+ {
56+ $ template = read_file (APPPATH . 'templates/Core.php ' );
57+ $ template = str_replace ('<core> ' , $ name , $ template );
58+
59+ write_file (APPPATH . "core/ {$ name }.php " , $ template );
60+ }
61+ else
62+ {
63+ echo "\n\"{$ name }\" core already exists \n\n" ;
3264 }
3365 }
3466
@@ -37,11 +69,32 @@ public function database($name)
3769 $ this ->load ->dbforge ();
3870
3971 $ this ->dbforge ->create_database ($ name );
72+
73+ $ database = read_file (APPPATH . 'config/database.php ' );
74+ $ database = preg_replace ("/'database' => '.*'/ " , "'database' => ' {$ name }' " , $ database );
75+
76+ write_file (APPPATH . 'config/database.php ' , $ database );
77+ }
78+
79+ public function environment ($ env )
80+ {
81+ if (in_array ($ env , array ('development ' , 'testing ' , 'production ' , 'maintenance ' )) === TRUE )
82+ {
83+ $ htaccess = read_file (FCPATH . '.htaccess ' );
84+ $ htaccess = preg_replace ("/SetEnv CI_ENV (development|testing|production|maintenance)/ " , "SetEnv CI_ENV {$ env }" , $ htaccess );
85+
86+ write_file (FCPATH . '.htaccess ' , $ htaccess );
87+ }
88+ else
89+ {
90+ $ env = ucfirst ($ env );
91+ echo "\n\"{$ env }\" environment not found \n\n" ;
92+ }
4093 }
4194
4295 public function helper ($ name )
4396 {
44- if ( ! file_exists (APPPATH . "helpers/ {$ name }_helper.php " ))
97+ if (file_exists ( BASEPATH . " helpers/ { $ name } _helper.php " ) === FALSE AND file_exists (APPPATH . "helpers/ {$ name }_helper.php " ) === FALSE )
4598 {
4699 $ template = read_file (APPPATH . 'templates/Helper.php ' );
47100
@@ -50,7 +103,24 @@ public function helper($name)
50103 else
51104 {
52105 $ name = ucfirst ($ name );
53- echo "\n{$ name } helper already exists \n\n" ;
106+ echo "\n\"{$ name }\" helper already exists \n\n" ;
107+ }
108+ }
109+
110+ public function hook ($ name )
111+ {
112+ $ name = ucfirst ($ name );
113+
114+ if (file_exists (APPPATH . "hooks/ {$ name }.php " ) === FALSE )
115+ {
116+ $ template = read_file (APPPATH . 'templates/Hook.php ' );
117+ $ template = str_replace ('<hook> ' , $ name , $ template );
118+
119+ write_file (APPPATH . "hooks/ {$ name }.php " , $ template );
120+ }
121+ else
122+ {
123+ echo "\n\"{$ name }\" hook already exists \n\n" ;
54124 }
55125 }
56126
@@ -61,18 +131,36 @@ public function key($length = 16)
61131 $ encryption_key = bin2hex ($ this ->encryption ->create_key ($ length ));
62132
63133 $ config = read_file (APPPATH . 'config/config.php ' );
64- $ config = str_replace ( " '< encryption_key>' " , "bin2hex (' {$ encryption_key }') " , $ config );
134+ $ config = preg_replace ( ' /\$config\[ \' encryption_key \' \] = hex2bin\( \' [0-9a-f]* \' \);/ ' , "\$ config['encryption_key'] = hex2bin (' {$ encryption_key }'); " , $ config );
65135
66136 write_file (APPPATH . 'config/config.php ' , $ config );
67137
68138 echo "\nEncryption key: {$ encryption_key }\n\n" ;
69139 }
70140
141+ public function language ($ name )
142+ {
143+ $ localization = config_item ('language ' );
144+
145+ if (file_exists (APPPATH . "language/ {$ localization }/ {$ name }_lang.php " ) === FALSE )
146+ {
147+ $ template = read_file (APPPATH . 'templates/Language.php ' );
148+ $ template = str_replace ('<language> ' , $ name , $ template );
149+
150+ write_file (APPPATH . "language/ {$ localization }/ {$ name }_lang.php " , $ template );
151+ }
152+ else
153+ {
154+ $ name = ucfirst ($ name );
155+ echo "\n\"{$ name }\" language already exists \n\n" ;
156+ }
157+ }
158+
71159 public function library ($ name )
72160 {
73161 $ name = ucfirst ($ name );
74162
75- if ( ! file_exists (APPPATH . "libraries/ {$ name }.php " ))
163+ if (file_exists ( BASEPATH . " libraries/ { $ name } .php " ) === FALSE AND file_exists (APPPATH . "libraries/ {$ name }.php " ) === FALSE )
76164 {
77165 $ template = read_file (APPPATH . 'templates/Library.php ' );
78166 $ template = str_replace ('<library> ' , $ name , $ template );
@@ -81,7 +169,7 @@ public function library($name)
81169 }
82170 else
83171 {
84- echo "\n{$ name } library already exists \n\n" ;
172+ echo "\n\" {$ name }\" library already exists \n\n" ;
85173 }
86174 }
87175
@@ -101,7 +189,7 @@ public function migration($name)
101189 $ table = explode ('_ ' , $ name );
102190 $ table = end ($ table );
103191
104- if ( ! file_exists (APPPATH . "migrations/ {$ timestamp }_ {$ name }.php " ))
192+ if (file_exists (APPPATH . "migrations/ {$ timestamp }_ {$ name }.php " ) === FALSE )
105193 {
106194 $ template = read_file (APPPATH . 'templates/Migration.php ' );
107195 $ template = str_replace (
@@ -113,22 +201,22 @@ public function migration($name)
113201 write_file (APPPATH . "migrations/ {$ timestamp }_ {$ name }.php " , $ template );
114202
115203 $ migration = read_file (APPPATH . 'config/migration.php ' );
116- $ migration = str_replace ( " '<version>' " , $ timestamp , $ migration );
204+ $ migration = preg_replace ( ' /(\$config\[ \' migration_version \' \] =) \d+;/ ' , ' $1 ' . $ timestamp . ' ; ' , $ migration );
117205
118206 write_file (APPPATH . 'config/migration.php ' , $ migration );
119207 }
120208 else
121209 {
122210 $ name = ucfirst (str_replace ('_ ' , ' ' , $ name ));
123- echo "\n{$ name } migration already exists \n\n" ;
211+ echo "\n\" {$ name }\" migration already exists \n\n" ;
124212 }
125213 }
126214
127215 public function model ($ name )
128216 {
129217 $ name = ucfirst ($ name );
130218
131- if ( ! file_exists (APPPATH . "models/ {$ name }_model.php " ))
219+ if (file_exists (APPPATH . "models/ {$ name }_model.php " ) === FALSE )
132220 {
133221 $ template = read_file (APPPATH . 'templates/Model.php ' );
134222 $ template = str_replace ('<model> ' , $ name , $ template );
@@ -137,17 +225,45 @@ public function model($name)
137225 }
138226 else
139227 {
140- echo "\n{$ name } model already exists \n\n" ;
228+ echo "\n\" {$ name }\" model already exists \n\n" ;
141229 }
142230 }
143231
144232 public function seed ()
145233 {
146- return ;
234+ $ this ->load ->library ('seeder ' );
235+
236+ $ seeders = get_filenames (APPPATH . 'seeders/ ' );
237+
238+ foreach ($ seeders as $ seeder )
239+ {
240+ if (str_contains ($ seeder , '.php ' ))
241+ {
242+ $ name = str_replace ('.php ' , '' , $ seeder );
243+
244+ $ this ->seeder ->call ($ name );
245+ }
246+ }
147247 }
148248
149- public function seeder ()
249+ public function seeder ($ name )
150250 {
151- return ;
251+ $ name = ucfirst ($ name );
252+
253+ if (file_exists (APPPATH . "seeders/ {$ name }_seeder.php " ) === FALSE )
254+ {
255+ $ template = read_file (APPPATH . 'templates/Seeder.php ' );
256+ $ template = str_replace (
257+ array ('<seeder> ' , '<table> ' ),
258+ array ($ name , strtolower ($ name )),
259+ $ template
260+ );
261+
262+ write_file (APPPATH . "seeders/ {$ name }_seeder.php " , $ template );
263+ }
264+ else
265+ {
266+ echo "\n\"{$ name }\" seeder already exists \n\n" ;
267+ }
152268 }
153269}
0 commit comments