From a2cf22d4261b4641e3ed55eab5d2e8cc1663a963 Mon Sep 17 00:00:00 2001 From: Josiah Dahl Date: Sun, 6 Aug 2017 16:45:16 -0700 Subject: [PATCH] Added Laravel Routes - New template - Command updates --- .gitignore | 2 ++ lumen-test/.gitignore | 4 +++- lumen-test/clean.sh | 8 ++++++++ lumen-test/routes/api.php | 7 +++++++ src/Commands/ControllerCommand.php | 5 ++++- src/Commands/ResourceCommand.php | 4 +++- src/Commands/ResourcesCommand.php | 5 ++++- src/Commands/RouteCommand.php | 12 ++++++++++-- templates/routes-laravel.wnt | 8 ++++++++ 9 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 lumen-test/routes/api.php create mode 100644 templates/routes-laravel.wnt diff --git a/.gitignore b/.gitignore index 7319a28..c1eb769 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ tests/_output/* lumen-test/app lumen-test/database lumen-test/tests/tmp + +.idea diff --git a/lumen-test/.gitignore b/lumen-test/.gitignore index edb739f..c6490f3 100644 --- a/lumen-test/.gitignore +++ b/lumen-test/.gitignore @@ -4,4 +4,6 @@ tests/_output/* composer.lock -tests/_output/* \ No newline at end of file +tests/_output/* + +codecept.phar diff --git a/lumen-test/clean.sh b/lumen-test/clean.sh index 569b693..f11634f 100755 --- a/lumen-test/clean.sh +++ b/lumen-test/clean.sh @@ -11,6 +11,14 @@ echo "welcome(); });" > app/Http/routes.php +echo " routes/api.php + # Controllers rm app/Http/Controllers/*.php 2> /dev/null echo "option('no-routes')){ $this->call('wn:route', [ 'resource' => snake_case($name, '-'), - '--controller' => $controller + '--controller' => $controller, + '--laravel' => $this->options('laravel') ]); } } diff --git a/src/Commands/ResourceCommand.php b/src/Commands/ResourceCommand.php index 8830da5..c4926fd 100644 --- a/src/Commands/ResourceCommand.php +++ b/src/Commands/ResourceCommand.php @@ -15,6 +15,7 @@ class ResourceCommand extends BaseCommand { {--path=app : where to store the model file.} {--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options} {--force= : override the existing files} + {--laravel= : Boolean (default false) Use Laravel style route definitions} '; protected $description = 'Generates a model, migration, controller and routes for RESTful resource'; @@ -66,7 +67,8 @@ class ResourceCommand extends BaseCommand { $this->call('wn:controller', [ 'model' => $modelName, '--force' => $this->option('force'), - '--no-routes' => false + '--no-routes' => false, + '--laravel' => $this->option('laravel') ]); // generating model factory diff --git a/src/Commands/ResourcesCommand.php b/src/Commands/ResourcesCommand.php index 8be23b9..51bd269 100644 --- a/src/Commands/ResourcesCommand.php +++ b/src/Commands/ResourcesCommand.php @@ -9,6 +9,8 @@ class ResourcesCommand extends BaseCommand { {file : Path to the file containing resources declarations} {--path=app : where to store the model files.} {--force= : override the existing files} + {--laravel= : Boolean (default false) Use Laravel style route definitions} + '; protected $description = 'Generates multiple resources from a file'; @@ -32,7 +34,8 @@ class ResourcesCommand extends BaseCommand { '--belongs-to' => $i['belongsTo'], '--belongs-to-many' => $i['belongsToMany'], '--path' => $this->option('path'), - '--force' => $this->option('force') + '--force' => $this->option('force'), + '--laravel' => $this->option('laravel') ]); } diff --git a/src/Commands/RouteCommand.php b/src/Commands/RouteCommand.php index da619bf..2fdf727 100644 --- a/src/Commands/RouteCommand.php +++ b/src/Commands/RouteCommand.php @@ -5,21 +5,29 @@ class RouteCommand extends BaseCommand { protected $signature = 'wn:route {resource : Name of the resource.} - {--controller= : Name of the RESTful controller.}'; + {--controller= : Name of the RESTful controller.} + {--laravel= : Boolean (default false) Use Laravel style route definitions + '; protected $description = 'Generates RESTful routes.'; public function handle() { $resource = $this->argument('resource'); + $laravelRoutes = $this->option('laravel'); + $templateFile = 'routes'; $routesPath = './routes/web.php'; + if ($laravelRoutes) { + $routesPath = './routes/api.php'; + $templateFile = 'routes-laravel'; + } if (! $this->fs->exists($routesPath)) $routesPath = './app/Http/routes.php'; $content = $this->fs->get($routesPath); - $content .= PHP_EOL . $this->getTemplate('routes') + $content .= PHP_EOL . $this->getTemplate($templateFile) ->with([ 'resource' => $resource, 'controller' => $this->getController() diff --git a/templates/routes-laravel.wnt b/templates/routes-laravel.wnt new file mode 100644 index 0000000..1c9c22d --- /dev/null +++ b/templates/routes-laravel.wnt @@ -0,0 +1,8 @@ +/** + * Routes for resource {{resource}} + */ +Route::get('{{resource}}', '{{controller}}@all'); +Route::get('{{resource}}/{id}', '{{controller}}@get'); +Route::post('{{resource}}', '{{controller}}@add'); +Route::put('{{resource}}/{id}', '{{controller}}@put'); +Route::delete('{{resource}}/{id}', '{{controller}}@remove');