项目作者: matthewbdaly

项目描述 :
A base repository class and interface, together with a caching decorator. Extend them for use in your own projects
高级语言: PHP
项目地址: git://github.com/matthewbdaly/laravel-repositories.git
创建时间: 2017-11-14T17:13:33Z
项目社区:https://github.com/matthewbdaly/laravel-repositories

开源协议:MIT License

下载


laravel-repositories

Build Status
Coverage Status
A base repository class and interface, together with a caching decorator. Extend them for use in your own projects.

The base interface is Matthewbdaly\LaravelRepositories\Repositories\Interfaces\AbstractRepositoryInterface. Your repositories should have interfaces that extend this, to facilitate type-hinting them.

This interface is implemented by both the abstract decorator Matthewbdaly\LaravelRepositories\Repositories\Decorators\BaseDecorator and the abstract repository Matthewbdaly\LaravelRepositories\Repositories\Base. Again, you should extend these classes to create your own repositories and decorators. You can then resolve these interfaces in your own service provider as follows:

  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\ServiceProvider;
  4. class AppServiceProvider extends ServiceProvider
  5. {
  6. /**
  7. * Bootstrap any application services.
  8. *
  9. * @return void
  10. */
  11. public function boot()
  12. {
  13. //
  14. }
  15. /**
  16. * Register any application services.
  17. *
  18. * @return void
  19. */
  20. public function register()
  21. {
  22. $this->app->singleton('App\Repositories\Interfaces\ExampleRepositoryInterface', function () {
  23. $baseRepo = new \App\Repositories\EloquentExampleRepository(new \App\Example);
  24. $cachingRepo = new \App\Repositories\Decorators\ExampleDecorator($baseRepo, $this->app['cache.store']);
  25. return $cachingRepo;
  26. });
  27. }
  28. }

Artisan tasks

This package implements the following Artisan tasks to help writing boilerplate:

  • make:repository - Makes a repository for the model passed, ie php artisan make:repository Foo. Pass the --all flag to also create the contract and decorator.
  • make:repository:contract - Makes a contract for the model passed, ie php artisan make:repository:contract Foo
  • make:repository:decorator - Makes a decorator for the model passed, ie php artisan make:repository:decorator Foo