Download the PHP package awsm3/yii2-repository without Composer
On this page you can find all versions of the php package awsm3/yii2-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download awsm3/yii2-repository
More information about awsm3/yii2-repository
Files in awsm3/yii2-repository
Package yii2-repository
Short Description Repository implementation in Yii2
License MIT
Informations about the package yii2-repository
Yii2 Repository Pattern implementation
Yii2 Repository Pattern implementation for Yii2
You can read more about repository patterns here:
- http://deviq.com/repository-pattern/
- http://martinfowler.com/eaaCatalog/repository.html
- http://shawnmc.cool/the-repository-pattern
- http://stackoverflow.com/questions/16176990/proper-repository-pattern-design-in-php
Table of Contents
- Installation
- Composer
-
Methods
- RepositoryInterface
- Usage
- Create a Model
- Create a Repository
- Attach your Repository to container
- Repository Sample Usage
Installation
Composer
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Methods
Awsm3\Yii2Repository\Interfaces\RepositoryInterface
Usage
Create a Model
create your ActiveRecord Model :
Create a Repository Interface
Create a Repository class
or
create a Repository as a Yii component
this approach is useful when toy have a class which is already extending a class and can't extend AbstractRepository class just like yii components by using traits you can use this classes as yii component.
if your model is using sql as it's data source and your model actually is extending yii\db\ActiveRecord your repository should extend Awsm3\Yii2Repository\AbstractSqlArRepository.
and if your data source is mongodb and your model actually is extending yii\mongodb\ActiveRecord your repository should extend Awsm3\Yii2Repository\AbstractMongoArRepository.
and consider your application can use power of both sql and document-based databses (mongo)
Attach your Repository to container
if you are coding in a module you can put above code in your module bootstrap file. and also you can don't use container and create repository object every where you want like this :
Repository Sample Usage
sample usage which I show by using a controller.