mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2025-01-28 20:57:53 +03:00
added documentation
This commit is contained in:
parent
0b4f299142
commit
1b2f524683
493
README.md
493
README.md
@ -2,6 +2,495 @@
|
||||
|
||||
[![Build Status](https://travis-ci.org/webNeat/lumen-generators.svg?branch=master)](https://travis-ci.org/webNeat/lumen-generators)
|
||||
|
||||
A collection of generators for Lumen and Laravel 5.
|
||||
A collection of generators for Lumen and Laravel 5. Since Lumen comes
|
||||
|
||||
THIS PACKAGE IS UNDER LIVE CONSTRUCTION !
|
||||
## Why ?
|
||||
|
||||
I installed Lumen and wanted to use it to create a REST API (since this is the main usage of Lumen). But I didn't find commands which will speed up my workflow. That's why I created this package and included useful commands to build a RESTful API.
|
||||
|
||||
This packages was mainly built to be used with Lumen, but it should work fine with Laravel 5 too.
|
||||
|
||||
## Installation
|
||||
|
||||
Add the generators package to your composer.json by running the command:
|
||||
|
||||
`composer require wn/lumen-generators`
|
||||
|
||||
Then add the service provider in the file `app/Providers/AppServiceProvider.php`like the following:
|
||||
|
||||
```
|
||||
public function register()
|
||||
{
|
||||
if ($this->app->environment() == 'local') {
|
||||
$this->app->register('Wn\Generators\CommandsServiceProvider');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Don't forget to include the application service provider on your `bootstrap/app.php` and to enable Eloquent and Facades if you are using Lumen**
|
||||
|
||||
|
||||
If you run the command `php artisan list` you will see the list of added commands:
|
||||
|
||||
```
|
||||
wn
|
||||
wn:controller Generates RESTful controller using the RESTActions trait
|
||||
wn:controller:rest-actions Generates REST actions trait to use into controllers
|
||||
wn:migration Generates a migration to create a table with schema
|
||||
wn:model Generates a model class for a RESTfull resource
|
||||
wn:resource Generates a model, migration, controller and routes for RESTful resource
|
||||
wn:resources Generates multiple resources from a file
|
||||
wn:route Generates RESTful routes.
|
||||
```
|
||||
|
||||
## Quick Usage
|
||||
|
||||
To generate a RESTful resource for your application (model, migration, controller and RESTful routes), you simply need to run one single command. For example:
|
||||
|
||||
`php artisan wn:resource task "name;string;required;fillable project_id;integer:unsigned;numeric;fillable,key due;date;;date" --belongs-to=project`
|
||||
|
||||
will generate these files:
|
||||
|
||||
**app/Task.php**
|
||||
|
||||
```
|
||||
<?php namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Task extends Model {
|
||||
|
||||
protected $fillable = ["name", "project_id"];
|
||||
|
||||
protected $dates = ["due"];
|
||||
|
||||
public static $rules = [
|
||||
"name" => "required",
|
||||
"project_id" => "numeric",
|
||||
];
|
||||
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo("App\Project");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**app/Http/Controllers/RESTActions.php**
|
||||
|
||||
```
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
trait RESTActions {
|
||||
|
||||
protected $statusCodes = [
|
||||
'done' => 200,
|
||||
'created' => 201,
|
||||
'removed' => 204,
|
||||
'not_valid' => 400,
|
||||
'not_found' => 404,
|
||||
'conflict' => 409,
|
||||
'permissions' => 401
|
||||
];
|
||||
|
||||
public function all()
|
||||
{
|
||||
$m = self::MODEL;
|
||||
return $this->respond('done', $m::all());
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$model = $m::find($id);
|
||||
if(is_null($model)){
|
||||
return $this->respond('not_found');
|
||||
}
|
||||
return $this->respond('done', $model);
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$this->validate($request, $m::$rules);
|
||||
return $this->respond('created', $m::create($request->all()));
|
||||
}
|
||||
|
||||
public function put(Request $request, $id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$this->validate($request, $m::$rules);
|
||||
$model = $m::find($id);
|
||||
if(is_null($model)){
|
||||
return $this->respond('not_found');
|
||||
}
|
||||
$model->update($request->all());
|
||||
return $this->respond('done', $model);
|
||||
}
|
||||
|
||||
public function remove($id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
if(is_null($m::find($id))){
|
||||
return $this->respond('not_found');
|
||||
}
|
||||
$m::destroy($id);
|
||||
return $this->respond('removed');
|
||||
}
|
||||
|
||||
protected function respond($status, $data = [])
|
||||
{
|
||||
return response()->json($data, $this->statusCodes[$status]);
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
**app/Http/Controllers/TasksController.php**
|
||||
|
||||
```
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
|
||||
class TasksController extends Controller {
|
||||
|
||||
const MODEL = "App\Task";
|
||||
|
||||
use RESTActions;
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
**app/Http/routes.php**
|
||||
|
||||
```
|
||||
// These lignes will be added
|
||||
/**
|
||||
* Routes for resource task
|
||||
*/
|
||||
$app->get('task', 'TasksController@all');
|
||||
$app->get('task/{id}', 'TasksController@get');
|
||||
$app->post('task', 'TasksController@add');
|
||||
$app->put('task/{id}', 'TasksController@put');
|
||||
$app->delete('task/{id}', 'TasksController@remove');
|
||||
```
|
||||
|
||||
**database/migrations/date_time_create_tasks.php**
|
||||
|
||||
```
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTasksMigration extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tasks', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->integer('project_id')->unsigned();
|
||||
$table->date('due');
|
||||
$table->foreign('project_id')
|
||||
->references('id')
|
||||
->on('projects');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('tasks');
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Now simply run the migration and you are ready to go.
|
||||
|
||||
More then that, you can generate multiple resources with only one command ! [Click here to see an example](#multiple-resources-from-file)
|
||||
|
||||
## Detailed Usage
|
||||
|
||||
### Model Generator
|
||||
|
||||
The `wn:model` command is used to generate a model class based on Eloquent. It has the following syntax:
|
||||
|
||||
`wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--rules=...] [--path=...]`
|
||||
|
||||
- **name**: the name of the model.
|
||||
|
||||
`php artisan wn:model Task` generates the following:
|
||||
|
||||
```
|
||||
<?php namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Task extends Model {
|
||||
|
||||
protected $fillable = [];
|
||||
|
||||
protected $dates = [];
|
||||
|
||||
public static $rules = [
|
||||
// Validation rules
|
||||
];
|
||||
|
||||
// Relationships
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
- **--fillable**: the mass fillable fields of the model separated with commas.
|
||||
|
||||
`php artisan wn:model Task --fillable=name,title` gives:
|
||||
|
||||
```
|
||||
//...
|
||||
protected $fillable = ['name', 'title'];
|
||||
```
|
||||
|
||||
- **--dates**: the date fields of the model, these will be converted automatically to `Carbon` instances on retrieval.
|
||||
|
||||
`php artisan wn:model Task --dates=started_at,published_at` gives:
|
||||
|
||||
```
|
||||
//...
|
||||
protected $dates = ['started_at', 'published_at'];
|
||||
```
|
||||
|
||||
- **--path**: specifies the path where to store the model php file. This path is used to know the namespace of the model. The default value is "app".
|
||||
|
||||
`php artisan wn:model Task --path="app/Http/Models"` gives:
|
||||
|
||||
```
|
||||
<?php namespace App\Http\Models;
|
||||
//...
|
||||
```
|
||||
|
||||
- **--has-one**, **--has-many** and **--belongs-to**: the relationships of the model following the syntax `relation1:model1,relation2:model2,...`. If the `model` is missing, it will be deducted from the relation's name. If the `model` is given without a namespace, it will be considered having the same namespace as the model being generated.
|
||||
|
||||
`php artisan wn:model Task --has-many=accounts --belongs-to="owner:App\User" --has-one=number:Phone --path=tests/tmp` gives:
|
||||
|
||||
```
|
||||
//...
|
||||
public function accounts()
|
||||
{
|
||||
return $this->hasMany("Tests\\Tmp\\Account");
|
||||
}
|
||||
|
||||
public function owner()
|
||||
{
|
||||
return $this->belongsTo("App\\User");
|
||||
}
|
||||
|
||||
public function number()
|
||||
{
|
||||
return $this->hasOne("Tests\\Tmp\\Phone");
|
||||
}
|
||||
```
|
||||
|
||||
- **--rules**: specifies the validation rules of the model's fields. The syntax is `field1=rules1 field2=rules2 ...`.
|
||||
|
||||
`php artisan wn:model TestingModel --rules="name=required age=integer|min:13 email=email|unique:users,email_address"`` gives:
|
||||
|
||||
```
|
||||
// ...
|
||||
public static $rules = [
|
||||
"name" => "required",
|
||||
"age" => "integer|min:13",
|
||||
"email" => "email|unique:users,email_address",
|
||||
];
|
||||
```
|
||||
|
||||
### Migration Generator
|
||||
|
||||
The `wn:migration` command is used to generate a migration to create a table with schema. It has the following syntax:
|
||||
|
||||
`wn:migration table [--schema=...] [--keys=...] [--file=...]`
|
||||
|
||||
- **table**: the name of the table to create.
|
||||
|
||||
- **--file**: The migration file name. By default the name follows the patern `date_time_create_table_name.php`.
|
||||
|
||||
- **--schema**: the schema of the table using the syntax `field1:type.arg1,ag2:modifier1:modifier2.. field2:...`. The `type` could be `text`, `string.50`, `decimal.5,2` for example. Modifiers can be `unique` or `nullable` for example. [See documentation](http://laravel.com/docs/5.1/migrations#creating-columns) for the list of available types and modifiers.
|
||||
|
||||
`php artisan wn:migration tasks --schema="amount:decimal.5,2:after.'size':default.8 title:string:nullable"` gives:
|
||||
|
||||
```
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTasksMigration extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tasks', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->decimal('amount', 5, 2)->after('size')->default(8);
|
||||
$table->string('title')->nullable();
|
||||
// Constraints declaration
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('tasks');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- **--keys**: the foreign keys of the table following the syntax `field:column:table:on_delete:on_update ...`. The `column` is optional ("id" by default). The `table` is optional if the field follows the naming convention `singular_table_name_id`. `on_delete` and `on_update` are optional too.
|
||||
|
||||
`php artisan wn:migration tasks --keys="category_type_id user_id:identifier:members:cascade"` gives:
|
||||
|
||||
```
|
||||
//...
|
||||
$table->foreign('category_type_id')
|
||||
->references('id')
|
||||
->on('category_types');
|
||||
|
||||
$table->foreign('user_id')
|
||||
->references('identifier')
|
||||
->on('members')
|
||||
->onDelete('cascade');
|
||||
```
|
||||
|
||||
### Controller Generator
|
||||
|
||||
There are two commands for controllers. The first one is `wn:controller:rest-actions` which generates a trait used by all generated controllers. This trait includes the following methods:
|
||||
|
||||
- `all()` : returns all the model entries as JSON.
|
||||
|
||||
- `get($id)` : returns a specific model by id as JSON.
|
||||
|
||||
- `add(Request $request)` : adds a new model or returns validation errors as JSON.
|
||||
|
||||
- `put(Request $request, $id)` : updates a model or returns validation errors as JSON.
|
||||
|
||||
- `remove($id)` : removes an entry by id.
|
||||
|
||||
Note that the trait doesn't use the common used methods on Laravel (like index, store, ...) to avoid conflicts. Which enables you to use this trait with controllers you already have in your application.
|
||||
|
||||
The second command is `wn:controller` which actually generates the controller. The syntax of this command is `wn:controller model [--no-routes]`.
|
||||
|
||||
- **model**: Name of the model (with namespace if not `App`).
|
||||
|
||||
- **--no-routes**: Since routes are generated by default for the controller, this option is used to tell the generator "do not generate routes !".
|
||||
|
||||
`php artisan wn:controller Task --no-routes` gives:
|
||||
|
||||
|
||||
```
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
|
||||
class TasksController extends Controller {
|
||||
|
||||
const MODEL = "App\\Task";
|
||||
|
||||
use RESTActions;
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Routes Generator
|
||||
|
||||
The `wn:route` command is used to generate RESTfull routes for a controller. It has the following syntax:
|
||||
|
||||
`wn:route resource [--controller=...]`
|
||||
|
||||
- **resource**: the resource name to use in the URLs.
|
||||
|
||||
- **--controller**: the corresponding controller. If missing it's deducted from the resource name.
|
||||
|
||||
`php artisan wn:route project-type` gives the following routes:
|
||||
|
||||
```
|
||||
$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');
|
||||
```
|
||||
|
||||
### Resource Generator
|
||||
|
||||
The `wn:resource` command makes it very easy to generate a RESTful resource. It generates a model, migration, controller and routes. The syntax is : `wn:resource name fields [--has-many=...] [--has-one=...] [--belongs-to=...] [--migration-file=...]`
|
||||
|
||||
- **name**: the name of the resource used in the URLs and to determine the model, table and controller names.
|
||||
|
||||
- **fields**: specifies the fields of the resource along with schema and validation rules. It follows the syntax `name;schema;rules;tags ...`
|
||||
|
||||
- name: the name of the field
|
||||
|
||||
- schema: the schema following the syntax in the model generator. (note that the name is not part of the schema like on the model generator)
|
||||
|
||||
- rules: the validation rules
|
||||
|
||||
- tags: additional tags separated by commas. The possible tags are:
|
||||
|
||||
- `fillable`: add this field to the fillable array of the model.
|
||||
|
||||
- `date`: add this field to the dates array of the model.
|
||||
|
||||
- `key`: this field is a foreign key.
|
||||
|
||||
- **--has-one**, **--has-many** and **--belongs-to** are the same as for the `wn:model` command.
|
||||
|
||||
- **--migration-file**: passed to the `wn:migration` as the `--file` option.
|
||||
|
||||
### Multiple Resources From File
|
||||
|
||||
The `wn:resources` (note the "s" in "resources") command takes the generation process to an other level by parsing a file and generating multiple resources based on it. The syntax is `wn:resources filename`
|
||||
|
||||
The file given to the command should be a valid YAML file ( for the moment, support of other types like XML or JSON could be added in the future). An example is the following:
|
||||
|
||||
```
|
||||
---
|
||||
Store:
|
||||
hasMany: products
|
||||
fields:
|
||||
name:
|
||||
schema: string:50 unique
|
||||
rules: required|min:3
|
||||
tags: fillable
|
||||
Product:
|
||||
belongsTo: store
|
||||
fields:
|
||||
name:
|
||||
schema: string
|
||||
rules: required
|
||||
tags: fillable
|
||||
store_id:
|
||||
schema: integer unsigned
|
||||
rules: required numeric
|
||||
tags: fillable key
|
||||
desc:
|
||||
schema: text nullable
|
||||
tags: fillable
|
||||
published_at:
|
||||
schema: date
|
||||
rules: date
|
||||
tags: date fillable
|
||||
price:
|
||||
schema: 'decimal:5,2' # need quotes when using ','
|
||||
rules: numeric
|
||||
tags: fillable
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull requests are welcome :D
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTaskCategoriesMigration extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::create('task_categories', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name')->unique();
|
||||
$table->text('descr')->nullable();
|
||||
$table->integer('project_id');
|
||||
$table->timestamp('due');
|
||||
$table->foreign('project_id')
|
||||
->references('id')
|
||||
->on('projects');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('task_categories');
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTaskCategoriesMigration extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::create('task_categories', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name')->unique();
|
||||
$table->text('descr')->nullable();
|
||||
$table->integer('project_id');
|
||||
$table->timestamp('due');
|
||||
$table->foreign('project_id')
|
||||
->references('id')
|
||||
->on('projects');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('task_categories');
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTaskCategoriesMigration extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::create('task_categories', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name')->unique();
|
||||
$table->text('descr')->nullable();
|
||||
$table->integer('project_id');
|
||||
$table->timestamp('due');
|
||||
$table->foreign('project_id')
|
||||
->references('id')
|
||||
->on('projects');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('task_categories');
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
class ControllerCommand extends BaseCommand {
|
||||
|
||||
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';
|
||||
|
@ -10,6 +10,7 @@ class ResourceCommand extends BaseCommand {
|
||||
{--has-one= : hasOne relationships.}
|
||||
{--belongs-to= : belongsTo relationships.}
|
||||
{--migration-file= : the migration file name.}
|
||||
{--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}
|
||||
';
|
||||
|
||||
protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
|
||||
@ -62,7 +63,9 @@ class ResourceCommand extends BaseCommand {
|
||||
protected function parseFields()
|
||||
{
|
||||
$fields = $this->argument('fields');
|
||||
if(! $fields){
|
||||
if($this->option('parsed')){
|
||||
$this->fields = $fields;
|
||||
} else if(! $fields){
|
||||
$this->fields = [];
|
||||
} else {
|
||||
$this->fields = $this->getArgumentParser('fields')
|
||||
|
89
src/Commands/ResourcesCommand.php
Normal file
89
src/Commands/ResourcesCommand.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php namespace Wn\Generators\Commands;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
|
||||
class ResourcesCommand extends BaseCommand {
|
||||
|
||||
protected $signature = 'wn:resources
|
||||
{file : Path to the file containing resources declarations}';
|
||||
|
||||
protected $description = 'Generates multiple resources from a file';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$content = $this->fs->get($this->argument('file'));
|
||||
$content = Yaml::parse($content);
|
||||
|
||||
foreach ($content as $model => $i){
|
||||
$i = $this->getResourceParams($model, $i);
|
||||
|
||||
$this->call('wn:resource', [
|
||||
'name' => $i['name'],
|
||||
'fields' => $i['fields'],
|
||||
'--has-many' => $i['hasMany'],
|
||||
'--has-one' => $i['hasOne'],
|
||||
'--belongs-to' => $i['belongsTo']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getResourceParams($modelName, $i)
|
||||
{
|
||||
$i['name'] = snake_case($modelName);
|
||||
|
||||
foreach(['hasMany', 'hasOne', 'belongsTo'] as $relation){
|
||||
if(isset($i[$relation])){
|
||||
$i[$relation] = $this->convertArray($i[$relation], ' ', ',');
|
||||
} else {
|
||||
$i[$relation] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if($i['belongsTo']){
|
||||
$relations = $this->getArgumentParser('relations')->parse($i['belongsTo']);
|
||||
foreach ($relations as $relation){
|
||||
$foreignName = '';
|
||||
|
||||
if(! $relation['model']){
|
||||
$foreignName = snake_case($relation['name']) . '_id';
|
||||
} else {
|
||||
$names = array_reverse(explode("\\", $relation['model']));
|
||||
$foreignName = snake_case($names[0]) . '_id';
|
||||
}
|
||||
|
||||
$i['fields'][$foreignName] = [
|
||||
'schema' => 'integer',
|
||||
'tags' => 'key'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$fields = [];
|
||||
foreach($i['fields'] as $name => $value) {
|
||||
$value['name'] = $name;
|
||||
$fields[] = $this->serializeField($value);
|
||||
}
|
||||
$i['fields'] = implode(' ', $fields);
|
||||
|
||||
return $i;
|
||||
}
|
||||
|
||||
protected function serializeField($field)
|
||||
{
|
||||
$name = $field['name'];
|
||||
$schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':');
|
||||
$rules = (isset($field['rules'])) ? trim($field['rules']) : '';
|
||||
$tags = $this->convertArray($field['tags'], ' ', ',');
|
||||
|
||||
return "{$name};{$schema};{$rules};{$tags}";
|
||||
}
|
||||
|
||||
protected function convertArray($list, $old, $new)
|
||||
{
|
||||
return implode($new, array_filter(explode($old, $list), function($item){
|
||||
return !empty($item);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,7 @@ class CommandsServiceProvider extends ServiceProvider
|
||||
$this->registerRouteCommand();
|
||||
$this->registerMigrationCommand();
|
||||
$this->registerResourceCommand();
|
||||
$this->registerResourcesCommand();
|
||||
// $this->registerSeedCommand();
|
||||
// $this->registerTestCommand();
|
||||
}
|
||||
@ -81,4 +82,12 @@ class CommandsServiceProvider extends ServiceProvider
|
||||
|
||||
}
|
||||
|
||||
protected function registerResourcesCommand(){
|
||||
$this->app->singleton('command.wn.resources', function($app){
|
||||
return $app['Wn\Generators\Commands\ResourcesCommand'];
|
||||
});
|
||||
$this->commands('command.wn.resources');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user