crixuamg / laravel-decorators
9.0.0-beta-13
2023-12-29 20:55 UTC
Requires
Requires (Dev)
- barryvdh/laravel-ide-helper: ^2.13
- friendsofphp/php-cs-fixer: ^3.14
- mockery/mockery: ^1.5
- nunomaduro/phpinsights: ^2.7
- orchestra/testbench: ^7.22
- phpmd/phpmd: ^2.13
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
- dev-master
- 9.0.0-beta-13
- 9.0.0-beta-12
- 9.0.0-beta-11
- 9.0.0-beta.10
- 9.0.0-beta.9
- 9.0.0-beta.8
- 9.0.0-beta.7
- 9.0.0-beta.6
- 9.0.0-beta.5
- 9.0.0-beta.4
- 9.0.0-beta.3
- 9.0.0-beta.2
- 9.0.0-alpha.1
- 8.3.0
- 8.2.0
- 8.1.2
- 8.1.1
- 8.1.0
- 8.0.3
- 8.0.2
- 8.0.1
- 8.0.0
- 7.7.4
- 7.7.3
- 7.7.2
- 7.7.1
- 7.7.0
- 7.6.0
- 7.5.0
- 7.4.4
- 7.4.3
- 7.4.2
- 7.4.1
- 7.4.0
- 7.3.0
- 7.2.1
- 7.2.0
- 7.1.0
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.6.1
- 6.6.0
- 6.5.1
- 6.5.0
- 6.4.0
- 6.3.1
- 6.3.0
- 6.2.6
- 6.2.5
- 6.2.4
- 6.2.3
- 6.2.2
- 6.2.1
- 6.2.0
- 6.1.11
- 6.1.10
- 6.1.9
- 6.1.8
- 6.1.7
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.1
- 6.0.0
- 5.0.2
- 5.0.1
- 5.0.0
- 4.6.2
- 4.6.1
- 4.6.0
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.0
- 3.10.1
- 3.10.0
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.1
- 3.8.0
- 3.7.1
- 3.7.0
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.0
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.2.1
- 1.2.0
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.6.9
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.3
- 0.2.2
- v0.2.1
- v0.2.0
This package is auto-updated.
Last update: 2024-08-29 22:39:27 UTC
README
安装
将以下内容放入您的 composer.json 文件中
"require": { "crixuamg/laravel-decorators": "^6.0.0", // ... }
使用
发布配置文件后,按照文件底部所示注册装饰器。然后在控制器中扩展 AbstractController 并在 __construct()
中使用配置文件中创建的键调用 $this->setup()
。
Example:\
UserController
```php
use \CrixuAMG\Decorators\Http\Controllers\AbstractController;
class UserController extends AbstractController {
public function __construct()
{
$this->setup('users', UserResource::class);
}
public function index() {
return $this->forwardResourceful(__FUNCTION__);
}
}
```
And put the following in
config/decorators.php
```php
'tree' => [
'users' => [
'contract' => App\Contracts\UserContract::class,
'arguments' => [
// First element is the deepest layer
App\Repositories\UserRepository::class,
App\Caches\UserCache::class,
App\Decorators\UserDecorator::class,
],
],
]
```
当访问连接到索引方法的路由时,应用程序将经过 UserDecorator、UserCache 和 UserRepository。然后它将逆序通过相同的类,传递返回的数据并执行所需操作,如缓存和触发事件。处理完所有内容后,将使用在 __construct
中声明的资源返回数据。
自定义
您可以在 config/decorators.php
文件中设置一个 enabled
标志。当它设置为 false 时,任何实现 CrixuAMG\Decorators\Caches\AbstractCache
类的装饰器都将被忽略。
命令
为了使开发更快、更简单,已经创建了一些命令来提高易用性。
php artisan decorator:cache ModelCache php artisan decorator:repository ModelRepository php artisan decorator:contract ModelContract
或者,创建三个命令
php artisan decorators:make User
为了您的方便,已包含一个命令,可以自动创建以下内容
- 模型
- 控制器
- 合约
- 缓存
- 仓库
- 资源
php artisan decorators:starter User
以下选项可用于创建额外的文件
-m
创建迁移-d
创建装饰器-r
在 app/Http/Requests// 中创建 4 个请求类(Show、Store、Update、Delete)