diff --git a/src/CrudMake.php b/src/CrudMake.php index c794a68..89d44b5 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -40,6 +40,7 @@ class CrudMake extends Command /** * Construct CrudMake class + * * @param Filesystem $files Put generated file content to application file system */ public function __construct(Filesystem $files) @@ -127,6 +128,12 @@ class CrudMake extends Command ]; } + /** + * Get model path on storage + * + * @param string $modelName Input model name from command argument + * @return string Model path on storage + */ protected function getModelPath($modelName) { $inputName = explode('/', ucfirst($modelName)); @@ -135,6 +142,12 @@ class CrudMake extends Command return implode('/', $inputName); } + /** + * Get model namespace + * + * @param string $modelPath Model path + * @return string Model namespace + */ protected function getModelNamespace($modelPath) { $modelNamespace = str_replace('/', '\\', 'App/'.ucfirst($modelPath)); @@ -150,42 +163,4 @@ class CrudMake extends Command { return $this->files->exists(app_path($this->modelNames['model_name'].'.php')); } - - /** - * Make directory if the path is not exists - * @param string $path Absolute path of targetted directory - * @return string Absolute path - */ - protected function makeDirectory($path) - { - if (! $this->files->isDirectory($path)) { - $this->files->makeDirectory($path, 0777, true, true); - } - - return $path; - } - - /** - * Replace all string of model names - * - * @param string $stub String of file or class stub with default content - * @return string Replaced content - */ - protected function replaceStubString($stub) - { - return str_replace($this->stubModelNames, $this->modelNames, $stub); - } - - /** - * Generate file on filesystem - * @param string $path Absoute path of file - * @param string $content Generated file content - * @return string Absolute path of file - */ - protected function generateFile($path, $content) - { - $this->files->put($path, $content); - - return $path; - } } diff --git a/src/Generators/BaseGenerator.php b/src/Generators/BaseGenerator.php index 8d864c0..32e3f0f 100644 --- a/src/Generators/BaseGenerator.php +++ b/src/Generators/BaseGenerator.php @@ -44,37 +44,11 @@ abstract class BaseGenerator $this->command = $command; - $this->getModelNames(); + $this->modelNames = $this->command->modelNames; $this->getStubModelNames(); } /** - * Generate class properties for model names in different usage - * - * @return array - */ - public function getModelNames($modelName = null) - { - $modelName = is_null($modelName) ? $this->command->argument('name') : $modelName; - $model_name = ucfirst(class_basename($modelName)); - $plural_model_name = str_plural($model_name); - $modelPath = $this->getModelPath($modelName); - $modelNamespace = $this->getModelNamespace($modelPath); - - return $this->modelNames = [ - 'model_namespace' => $modelNamespace, - 'full_model_name' => $modelNamespace.'\\'.$model_name, - 'plural_model_name' => $plural_model_name, - 'model_name' => $model_name, - 'table_name' => snake_case($plural_model_name), - 'lang_name' => snake_case($model_name), - 'collection_model_var_name' => camel_case($plural_model_name), - 'single_model_var_name' => camel_case($model_name), - 'model_path' => $modelPath, - ]; - } - - /** * Get stub's model names * * @return array @@ -144,23 +118,4 @@ abstract class BaseGenerator { return str_replace($this->stubModelNames, $this->command->modelNames, $stub); } - - /** - * Get model path on storage - * @param string $modelName Input model name from command argument - * @return string Model path on storage - */ - protected function getModelPath($modelName) - { - $inputName = explode('/', ucfirst($modelName)); - array_pop($inputName); - - return implode('/', $inputName); - } - - protected function getModelNamespace($modelPath) - { - $modelNamespace = str_replace('/', '\\', 'App/'.ucfirst($modelPath)); - return $modelNamespace == 'App\\' ? 'App' : $modelNamespace; - } -} \ No newline at end of file +} diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index 819ca01..f044063 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -34,7 +34,6 @@ class ControllerGenerator extends BaseGenerator $controllerFileContent = $this->replaceStubString($stub); if (! is_null($parentName = $this->command->option('parent'))) { - $searches = [ 'App\Http\Controllers;', "use {$this->modelNames['full_model_name']};\n" @@ -54,4 +53,4 @@ class ControllerGenerator extends BaseGenerator return $controllerFileContent; } -} \ No newline at end of file +} diff --git a/src/Generators/FeatureTestGenerator.php b/src/Generators/FeatureTestGenerator.php index bc49856..dca3235 100644 --- a/src/Generators/FeatureTestGenerator.php +++ b/src/Generators/FeatureTestGenerator.php @@ -17,7 +17,6 @@ class FeatureTestGenerator extends BaseGenerator $featureTestPath = $this->makeDirectory(base_path('tests/Feature')); $this->generateFile("{$featureTestPath}/Manage{$this->modelNames['plural_model_name']}Test.php", $this->getContent()); $this->command->info('Manage'.$this->modelNames['plural_model_name'].'Test generated.'); - } /** @@ -57,4 +56,4 @@ class FeatureTestGenerator extends BaseGenerator { return $this->files->get(__DIR__.'/../stubs/test-browserkit-base-class.stub'); } -} \ No newline at end of file +} diff --git a/src/Generators/FormViewGenerator.php b/src/Generators/FormViewGenerator.php index fb47157..52dc6ed 100644 --- a/src/Generators/FormViewGenerator.php +++ b/src/Generators/FormViewGenerator.php @@ -27,4 +27,4 @@ class FormViewGenerator extends BaseGenerator $stub = $this->files->get(__DIR__.'/../stubs/view-forms.stub'); return $this->replaceStubString($stub); } -} \ No newline at end of file +} diff --git a/src/Generators/IndexViewGenerator.php b/src/Generators/IndexViewGenerator.php index 6cda00e..682c66f 100644 --- a/src/Generators/IndexViewGenerator.php +++ b/src/Generators/IndexViewGenerator.php @@ -27,4 +27,4 @@ class IndexViewGenerator extends BaseGenerator $stub = $this->files->get(__DIR__.'/../stubs/view-index.stub'); return $this->replaceStubString($stub); } -} \ No newline at end of file +} diff --git a/src/Generators/LangFileGenerator.php b/src/Generators/LangFileGenerator.php index d0d0e93..25e23d8 100644 --- a/src/Generators/LangFileGenerator.php +++ b/src/Generators/LangFileGenerator.php @@ -61,4 +61,4 @@ class LangFileGenerator extends BaseGenerator { return $this->files->get(__DIR__.'/../stubs/lang-app.stub'); } -} \ No newline at end of file +} diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php index 8644841..a7e03a6 100644 --- a/src/Generators/MigrationGenerator.php +++ b/src/Generators/MigrationGenerator.php @@ -31,4 +31,4 @@ class MigrationGenerator extends BaseGenerator $stub = $this->files->get(__DIR__.'/../stubs/migration-create.stub'); return $this->replaceStubString($stub); } -} \ No newline at end of file +} diff --git a/src/Generators/ModelFactoryGenerator.php b/src/Generators/ModelFactoryGenerator.php index bb9ec9a..3270218 100644 --- a/src/Generators/ModelFactoryGenerator.php +++ b/src/Generators/ModelFactoryGenerator.php @@ -30,4 +30,4 @@ class ModelFactoryGenerator extends BaseGenerator $stub = $this->files->get(__DIR__.'/../stubs/model-factory.stub'); return $this->replaceStubString($stub); } -} \ No newline at end of file +} diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index b18e611..f55a2e8 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -28,4 +28,4 @@ class ModelGenerator extends BaseGenerator $stub = $this->files->get(__DIR__.'/../stubs/model.stub'); return $this->replaceStubString($stub); } -} \ No newline at end of file +} diff --git a/src/Generators/ModelTestGenerator.php b/src/Generators/ModelTestGenerator.php index 5226121..09c827a 100644 --- a/src/Generators/ModelTestGenerator.php +++ b/src/Generators/ModelTestGenerator.php @@ -25,4 +25,4 @@ class ModelTestGenerator extends BaseGenerator $stub = $this->files->get(__DIR__.'/../stubs/test-unit.stub'); return $this->replaceStubString($stub); } -} \ No newline at end of file +} diff --git a/src/Generators/WebRouteGenerator.php b/src/Generators/WebRouteGenerator.php index 46400cc..63548bc 100644 --- a/src/Generators/WebRouteGenerator.php +++ b/src/Generators/WebRouteGenerator.php @@ -28,7 +28,6 @@ class WebRouteGenerator extends BaseGenerator $webRouteFileContent = $this->replaceStubString($stub); if (! is_null($parentName = $this->command->option('parent'))) { - $pluralModelName = $this->modelNames['plural_model_name']; $webRouteFileContent = str_replace( @@ -59,4 +58,4 @@ class WebRouteGenerator extends BaseGenerator return $routeDirPath.'/'.$filename; } -} \ No newline at end of file +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 9c62689..295c2f3 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -20,6 +20,6 @@ class ServiceProvider extends BaseServiceProvider public function boot() { - + // } }