mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2024-12-27 06:25:28 +03:00
Added Laravel Routes
- New template - Command updates
This commit is contained in:
parent
dafa7f2f22
commit
a2cf22d426
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ tests/_output/*
|
|||||||
lumen-test/app
|
lumen-test/app
|
||||||
lumen-test/database
|
lumen-test/database
|
||||||
lumen-test/tests/tmp
|
lumen-test/tests/tmp
|
||||||
|
|
||||||
|
.idea
|
||||||
|
2
lumen-test/.gitignore
vendored
2
lumen-test/.gitignore
vendored
@ -5,3 +5,5 @@ tests/_output/*
|
|||||||
|
|
||||||
composer.lock
|
composer.lock
|
||||||
tests/_output/*
|
tests/_output/*
|
||||||
|
|
||||||
|
codecept.phar
|
||||||
|
@ -11,6 +11,14 @@ echo "<?php
|
|||||||
return \$app->welcome();
|
return \$app->welcome();
|
||||||
});" > app/Http/routes.php
|
});" > app/Http/routes.php
|
||||||
|
|
||||||
|
echo "<?php
|
||||||
|
/*
|
||||||
|
|------------------------------------------
|
||||||
|
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|
||||||
|
|------------------------------------------
|
||||||
|
*/
|
||||||
|
" > routes/api.php
|
||||||
|
|
||||||
# Controllers
|
# Controllers
|
||||||
rm app/Http/Controllers/*.php 2> /dev/null
|
rm app/Http/Controllers/*.php 2> /dev/null
|
||||||
echo "<?php
|
echo "<?php
|
||||||
|
7
lumen-test/routes/api.php
Normal file
7
lumen-test/routes/api.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
|------------------------------------------
|
||||||
|
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|
||||||
|
|------------------------------------------
|
||||||
|
*/
|
||||||
|
|
@ -7,6 +7,8 @@ class ControllerCommand extends BaseCommand {
|
|||||||
{model : Name of the model (with namespace if not App)}
|
{model : Name of the model (with namespace if not App)}
|
||||||
{--no-routes= : without routes}
|
{--no-routes= : without routes}
|
||||||
{--force= : override the existing files}
|
{--force= : override the existing files}
|
||||||
|
{--laravel= : Boolean (default false) Use Laravel style route definitions}
|
||||||
|
|
||||||
';
|
';
|
||||||
|
|
||||||
protected $description = 'Generates RESTful controller using the RESTActions trait';
|
protected $description = 'Generates RESTful controller using the RESTActions trait';
|
||||||
@ -35,7 +37,8 @@ class ControllerCommand extends BaseCommand {
|
|||||||
if(! $this->option('no-routes')){
|
if(! $this->option('no-routes')){
|
||||||
$this->call('wn:route', [
|
$this->call('wn:route', [
|
||||||
'resource' => snake_case($name, '-'),
|
'resource' => snake_case($name, '-'),
|
||||||
'--controller' => $controller
|
'--controller' => $controller,
|
||||||
|
'--laravel' => $this->options('laravel')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ class ResourceCommand extends BaseCommand {
|
|||||||
{--path=app : where to store the model file.}
|
{--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}
|
{--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}
|
{--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';
|
protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
|
||||||
@ -66,7 +67,8 @@ class ResourceCommand extends BaseCommand {
|
|||||||
$this->call('wn:controller', [
|
$this->call('wn:controller', [
|
||||||
'model' => $modelName,
|
'model' => $modelName,
|
||||||
'--force' => $this->option('force'),
|
'--force' => $this->option('force'),
|
||||||
'--no-routes' => false
|
'--no-routes' => false,
|
||||||
|
'--laravel' => $this->option('laravel')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// generating model factory
|
// generating model factory
|
||||||
|
@ -9,6 +9,8 @@ class ResourcesCommand extends BaseCommand {
|
|||||||
{file : Path to the file containing resources declarations}
|
{file : Path to the file containing resources declarations}
|
||||||
{--path=app : where to store the model files.}
|
{--path=app : where to store the model files.}
|
||||||
{--force= : override the existing files}
|
{--force= : override the existing files}
|
||||||
|
{--laravel= : Boolean (default false) Use Laravel style route definitions}
|
||||||
|
|
||||||
';
|
';
|
||||||
|
|
||||||
protected $description = 'Generates multiple resources from a file';
|
protected $description = 'Generates multiple resources from a file';
|
||||||
@ -32,7 +34,8 @@ class ResourcesCommand extends BaseCommand {
|
|||||||
'--belongs-to' => $i['belongsTo'],
|
'--belongs-to' => $i['belongsTo'],
|
||||||
'--belongs-to-many' => $i['belongsToMany'],
|
'--belongs-to-many' => $i['belongsToMany'],
|
||||||
'--path' => $this->option('path'),
|
'--path' => $this->option('path'),
|
||||||
'--force' => $this->option('force')
|
'--force' => $this->option('force'),
|
||||||
|
'--laravel' => $this->option('laravel')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,21 +5,29 @@ class RouteCommand extends BaseCommand {
|
|||||||
|
|
||||||
protected $signature = 'wn:route
|
protected $signature = 'wn:route
|
||||||
{resource : Name of the resource.}
|
{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.';
|
protected $description = 'Generates RESTful routes.';
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$resource = $this->argument('resource');
|
$resource = $this->argument('resource');
|
||||||
|
$laravelRoutes = $this->option('laravel');
|
||||||
|
$templateFile = 'routes';
|
||||||
|
|
||||||
$routesPath = './routes/web.php';
|
$routesPath = './routes/web.php';
|
||||||
|
if ($laravelRoutes) {
|
||||||
|
$routesPath = './routes/api.php';
|
||||||
|
$templateFile = 'routes-laravel';
|
||||||
|
}
|
||||||
if (! $this->fs->exists($routesPath))
|
if (! $this->fs->exists($routesPath))
|
||||||
$routesPath = './app/Http/routes.php';
|
$routesPath = './app/Http/routes.php';
|
||||||
|
|
||||||
$content = $this->fs->get($routesPath);
|
$content = $this->fs->get($routesPath);
|
||||||
|
|
||||||
$content .= PHP_EOL . $this->getTemplate('routes')
|
$content .= PHP_EOL . $this->getTemplate($templateFile)
|
||||||
->with([
|
->with([
|
||||||
'resource' => $resource,
|
'resource' => $resource,
|
||||||
'controller' => $this->getController()
|
'controller' => $this->getController()
|
||||||
|
8
templates/routes-laravel.wnt
Normal file
8
templates/routes-laravel.wnt
Normal file
@ -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');
|
Loading…
Reference in New Issue
Block a user