weble/laravel-playbooks
在您的Laravel应用程序中运行不同的playbook集合
4.0.0
2023-03-02 10:48 UTC
Requires
- php: ^8.0
- illuminate/support: ^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0
- phpunit/phpunit: ^9.0|^10.0
README
在您的Laravel应用程序中运行不同的playbook集合。受Brent的聚合启发和借鉴(略有修改)。
版本兼容性
安装
您可以通过composer安装此包
composer require weble/laravel-playbooks
配置
php artisan vendor:publish --provider="Weble\LaravelPlaybooks\PlaybooksServiceProvider"
这是配置文件的默认内容
<?php return [ /* |-------------------------------------------------------------------------- | Run only in these environments |-------------------------------------------------------------------------- | | Do not allow Playbooks to be run in any environment outside of the ones specified here | | default: ['local'] */ 'envs' => [ 'local' ], /* |-------------------------------------------------------------------------- | Raise PHP memory limit |-------------------------------------------------------------------------- | | Raise the default memory limit to avoid issues when running large playbooks. | Set to null to disable this feature. | | default: '20148M' */ 'raise_memory_limit' => '2048M', /* |-------------------------------------------------------------------------- | Fresh Migration |-------------------------------------------------------------------------- | | Run a migrate:refresh command before every playbook run by default. | This can be disabled or enabled manually through the | --no-migration or --migration options | | default: true */ 'migrate_by_default' => true, /* |-------------------------------------------------------------------------- | Playbook path |-------------------------------------------------------------------------- | | Choose the root directory where new Playbooks should be created and where | the `php artisan playbook:run` command should scan for available playbooks | example: 'Console/Playbooks' | | default: 'Playbooks' */ 'path' => 'Playbooks', ];
使用方法
注意:默认情况下,此包在运行每个playbook之前都会运行一个migrate:refresh
命令。您可以在配置中禁用此行为,或在命令中使用手动--no-migration选项。
首先创建一个(或多个)playbook
php artisan make:playbook FullPlaybook
此playbook将具有App\Playbooks
命名空间,并保存在app/Playbooks
中。
您也可以指定一个自定义命名空间,例如,App\Console\Playbooks
php artisan make:playbook Console/Playbooks/FullPlaybook
此playbook将具有App\Console\Presenters命名空间,并保存在app/Console/Playbooks中。
现在,您可以自由地在其中编写一些内容
<?php namespace App\Playbooks; use App\CarType; use Weble\LaravelPlaybooks\Playbook; final class CarTypesPlaybook extends Playbook { public function before(): array { return [ // List of other playbooks to run before this one // ie: BasePlaybook::once() // ie: BasePlaybook::times(3) to run it 3 times ]; } public function run(): void { $this->createCarTypes(); } private function createCarTypes(): void { $types = [ 'Economy' => 3, 'Business' => 4, 'Family' => 4, 'Sport' => 2, 'Luxury' => 3, 'Van' => 8, 'Luxury Van' => 6, ]; foreach ($types as $type => $passengers) { factory(CarType::class)->create([ 'title' => [ 'it' => $type, 'en' => $type, ], 'subtitle' => [ 'it' => 'Adipiscing elit. aute irure dolor', 'en' => 'Adipiscing elit. aute irure dolor', ], 'description' => [ 'it' => 'Lorem ipsum dolor sit amet consecte tur adipiscing elit. aute irure dolor in reprehende.', 'en' => 'Lorem ipsum dolor sit amet consecte tur adipiscing elit. aute irure dolor in reprehende.', ], 'max_passengers' => $passengers, 'max_luggage' => $passengers - 1, ]); } } public function after(): array { return [ // List of other playbooks to run before this one // ie: BasePlaybook::once() // ie: BasePlaybook::times(3) to run it 3 times ]; } }
最后,您可以运行它们!
php artisan playbook:run FullPlaybook
待办事项
为运行命令编写更多测试
更新日志
请参阅更新日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件daniele@weble.it报告,而不是使用问题跟踪器。
致谢
许可
MIT许可证(MIT)。有关更多信息,请参阅许可文件。