Skip to content

Commit 948e880

Browse files
authored
Merge pull request #12 from webfactor/3.0
3.0
2 parents 1f7f343 + 536718d commit 948e880

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1398
-1002
lines changed

CHANGELOG.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,37 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
2121
### Security
2222
- Nothing
2323

24+
## 3.0.0 - 2018-06-24 - Complete Refactoring
25+
26+
The Refactoring is supposed to provide new functions more easily in the future.
27+
28+
Attention: `schema` has been changed and only registered FieldTypes (see config-file) will be parsed. There are only a few FieldTypes available at the moment, more will come soon.
29+
30+
### Added
31+
32+
- `AddToGitService`: using `--git` in command will add all files to git
33+
34+
### Changed
35+
36+
- The parsing of `--schema=""` is now a bit different, but much more powerful. Please see Readme for further information
37+
- Naming for each service is handled by dedicated classes and can be accessed everywhere (e.g. name of Model inside a CrudController)
38+
39+
### Removed
40+
41+
- additional commands which are now integrated in the corresponding services
42+
43+
## 2.1.0 - 2018-03-30 (for Backpack Base v0.9)
44+
45+
### Added
46+
- `SidebarService` adds an entry to your sidebar
47+
48+
### Changed
49+
- `RouteService` now uses `routes/backpack/custom.php
50+
2451
## 2.0.0 - 2018-03-23
2552

2653
### Added
27-
- `LanguageService` generates models.php translation file (if not exists) and fill singular/plural translation
54+
- `LanguageFileService` generates models.php translation file (if not exists) and fill singular/plural translation
2855
- `OpenIdeService` opens all generated file with PhpStorm if command is called with `--ide={ide}`
2956
- `RouteService` adds Backpack Crud route to admin.php
3057

README.md

Lines changed: 103 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,124 @@ composer require --dev webfactor/laravel-generators
2323
## Usage
2424

2525
``` bash
26-
php artisan make:entity {entity_name} {--schema=} {--ide=}
26+
php artisan make:entity {entity_name} {--schema=} {--migrate} {--ide=} {--git}
2727
```
2828

29-
`--schema` currently uses syntax from [Laravel 5 Extended Generators](https://github.com/laracasts/Laravel-5-Generators-Extended) (this will be slightly changed in upcoming v3.0 to provide an extended functionality)
29+
- `entity_name`: Recommendation: use *singular* for entity. see "[Naming](#naming)" for more information
30+
- `--schema=`: Here you can provide a [schema-String](#schema)
31+
- `--migrate`: will automatically call `php artisan migrate` after creating the migration file
32+
- `--ide=`: will open all files in your prefered [IDE](#open-files-in-ide)
33+
- `--git`: will add all files to [git](#add-files-to-git)
3034

31-
Use *singular* for entity. This will automatically create (while respecting our internal naming conventions):
3235

33-
* Migration
34-
* Factory
35-
* Seeder
36-
* Backpack CRUD (modified Backpack Generator):
37-
* Model (incl. `$fillable`)
38-
* Request (incl. `rules()`)
39-
* Controller (incl. CrudColumns and CrudFields, basic for now)
40-
* Language File
41-
* Route to Backpack CRUD in admin.php
36+
If you want to add Services, Naming classes, Field Types, or IDE Opener you have to publish the config-file:
4237

43-
### Open files in IDE
38+
``` bash
39+
php artisan vendor:publish --provider="Webfactor\Laravel\Generators\GeneratorsServiceProvider"
40+
```
41+
42+
## Services
43+
44+
All Services defined in the config file have to implement `Webfactor\Laravel\Generators\Contracts\ServiceInterface` and will then be called in the given order.
45+
46+
### Included Services
47+
48+
Can be removed or extended by publishing config file:
49+
50+
- `MigrationService`
51+
- `FactoryService`
52+
- `SeederService`
53+
- Backpack CRUD:
54+
- `BackpackCrudModelService` (incl. `$fillable`)
55+
- `BackpackCrudRequestService` (incl. `rules()`)
56+
- `BackpackCrudControllerService` (incl. CrudColumns and CrudFields, more coming soon)
57+
- `SidebarService`
58+
- `LanguageFileService`
59+
- `RouteFileService`
60+
61+
### Always available (activated by option):
4462

45-
With `{--ide=}` option you can define your preferred IDE to open all automatically generated files. This package comes with an implementation for PhpStorm (`Webfactor\Laravel\Generators\Recipes\PhpStormOpener`) which is defined in `generators.php`. The keys in the `ides`-Array are possible values for the command option. You can add other IDE-Opener classes, they have to implement `Webfactor\Laravel\Generators\Contracts\OpenInIdeInterface`.
63+
- `OpenIdeService`
64+
- `AddToGitService`
4665

47-
In your service class you have to define the path to the file generated by this service. Then add `$this->addLatestFileToIdeStack();` and all files of the stack will be opened by `Webfactor\Laravel\Generators\Services\OpenIdeService` (should be placed at the end of the `services`-array in `generators.php`)
66+
## Schema
67+
68+
The intention of this package concerning Laravel Backpack CRUD is to provide an easy way to define standard Field Types with some default options and override them if necessary.
4869

4970
Example:
5071

51-
```php
52-
<?php
72+
``` bash
73+
php artisan make:entity blog --schema="title:string,text:summernote"
74+
```
75+
76+
This will use the `StringType` and `SummernoteType` classes to create (besides all other files):
77+
78+
- Blog.php with `$fillable = ['title', 'text']`
79+
- BlogRequest.php with predefined rules for each field
80+
- BlogCrudController.php with columns and fields for `title` and `text`
81+
82+
If you want to add/overwrite certain options you can use something like this:
5383

