crixuamg/laravel-decorators
最新稳定版本:9.0.0-beta-13
Composer 安装命令:
composer require crixuamg/laravel-decorators
包简介
README 文档
README
About
Installation
Usage
Customization
Commands
Installation
Put the following in your composer.json file:
"require": { "crixuamg/laravel-decorators": "^6.0.0", // ... }
Usage
After publishing the config file, register your decorators as shown in the bottom of the file. Then extend the AbstractController in a controller and call $this->setup() in the __construct() using the key created in the config file.
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,
],
],
]
```
When hitting the route linked to the index method the application will go through the UserDecorator, UserCache and UserRepository. Then it will go back through the same classes, passing the returned data and performing the required actions, like caching and firing events.
After everything has been processed the data will be returned using the resource as stated in the __construct.
Customization
You can set an enabled flag within the config/decorators.php file.
When this is set to false, any decorators implementing the CrixuAMG\Decorators\Caches\AbstractCache class will be ignored.
Commands
To make development even faster and easier, some commands have been created to improve ease of use.
php artisan decorator:cache ModelCache
php artisan decorator:repository ModelRepository
php artisan decorator:contract ModelContract
Or, create all three in a single command:
php artisan decorators:make User
For your convenience, a command has been included that automatically creates the following:
- Model
- Controller
- Contract
- Cache
- Repository
- Resource
php artisan decorators:starter User
The following options can be used to create extra files:
-mCreates a migration-dCreates a decorator-rCreates 4 request classes (Show, Store, Update, Delete) in app/Http/Requests/<MODEL_NAME>/
统计信息
- 总下载量: 8.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-13