22
33namespace CrestApps \CodeGenerator \Commands \Framework ;
44
5- use CrestApps \CodeGenerator \Models \ResourceInput ;
5+ use CrestApps \CodeGenerator \Models \Bases \ScaffoldInputBase ;
6+ use CrestApps \CodeGenerator \Models \ScaffoldInput ;
67use CrestApps \CodeGenerator \Support \Config ;
78use CrestApps \CodeGenerator \Support \Helpers ;
89use CrestApps \CodeGenerator \Traits \CommonCommand ;
@@ -20,20 +21,28 @@ class CreateMappedResourcesCommand extends Command
2021 */
2122 protected $ signature = 'create:mapped-resources
2223 {--controller-directory= : The directory where the controller should be created under. }
23- {--controller-extends=Http\Controllers\Controller : The base controller to be extend.}
2424 {--model-directory= : The path of the model.}
2525 {--views-directory= : The name of the view path.}
2626 {--models-per-page=25 : The amount of models per page for index pages.}
27+ {--language-filename= : The languages file name to put the labels in.}
28+ {--table-name= : The name of the table.}
29+ {--controller-name= : The name of the controler.}
2730 {--with-form-request : This will extract the validation into a request form class.}
2831 {--with-auth : Generate the controller with Laravel auth middlewear. }
32+ {--with-migration : Prevent creating a migration for this resource.}
2933 {--with-soft-delete : Enables softdelete future should be enable in the model.}
3034 {--without-timestamps : Prevent Eloquent from maintaining both created_at and the updated_at properties.}
31- {--with-migration : Prevent creating a migration for this resource.}
35+ {--without-languages : Generate the resource without the language files. }
36+ {--without-model : Generate the resource without the model file. }
37+ {--without-controller : Generate the resource without the controller file. }
38+ {--without-form-request : Generate the resource without the form-request file. }
39+ {--without-views : Generate the resource without the views. }
3240 {--connection-name= : A specific connection name.}
3341 {--engine-name= : A specific engine name.}
34- {--layout-name=layouts.app : This will extract the validation into a request form class.}
42+ {--layout-name= : This will extract the validation into a request form class.}
3543 {--template-name= : The template name to use when generating the code.}
3644 {--table-exists : This option will attempt to fetch the field from existing database table.}
45+ {--routes-prefix=default-form : Prefix of the route group.}
3746 {--primary-key=id : The name of the primary key.}
3847 {--translation-for= : A comma seperated string of languages to create fields for.}
3948 {--form-request-directory= : The directory of the form-request.}
@@ -65,25 +74,32 @@ public function handle()
6574
6675 foreach ($ validInputs as $ validInput ) {
6776 $ this ->call (
68- 'create:resources ' ,
77+ 'create:scaffold ' ,
6978 [
7079 'model-name ' => $ validInput ->modelName ,
7180 '--controller-name ' => $ validInput ->controllerName ,
7281 '--controller-directory ' => $ validInput ->controllerDirectory ,
7382 '--controller-extends ' => $ validInput ->controllerExtends ,
7483 '--model-directory ' => $ validInput ->modelDirectory ,
84+ '--model-extends ' => $ validInput ->modelExtends ,
7585 '--views-directory ' => $ validInput ->viewsDirectory ,
7686 '--resource-file ' => $ validInput ->resourceFile ,
7787 '--routes-prefix ' => $ validInput ->prefix ,
7888 '--models-per-page ' => $ validInput ->perPage ,
7989 '--language-filename ' => $ validInput ->languageFileName ,
80- '--with-form-request ' => $ validInput ->formRequest ,
90+ '--with-form-request ' => $ validInput ->withFormRequest ,
91+ '--form-request-directory ' => $ validInput ->formRequestDirectory ,
8192 '--form-request-directory ' => $ validInput ->formRequestDirectory ,
8293 '--with-auth ' => $ validInput ->withAuth ,
8394 '--table-name ' => $ validInput ->table ,
8495 '--primary-key ' => $ validInput ->primaryKey ,
8596 '--with-soft-delete ' => $ validInput ->withSoftDelete ,
97+ '--without-model ' => $ validInput ->withoutModel ,
98+ '--without-controller ' => $ validInput ->withoutController ,
99+ '--without-form-request ' => $ validInput ->withoutFormRequest ,
100+ '--without-views ' => $ validInput ->withoutViews ,
86101 '--without-timestamps ' => $ validInput ->withoutTimeStamps ,
102+ '--without-languages ' => $ validInput ->withoutLanguages ,
87103 '--with-migration ' => $ validInput ->withMigration ,
88104 '--migration-class-name ' => $ validInput ->migrationClass ,
89105 '--connection-name ' => $ validInput ->connectionName ,
@@ -108,15 +124,15 @@ public function handle()
108124 * @param array $object
109125 * @param CrestApps\CodeGenerator\Models\ResourceInput $input
110126 *
111- * @return array of CrestApps\CodeGenerator\Models\ResourceInput
127+ * @return array of CrestApps\CodeGenerator\Models\ScaffoldInput
112128 */
113- protected function getValidInputs (array $ objects , ResourceInput $ originalInput )
129+ protected function getValidInputs (array $ objects , ScaffoldInput $ originalInput )
114130 {
115131 $ validInputs = [];
116132
117- foreach ($ objects as $ object ) {
133+ foreach ($ objects as $ obj ) {
118134 $ input = clone $ originalInput ;
119- $ object = (object ) $ object ;
135+ $ object = (object ) $ obj ;
120136
121137 if (!isset ($ object ->{'model-name ' })) {
122138 throw new Exception ('Each entry in the mapping file must a have value for model-name ' );
@@ -134,15 +150,22 @@ protected function getValidInputs(array $objects, ResourceInput $originalInput)
134150 $ input ->table = $ this ->getValue ($ object , 'table-name ' , $ madeupTableName );
135151 $ input ->viewsDirectory = $ this ->getValue ($ object , 'views-directory ' , $ input ->viewsDirectory );
136152 $ input ->perPage = $ this ->getValue ($ object , 'models-per-page ' , $ input ->perPage );
137- $ input ->formRequest = $ this ->getValue ($ object , 'with-form-request ' , $ input ->formRequest );
153+ $ input ->withFormRequest = $ this ->getValue ($ object , 'with-form-request ' , $ input ->withFormRequest );
138154 $ input ->controllerDirectory = $ this ->getValue ($ object , 'controller-directory ' , $ input ->controllerDirectory );
139- $ input ->controllerExtends = $ this ->getValue ($ object , 'controller-extends ' , $ input ->controllerExtends );
155+ $ input ->controllerExtends = $ this ->getValue ($ object , 'controller-extends ' , 'default-controller ' );
156+
157+ $ input ->modelExtends = $ this ->getValue ($ object , 'model-extends ' , 'default-model ' );
140158 $ input ->withMigration = $ this ->getValue ($ object , 'with-migration ' , $ input ->withMigration );
141159 $ input ->force = $ this ->getValue ($ object , 'force ' , $ input ->force );
142160 $ input ->modelDirectory = $ this ->getValue ($ object , 'model-directory ' , $ input ->modelDirectory );
143161 $ input ->primaryKey = $ this ->getValue ($ object , 'primary-key ' , $ input ->primaryKey );
144162 $ input ->withSoftDelete = $ this ->getValue ($ object , 'with-soft-delete ' , $ input ->withSoftDelete );
145163 $ input ->withoutTimeStamps = $ this ->getValue ($ object , 'without-timestamps ' , $ input ->withoutTimeStamps );
164+ $ input ->withoutLanguages = $ this ->getValue ($ object , 'without-languages ' , $ input ->withoutLanguages );
165+ $ input ->withoutModel = $ this ->getValue ($ object , 'without-model ' , $ input ->withoutModel );
166+ $ input ->withoutController = $ this ->getValue ($ object , 'without-controller ' , $ input ->withoutController );
167+ $ input ->withoutFormRequest = $ this ->getValue ($ object , 'without-form-request ' , $ input ->withoutFormRequest );
168+ $ input ->withoutViews = $ this ->getValue ($ object , 'without-views ' , $ input ->withoutViews );
146169 $ input ->migrationClass = $ this ->getValue ($ object , 'migration-class-name ' , $ input ->migrationClass );
147170 $ input ->connectionName = $ this ->getValue ($ object , 'connection-name ' , $ input ->connectionName );
148171 $ input ->engineName = $ this ->getValue ($ object , 'engine-name ' , $ input ->engineName );
@@ -182,7 +205,7 @@ protected function getMappingFile()
182205 */
183206 protected function getValue ($ object , $ name , $ default = null )
184207 {
185- if (isset ($ object->{ $ name} )) {
208+ if (property_exists ($ object, $ name )) {
186209 return $ object ->{$ name };
187210 }
188211
@@ -222,30 +245,37 @@ protected function validateField($fields)
222245 /**
223246 * Gets a clean user inputs.
224247 *
225- * @return CrestApps\CodeGenerator\Models\ResourceInput
248+ * @return CrestApps\CodeGenerator\Models\ScaffoldInput
226249 */
227250 protected function getCommandInput ()
228251 {
229- $ input = new ResourceInput (Config::getDefaultMapperFileName ());
252+ $ inputBase = new ScaffoldInputBase ('' );
253+
254+ $ inputBase ->perPage = intval ($ this ->option ('models-per-page ' ));
255+ $ inputBase ->withFormRequest = $ this ->option ('with-form-request ' );
256+ $ inputBase ->controllerDirectory = $ this ->option ('controller-directory ' );
257+ $ inputBase ->withMigration = $ this ->option ('with-migration ' );
258+ $ inputBase ->force = $ this ->option ('force ' );
259+ $ inputBase ->modelDirectory = $ this ->option ('model-directory ' );
260+ $ inputBase ->primaryKey = $ this ->option ('primary-key ' );
261+ $ inputBase ->withSoftDelete = $ this ->option ('with-soft-delete ' );
262+ $ inputBase ->connectionName = $ this ->option ('connection-name ' );
263+ $ inputBase ->engineName = $ this ->option ('engine-name ' );
264+ $ inputBase ->template = $ this ->getTemplateName ();
265+ $ inputBase ->tableExists = $ this ->option ('table-exists ' );
266+ $ inputBase ->translationFor = $ this ->option ('translation-for ' );
267+ $ inputBase ->withAuth = $ this ->option ('with-auth ' );
268+ $ inputBase ->formRequestDirectory = $ this ->option ('form-request-directory ' );
269+ $ inputBase ->withoutTimeStamps = $ this ->option ('without-timestamps ' );
270+ $ inputBase ->withoutLanguages = $ this ->option ('without-languages ' );
271+ $ inputBase ->withoutModel = $ this ->option ('without-model ' );
272+ $ inputBase ->withoutController = $ this ->option ('without-controller ' );
273+ $ inputBase ->withoutFormRequest = $ this ->option ('without-form-request ' );
274+ $ inputBase ->withoutViews = $ this ->option ('without-views ' );
275+
276+ $ input = new ScaffoldInput ($ inputBase );
230277 $ input ->viewsDirectory = trim ($ this ->option ('views-directory ' ));
231- $ input ->perPage = intval ($ this ->option ('models-per-page ' ));
232- $ input ->formRequest = $ this ->option ('with-form-request ' );
233- $ input ->controllerDirectory = $ this ->option ('controller-directory ' );
234- $ input ->controllerExtends = $ this ->option ('controller-extends ' ) ?: null ;
235- $ input ->withMigration = $ this ->option ('with-migration ' );
236- $ input ->force = $ this ->option ('force ' );
237- $ input ->modelDirectory = $ this ->option ('model-directory ' );
238- $ input ->primaryKey = $ this ->option ('primary-key ' );
239- $ input ->withSoftDelete = $ this ->option ('with-soft-delete ' );
240- $ input ->withoutTimeStamps = $ this ->option ('without-timestamps ' );
241- $ input ->connectionName = $ this ->option ('connection-name ' );
242- $ input ->engineName = $ this ->option ('engine-name ' );
243- $ input ->template = $ this ->getTemplateName ();
244278 $ input ->layoutName = $ this ->option ('layout-name ' ) ?: 'layouts.app ' ;
245- $ input ->tableExists = $ this ->option ('table-exists ' );
246- $ input ->translationFor = $ this ->option ('translation-for ' );
247- $ input ->withAuth = $ this ->option ('with-auth ' );
248- $ input ->formRequestDirectory = $ this ->option ('form-request-directory ' );
249279
250280 return $ input ;
251281 }
0 commit comments