54-
class ExampleService extends ServiceAbstract implements ServiceInterface
55-
{
56-
protected $relativeToBasePath = 'path/to/file';
84+
``` bash
85+
php artisan make:entity blog --schema="title:string(unique|default:title);rule(required|min:3|max:64),text:summernote;field(label:Content);column(label:Content)"
86+
```
87+
88+
## Field Types
89+
90+
Currently available Field Types (more coming soon):
5791

58-
public function call()
59-
{
60-
// do some magic
92+
- Date
93+
- Number
94+
- String
95+
- Summernote (as a proof of concept)
96+
- Text
6197

62-
// searches for latest file (using modified date) in given directory and adds it to the stack
63-
$this->addLatestFileToIdeStack();
64-
}
65-
}
98+
The available definitions in the Field Type classes currently are:
99+
100+
```php
101+
public $validationRule; // 'required|min:5'...
102+
103+
public $migrationField = [
104+
'type' => 'string', // any type available for a migration file
105+
// optional:
106+
// 'unique' => true
107+
// 'default' => 'value'
108+
// 'nullable' => true
109+
// etc.
110+
];
111+
112+
public $crudColumn = [
113+
'type' => 'text', // or date, number, any backpack column
114+
// 'label' => 'Name of label'
115+
// ... any option
116+
];
117+
118+
public $crudField = [
119+
'type' => 'text', // or date, number, any backpack field
120+
// 'label' => 'Name of label'
121+
// ... prefix, suffix... any option
122+
];
66123
```
67124

125+
## Naming
126+
127+
`// to be written`
128+
129+
## Add files to git
130+
131+
With `{--git}` option all generated files will be added to git automatically. In your service class you have to add the generated file. You can:
132+
133+
- use `$this->command->addFile(SplileInfo $file)` or
134+
- use `$this->addGeneratedFileToIdeStack()` if you use a naming key or
135+
- use the `Webfactor\Laravel\Generators\Traits\CanGenerateFile` define a naming key and just implement a `buildFileContent()` method
136+
137+
## Open files in IDE
138+
139+
With `{--ide=}` option you can define your preferred IDE to open all automatically generated files. This package comes with an implementation for PhpStorm (`Webfactor\Laravel\Generators\RecipesPhpStormOpener`) which is defined in `generators.php`. The keys in the `ides`-Array are possible values for the command option. You can add other IDE-Opener classes, they have to implement `Webfactor\Laravel\Generators\Contracts\OpenInIdeInterface`.
140+
141+
In your service class you have to add the generated file to a stack (see "Add files to git" section)
142+
143+
68144
## Adaption
69145

70146
Feel free to write your own Services that fit your purposes!

config/generators.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
*/
88
'services' => [
99
Webfactor\Laravel\Generators\Services\MigrationService::class,
10-
Webfactor\Laravel\Generators\Services\LanguageService::class,
10+
Webfactor\Laravel\Generators\Services\LanguageFileService::class,
1111
Webfactor\Laravel\Generators\Services\BackpackCrudModelService::class,
12-
Webfactor\Laravel\Generators\Services\BackpackCrudControllerService::class,
1312
Webfactor\Laravel\Generators\Services\BackpackCrudRequestService::class,
13+
Webfactor\Laravel\Generators\Services\BackpackCrudControllerService::class,
1414
Webfactor\Laravel\Generators\Services\FactoryService::class,
1515
Webfactor\Laravel\Generators\Services\SeederService::class,
1616
Webfactor\Laravel\Generators\Services\RouteService::class,
1717
Webfactor\Laravel\Generators\Services\SidebarService::class,
18-
Webfactor\Laravel\Generators\Services\OpenIdeService::class,
1918
],
2019

2120
/*
@@ -25,4 +24,24 @@
2524
'ides' => [
2625
'pstorm' => Webfactor\Laravel\Generators\Recipes\PhpStormOpener::class,
2726
],
27+
28+
'naming' => [
29+
'migration' => Webfactor\Laravel\Generators\Schemas\Naming\Migration::class,
30+
'languageFile' => Webfactor\Laravel\Generators\Schemas\Naming\LanguageFile::class,
31+
'crudModel' => Webfactor\Laravel\Generators\Schemas\Naming\CrudModel::class,
32+
'crudRequest' => Webfactor\Laravel\Generators\Schemas\Naming\CrudRequest::class,
33+
'crudController' => Webfactor\Laravel\Generators\Schemas\Naming\CrudController::class,
34+
'routeFile' => Webfactor\Laravel\Generators\Schemas\Naming\RouteFile::class,
35+
'factory' => Webfactor\Laravel\Generators\Schemas\Naming\Factory::class,
36+
'seeder' => Webfactor\Laravel\Generators\Schemas\Naming\Seeder::class,
37+
'sidebar' => Webfactor\Laravel\Generators\Schemas\Naming\Sidebar::class,
38+
],
39+
40+
'fieldTypes' => [
41+
'date' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\DateType::class,
42+
'number' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\NumberType::class,
43+
'summernote' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\SummernoteType::class,
44+
'string' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\StringType::class,
45+
'text' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\TextType::class,
46+
]
2847
];

src/Commands/MakeBackpackCrudController.php

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)