mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2025-01-28 12:57:53 +03:00
wn:route command added and wn:controller command modified
This commit is contained in:
parent
6528a95f74
commit
df6abe636c
24
formats/schemas.json
Normal file
24
formats/schemas.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"type": "array",
|
||||||
|
"separator": " ",
|
||||||
|
"fields": {
|
||||||
|
"type": "array",
|
||||||
|
"separator": ":",
|
||||||
|
"fields": {
|
||||||
|
"type": "object",
|
||||||
|
"separator": ".",
|
||||||
|
"fields": [
|
||||||
|
"name",
|
||||||
|
{
|
||||||
|
"name": "args",
|
||||||
|
"type": "array",
|
||||||
|
"separator": ",",
|
||||||
|
"default": [],
|
||||||
|
"fields": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,6 @@
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$app->get('/', function () use ($app) {
|
$app->get("/", function () use ($app) {
|
||||||
return $app->welcome();
|
return $app->welcome();
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
$I = new AcceptanceTester($scenario);
|
$I = new AcceptanceTester($scenario);
|
||||||
|
|
||||||
$I->wantTo('generate a RESTful controller with short model name');
|
$I->wantTo('generate a RESTful controller with short model name');
|
||||||
$I->runShellCommand('php artisan wn:controller Test');
|
$I->runShellCommand('php artisan wn:controller Test --no-routes');
|
||||||
$I->seeInShellOutput('TestsController generated');
|
$I->seeInShellOutput('TestsController generated');
|
||||||
$I->seeFileFound('./app/Http/Controllers/TestsController.php');
|
$I->seeFileFound('./app/Http/Controllers/TestsController.php');
|
||||||
$I->openFile('./app/Http/Controllers/TestsController.php');
|
$I->openFile('./app/Http/Controllers/TestsController.php');
|
||||||
@ -19,7 +19,7 @@ class TestsController extends Controller {
|
|||||||
');
|
');
|
||||||
$I->deleteFile('./app/Http/Controllers/TestsController.php');
|
$I->deleteFile('./app/Http/Controllers/TestsController.php');
|
||||||
|
|
||||||
$I->wantTo('generate a RESTful controller with full model name');
|
$I->wantTo('generate a RESTful controller with full model name and routes');
|
||||||
$I->runShellCommand('php artisan wn:controller "App\Models\Category"');
|
$I->runShellCommand('php artisan wn:controller "App\Models\Category"');
|
||||||
$I->seeInShellOutput('CategoriesController generated');
|
$I->seeInShellOutput('CategoriesController generated');
|
||||||
$I->seeFileFound('./app/Http/Controllers/CategoriesController.php');
|
$I->seeFileFound('./app/Http/Controllers/CategoriesController.php');
|
||||||
@ -36,3 +36,28 @@ class CategoriesController extends Controller {
|
|||||||
}
|
}
|
||||||
');
|
');
|
||||||
$I->deleteFile('./app/Http/Controllers/CategoriesController.php');
|
$I->deleteFile('./app/Http/Controllers/CategoriesController.php');
|
||||||
|
$I->openFile('./app/Http/routes.php');
|
||||||
|
$I->seeInThisFile("
|
||||||
|
\$app->get('category', 'CategoriesController@all');
|
||||||
|
\$app->get('category/{id}', 'CategoriesController@get');
|
||||||
|
\$app->post('category', 'CategoriesController@add');
|
||||||
|
\$app->put('category/{id}', 'CategoriesController@put');
|
||||||
|
\$app->delete('category/{id}', 'CategoriesController@remove');
|
||||||
|
");
|
||||||
|
$I->writeToFile('./app/Http/routes.php', '<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here is where you can register all of the routes for an application.
|
||||||
|
| It is a breeze. Simply tell Lumen the URIs it should respond to
|
||||||
|
| and give it the Closure to call when that URI is requested.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app->get("/", function () use ($app) {
|
||||||
|
return $app->welcome();
|
||||||
|
});
|
||||||
|
');
|
61
lumen-test/tests/acceptance/RouteCommandCept.php
Normal file
61
lumen-test/tests/acceptance/RouteCommandCept.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
$I = new AcceptanceTester($scenario);
|
||||||
|
|
||||||
|
$I->wantTo('generate RESTful routes for a resource with default controller');
|
||||||
|
$I->runShellCommand('php artisan wn:route project-type');
|
||||||
|
$I->seeInShellOutput('project-type routes generated');
|
||||||
|
$I->openFile('./app/Http/routes.php');
|
||||||
|
$I->seeInThisFile("
|
||||||
|
\$app->get('project-type', 'ProjectTypesController@all');
|
||||||
|
\$app->get('project-type/{id}', 'ProjectTypesController@get');
|
||||||
|
\$app->post('project-type', 'ProjectTypesController@add');
|
||||||
|
\$app->put('project-type/{id}', 'ProjectTypesController@put');
|
||||||
|
\$app->delete('project-type/{id}', 'ProjectTypesController@remove');
|
||||||
|
");
|
||||||
|
$I->writeToFile('./app/Http/routes.php', '<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here is where you can register all of the routes for an application.
|
||||||
|
| It is a breeze. Simply tell Lumen the URIs it should respond to
|
||||||
|
| and give it the Closure to call when that URI is requested.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app->get("/", function () use ($app) {
|
||||||
|
return $app->welcome();
|
||||||
|
});
|
||||||
|
');
|
||||||
|
|
||||||
|
|
||||||
|
$I->wantTo('generate RESTful routes for a resource with custom controller');
|
||||||
|
$I->runShellCommand('php artisan wn:route foo --controller=customController');
|
||||||
|
$I->seeInShellOutput('foo routes generated');
|
||||||
|
$I->openFile('./app/Http/routes.php');
|
||||||
|
$I->seeInThisFile("
|
||||||
|
\$app->get('foo', 'customController@all');
|
||||||
|
\$app->get('foo/{id}', 'customController@get');
|
||||||
|
\$app->post('foo', 'customController@add');
|
||||||
|
\$app->put('foo/{id}', 'customController@put');
|
||||||
|
\$app->delete('foo/{id}', 'customController@remove');
|
||||||
|
");
|
||||||
|
$I->writeToFile('./app/Http/routes.php', '<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here is where you can register all of the routes for an application.
|
||||||
|
| It is a breeze. Simply tell Lumen the URIs it should respond to
|
||||||
|
| and give it the Closure to call when that URI is requested.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app->get("/", function () use ($app) {
|
||||||
|
return $app->welcome();
|
||||||
|
});
|
||||||
|
');
|
@ -4,7 +4,8 @@
|
|||||||
class ControllerCommand extends BaseCommand {
|
class ControllerCommand extends BaseCommand {
|
||||||
|
|
||||||
protected $signature = 'wn:controller
|
protected $signature = 'wn:controller
|
||||||
{model : Name of the model (with namespace if not App;}';
|
{model : Name of the model (with namespace if not App;)}
|
||||||
|
{--no-routes= : without routes}';
|
||||||
|
|
||||||
protected $description = 'Generates RESTful controller using the RESTActions trait';
|
protected $description = 'Generates RESTful controller using the RESTActions trait';
|
||||||
|
|
||||||
@ -19,17 +20,24 @@ class ControllerCommand extends BaseCommand {
|
|||||||
$name = explode("\\", $model);
|
$name = explode("\\", $model);
|
||||||
$name = $name[count($name) - 1];
|
$name = $name[count($name) - 1];
|
||||||
}
|
}
|
||||||
$name = ucwords(str_plural($name));
|
$controller = ucwords(str_plural($name)) . 'Controller';
|
||||||
$content = $this->getTemplate('controller')
|
$content = $this->getTemplate('controller')
|
||||||
->with([
|
->with([
|
||||||
'name' => $name,
|
'name' => $controller,
|
||||||
'model' => $model
|
'model' => $model
|
||||||
])
|
])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->save($content, "./app/Http/Controllers/{$name}Controller.php");
|
$this->save($content, "./app/Http/Controllers/{$controller}.php");
|
||||||
|
|
||||||
$this->info("{$name}Controller generated !");
|
$this->info("{$controller} generated !");
|
||||||
|
|
||||||
|
if(! $this->option('no-routes')){
|
||||||
|
$this->call('wn:route', [
|
||||||
|
'resource' => snake_case($name, '-'),
|
||||||
|
'--controller' => $controller
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
<?php namespace Wn\Generators\Commands;
|
||||||
|
|
||||||
|
|
||||||
|
class RouteCommand extends BaseCommand {
|
||||||
|
|
||||||
|
protected $signature = 'wn:route
|
||||||
|
{resource : Name of the resource.}
|
||||||
|
{--controller= : Name of the RESTful controller.}';
|
||||||
|
|
||||||
|
protected $description = 'Generates RESTful routes.';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$resource = $this->argument('resource');
|
||||||
|
|
||||||
|
$content = $this->fs->get('./app/Http/routes.php');
|
||||||
|
|
||||||
|
$content .= PHP_EOL . $this->getTemplate('routes')
|
||||||
|
->with([
|
||||||
|
'resource' => $resource,
|
||||||
|
'controller' => $this->getController()
|
||||||
|
])
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$this->save($content, './app/Http/routes.php');
|
||||||
|
|
||||||
|
$this->info("{$resource} routes generated !");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getController()
|
||||||
|
{
|
||||||
|
$controller = $this->option('controller');
|
||||||
|
if(! $controller){
|
||||||
|
$controller = ucwords(str_plural(camel_case($this->argument('resource')))) . 'Controller';
|
||||||
|
}
|
||||||
|
return $controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,9 +10,9 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
$this->registerModelCommand();
|
$this->registerModelCommand();
|
||||||
$this->registerControllerRestActionsCommand();
|
$this->registerControllerRestActionsCommand();
|
||||||
$this->registerControllerCommand();
|
$this->registerControllerCommand();
|
||||||
|
$this->registerRouteCommand();
|
||||||
// $this->registerMigrationCommand();
|
// $this->registerMigrationCommand();
|
||||||
// $this->registerSeedCommand();
|
// $this->registerSeedCommand();
|
||||||
// $this->registerRouteCommand();
|
|
||||||
// $this->registerTestCommand();
|
// $this->registerTestCommand();
|
||||||
// $this->registerResourceCommand();
|
// $this->registerResourceCommand();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php namespace App\Http\Controllers;
|
<?php namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
|
||||||
class {{name}}Controller extends Controller {
|
class {{name}} extends Controller {
|
||||||
|
|
||||||
const MODEL = "{{model}}";
|
const MODEL = "{{model}}";
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Routes for resource {{resource}}
|
* Routes for resource {{resource}}
|
||||||
*/
|
*/
|
||||||
$app->get({{resource}}, '{{controller}}@all');
|
$app->get('{{resource}}', '{{controller}}@all');
|
||||||
$app->get({{resource}}.'/{id}', '{{controller}}@get');
|
$app->get('{{resource}}/{id}', '{{controller}}@get');
|
||||||
$app->post({{resource}}, '{{controller}}@add');
|
$app->post('{{resource}}', '{{controller}}@add');
|
||||||
$app->put({{resource}}.'/{id}', '{{controller}}@put');
|
$app->put('{{resource}}/{id}', '{{controller}}@put');
|
||||||
$app->delete({{resource}}.'/{id}', '{{controller}}@remove');
|
$app->delete('{{resource}}/{id}', '{{controller}}@remove');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user