Download the PHP package guillermoandrae/php-repository without Composer
On this page you can find all versions of the php package guillermoandrae/php-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download guillermoandrae/php-repository
More information about guillermoandrae/php-repository
Files in guillermoandrae/php-repository
Package php-repository
Short Description A PHP library that implements the Repository pattern.
License MIT
Informations about the package php-repository
PHP Repository Library
I use a simple implementation of the Repository pattern. Often. I've been copying and pasting the same code between projects for longer than I care to admit; I came to my senses recently, and that's why this project now exists.
Installation
Do this, then relax:
Usage
Before you do anything crazy, read up on the Repository pattern. If, after reading that, you decide you still want to move forward: keep reading.
Naming Classes
Your classes should be named according to their data type. For example, if you're dealing with widgets, your repository should be named WidgetsRepository
and your model should be named WidgetModel
. Note that the data type in the repository name is pluralized and singular in the model name.
Define the Namespace
By default, the RepositoryFactory
class will look for repositories in the App\Repositories
namespace. If you don't plan on using that namespace, you'll need to tell the factory where your repositories live. Use RepositoryFactory::setNamespace()
to do that, like so:
Creating Repositories
Leveraging the repository functionality is as easy as writing the following:
There are a few methods you need to implement in the classes that inherit from the AbstractRepository
class. Check out the AbstractRepository
classes for the most up-to-date list.
Creating Models
Creating models is straightforward:
I generally build immutable models, but how you use them is entirely up to you.
Testing
Run the following command to make sure you don't ruin the code coverage percentage:
Run the following command to make sure your code is appropriately styled:
Run the following command to invoke both of the above commands easily:
All versions of php-repository with dependencies
icanboogie/inflector Version ^2.0
guillermoandrae/php-collection Version ^2.0