matthewbdaly / laravel-repositories
一个基础仓库类和接口,以及一个缓存装饰器。扩展它们以在您的项目中使用。
1.2.1
2018-06-08 09:18 UTC
Requires (Dev)
- matthewbdaly/artisan-standalone: 0.0.*
- mockery/mockery: ^1.0
- orchestra/testbench: ^3.5
- phpunit/phpunit: ^6.4
- psy/psysh: ^0.8.14
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.1
README
一个基础仓库类和接口,以及一个缓存装饰器。扩展它们以在您的项目中使用。
基本接口是 Matthewbdaly\LaravelRepositories\Repositories\Interfaces\AbstractRepositoryInterface
。您的仓库应该有扩展此接口的接口,以方便类型提示。
此接口由抽象装饰器 Matthewbdaly\LaravelRepositories\Repositories\Decorators\BaseDecorator
和抽象仓库 Matthewbdaly\LaravelRepositories\Repositories\Base
实现。再次,您应该扩展这些类来创建自己的仓库和装饰器。然后,您可以在自己的服务提供者中按照以下方式解析这些接口
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // } /** * Register any application services. * * @return void */ public function register() { $this->app->singleton('App\Repositories\Interfaces\ExampleRepositoryInterface', function () { $baseRepo = new \App\Repositories\EloquentExampleRepository(new \App\Example); $cachingRepo = new \App\Repositories\Decorators\ExampleDecorator($baseRepo, $this->app['cache.store']); return $cachingRepo; }); } }
Artisan任务
此包实现了以下Artisan任务,以帮助编写样板代码
make:repository
- 为传递的模型创建仓库,例如php artisan make:repository Foo
。通过传递--all
标志,也可以创建合同和装饰器。make:repository:contract
- 为传递的模型创建合同,例如php artisan make:repository:contract Foo
make:repository:decorator
- 为传递的模型创建装饰器,例如php artisan make:repository:decorator Foo