webfactor/laravel-generators
Composer 安装命令:
composer require webfactor/laravel-generators
包简介
Laravel generators for quickly creating entities.
README 文档
README
This is a package developed by us for internal use. It is supposed to help us during development and save plenty of time by automating many steps while creating typical CRUD entities with Laravel Backpack. You can write your own Services (they have to implement Webfactor\Laravel\Generators\Contracts\ServiceInterface) and register them in the generators.php config file, or use this package as an inspiration for your own implementation.
Install
Via Composer
This package is indended to be used only for development, not for production. Because of that we recommend to use require-dev:
composer require --dev webfactor/laravel-generators
Usage
php artisan make:entity {entity_name} {--schema=} {--migrate} {--ide=} {--git}
entity_name: Recommendation: use singular for entity. see "Naming" for more information--schema=: Here you can provide a schema-String--migrate: will automatically callphp artisan migrateafter creating the migration file--ide=: will open all files in your prefered IDE--git: will add all files to git
If you want to add Services, Naming classes, Field Types, or IDE Opener you have to publish the config-file:
php artisan vendor:publish --provider="Webfactor\Laravel\Generators\GeneratorsServiceProvider"
Services
All Services defined in the config file have to implement Webfactor\Laravel\Generators\Contracts\ServiceInterface and will then be called in the given order.
Included Services
Can be removed or extended by publishing config file:
MigrationServiceFactoryServiceSeederService- Backpack CRUD:
BackpackCrudModelService(incl.$fillable)BackpackCrudRequestService(incl.rules())BackpackCrudControllerService(incl. CrudColumns and CrudFields, more coming soon)SidebarService
LanguageFileServiceRouteFileService
Always available (activated by option):
OpenIdeServiceAddToGitService
Schema
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.
Example:
php artisan make:entity blog --schema="title:string,text:summernote"
This will use the StringType and SummernoteType classes to create (besides all other files):
- Blog.php with
$fillable = ['title', 'text'] - BlogRequest.php with predefined rules for each field
- BlogCrudController.php with columns and fields for
titleandtext
If you want to add/overwrite certain options you can use something like this:
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)"
Field Types
Currently available Field Types (more coming soon):
- Date
- Number
- String
- Summernote (as a proof of concept)
- Text
The available definitions in the Field Type classes currently are:
public $validationRule; // 'required|min:5'... public $migrationField = [ 'type' => 'string', // any type available for a migration file // optional: // 'unique' => true // 'default' => 'value' // 'nullable' => true // etc. ]; public $crudColumn = [ 'type' => 'text', // or date, number, any backpack column // 'label' => 'Name of label' // ... any option ]; public $crudField = [ 'type' => 'text', // or date, number, any backpack field // 'label' => 'Name of label' // ... prefix, suffix... any option ];
Naming
You can provide your own naming convention classes by registering them in the config file. This classes should extend Webfactor\Laravel\Generators\Contracts\NamingAbstract to provide a certain base functionality.
Example for Webfactor\Laravel\Generators\Schemas\Naming\CrudController:
<?php namespace Webfactor\Laravel\Generators\Schemas\Naming; use Webfactor\Laravel\Generators\Contracts\NamingAbstract; class CrudController extends NamingAbstract { /** * @return string */ public function getNamespace(): string { return $this->getAppNamespace() . 'Http\\Controllers\\Admin'; } /** * @return string */ public function getClassName(): string { return ucfirst($this->entity) . 'CrudController'; } /** * @return string */ public function getFileName(): string { return $this->getClassName() . '.php'; } /** * @return string */ public function getPath(): string { return app_path('Http/Controllers/Admin'); } /** * @return string */ public function getStub(): string { return __DIR__ . '/../../../stubs/crud-controller.stub'; } }
All naming classes defined in the config file will be parsed and saved with their keys to the $naming-array of the command. As the entire command is available in each service class, you can access ALL naming conventions everywhere!
For example you need the Request-namespace in the CrudController: $this->command->naming['crudRequest']->getNamespace().
Furthermore there is a helper to keep things a bit simpler if you are IN the service class of the coresponding naming class! Just define $key and you can access the naming conventions directly through $this->naming:
<?php namespace Webfactor\Laravel\Generators\Services; class MyService extends ServiceAbstract implements ServiceInterface { protected $key = 'myNaming'; protected function call() { echo $this->naming; // same to echo $this->command->naming['myNaming']; // but you can additionally access echo $this->command->naming['otherNaming']; } }
Add files to git
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:
- use
$this->command->addFile(SplileInfo $file)or - use
$this->addGeneratedFileToIdeStack()if you use a naming key or - use the
Webfactor\Laravel\Generators\Traits\CanGenerateFiledefine a naming key and just implement abuildFileContent()method
Open files in IDE
If specified we will automatically open all generated files in the IDE of your choice.
There are three options to use this feature (applied in this order):
{--ide=}command option- .env variable
APP_EDITOR - config value
config('app.editor')
The keys in the ides-Array of the config file are possible values for the command option.
Per default we provide:
phpstorm: will open all files withpstormCLI helper of PhpStormpstorm: will open all files withpstormCLI helper of PhpStormsublime: will open all files withsublCLI helper of Sublimesubl: will open all files withsublCLI helper of Sublimevscode: will open all files withcodeCLI helper of VSCodecode: will open all files withcodeCLI helper of VSCode
You can add other IDE-Opener classes. They have to implement Webfactor\Laravel\Generators\Contracts\OpenInIdeInterface.
In your service class you have to add the generated file to a stack (see "Add files to git" section)
Adaption
Feel free to write your own Services that fit your purposes!
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email thomas.swonke@webfactor.de instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
webfactor/laravel-generators 适用场景与选型建议
webfactor/laravel-generators 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.11k 次下载、GitHub Stars 达 30, 最近一次更新时间为 2018 年 03 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「generators」 「backpack」 「Webfactor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webfactor/laravel-generators 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webfactor/laravel-generators 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webfactor/laravel-generators 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Extend Laravel's generators scaffold.
Code generators for Zend Framework 2 in console.
Laravel Artisan Command To Generate Facades (php artisan make generator now execpts facade Facadename)
Extended summernote fields for laravel backpack
Use a translation namespace vor mutliple translation files.
Ready to use Documents Backpack CRUD with API route for eg. privacy statement, imprint, sbt or gtc
统计信息
- 总下载量: 11.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-16