crixuamg / laravel-decorators
Installs: 7 141
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
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-10-29 22:59:48 UTC
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:
-m
Creates a migration-d
Creates a decorator-r
Creates 4 request classes (Show, Store, Update, Delete) in app/Http/Requests/<MODEL_NAME>/