Download the PHP package ulex/epic-repositories without Composer
On this page you can find all versions of the php package ulex/epic-repositories. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ulex/epic-repositories
More information about ulex/epic-repositories
Files in ulex/epic-repositories
Package epic-repositories
Short Description EPIC Repositories - An epic Laravel package
License MIT
Informations about the package epic-repositories
Add a powerful core setup to your application's queries
Documentation, Installation, and Usage Instructions
First, install the package via Composer:
Service Provider
For Laravel
You should publish the RepositoriesServiceProvider:
Optional: The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file: Laravel
For Lumen
In your bootstrap/app.php
add this:
Config
If config file epic-repositories.php
was not published copy it to config folder with:
Take some time to review this config file. Here you can adjust various configurations for your repositories setup.
- Set a custom TTL for each of you models.
- Set the namespaces of your folders
- Enable/add the repositories and decorators you will use.
- Add your model bindings for each repository and which decorators to use for that repository.
Note: In order to use elastic
repository you will have to add "elasticsearch/elasticsearch" package to your composer.json.
Create Repository/ies, Decorator/s with their Interfaces for a Model
First declare your models in config/epic-repositories
Run the following php artisan command:
Depending on you configuration, the necessary folders & classes will be created in your app/Repositories
folder.
Example:
How to use
This package provides an abstract structure that uses the Repository design pattern with caching decorator/s for you application.
Once installed you can create Repositories for your models that cache the data from your queries. Eloquent and Elastic Repositories are provided and ready to use if enabled. Follow the same principle for any data resource you have on your application.
Extending a model's CachingDecorator
For GET functions use the remember
function the same way as in the AbstractCachingDecorator. This will ensure that this function is cached and invalidated properly.
Function remember
signature
Functions that return a single result:
PostsEloquentCachingDecorator.php
Note: Remember to add the cache invalidation of the new function by extending flushGetKeys in the model's CachingDecorator.
PostsEloquentRepository.php
Add the query in the model's repository
Functions that return a collection of results:
For GET functions that return collections you MUST pass TRUE
to the $isCollection param on remember
function.
The above will be flushed in flushGetKeys
which calls flushCollections()
.
Note: If you are adding functions that create a new column, you need to add $this->flushCollections();
after the entry is created so that all collections are flushed and can include your new entry/ies. Check create
in AbstractCachingDecorator.
Contributing
This package is mostly based on Jeffrey Way's awesome Laracasts lessons when using the repository design pattern on Laravel From Scratch series.
License
The MIT License (MIT). Please see License File for more information.