Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/v1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Omranic committed Jun 21, 2016
2 parents c211553 + c0a1d96 commit c840b87
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 169 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,11 +5,17 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](CONTRIBUTING.md).


## [v1.0.2] - 2016-06-22
- Fix `findWhere` wrong results and fix docs mistakes (close #15)
- Enable/disable cache per query (close #16)
- Revamp the entire documentation (close #17)

## [v1.0.1] - 2016-06-21
- Update docs, docblocks, and fix homepage link
- Add per repository cache lifetime/driver support (Close #10)

## v1.0.0 - 2016-06-18
- Commit first draft

[v1.0.2]: https://github.com/rinvex/repository/compare/v1.0.1...v1.0.2
[v1.0.1]: https://github.com/rinvex/repository/compare/v1.0.0...v1.0.1
170 changes: 111 additions & 59 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
@@ -1,6 +1,6 @@
{
"name": "rinvex/repository",
"description": "Rinvex Repository is an intuitive, smart, and simple implementation of Repository Pattern used to abstract the data layer, with extremely flexible & granular caching system, making apps more flexible to maintain.",
"description": "Rinvex Repository is an intuitive, smart, and simple implementation of Repository Pattern used to abstract the data layer, with extremely flexible & granular caching system, making applications more flexible to maintain.",
"keywords": [
"solid",
"rinvex",
Expand Down
22 changes: 0 additions & 22 deletions config/config.php
Expand Up @@ -87,28 +87,6 @@

'skip_uri' => 'skipCache',

/*
|--------------------------------------------------------------------------
| Cache Methods
|--------------------------------------------------------------------------
|
| Specify which methods should be cached. Note that these methods
| MUST support caching in it's implementation for this to work.
|
| Default: ['find', 'findBy', 'findAll', 'paginate', 'findWhere', 'findWhereIn', 'findWhereNotIn']
|
*/

'methods' => [
'find',
'findBy',
'findAll',
'paginate',
'findWhere',
'findWhereIn',
'findWhereNotIn',
],

],

];
76 changes: 38 additions & 38 deletions src/Contracts/RepositoryContract.php
Expand Up @@ -127,11 +127,11 @@ public function orderBy($column, $direction = 'asc');
/**
* Find an entity by its primary key.
*
* @param int $id
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param int $id
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return object
*/
Expand All @@ -140,12 +140,12 @@ public function find($id, $columns = ['*'], $with = [], $lifetime = null, $drive
/**
* Find an entity by one of it's attributes.
*
* @param string $attribute
* @param string $value
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param string $attribute
* @param string $value
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return object
*/
Expand All @@ -154,10 +154,10 @@ public function findBy($attribute, $value, $columns = ['*'], $with = [], $lifeti
/**
* Find all entities.
*
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand All @@ -166,12 +166,12 @@ public function findAll($columns = ['*'], $with = [], $lifetime = null, $driver
/**
* Paginate all entities.
*
* @param int|null $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
* @param int $lifetime
* @param string $driver
* @param int|null $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
* @param int|null $lifetime
* @param string|null $driver
*
* @throws \InvalidArgumentException
*
Expand All @@ -182,11 +182,11 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
/**
* Find all entities matching where conditions.
*
* @param array $where
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param array $where
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand All @@ -195,12 +195,12 @@ public function findWhere(array $where, $columns = ['*'], $with = [], $lifetime
/**
* Find all entities matching whereIn conditions.
*
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand All @@ -209,12 +209,12 @@ public function findWhereIn($attribute, array $values, $columns = ['*'], $with =
/**
* Find all entities matching whereNotIn conditions.
*
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand Down
16 changes: 7 additions & 9 deletions src/Repositories/BaseRepository.php
Expand Up @@ -68,18 +68,18 @@ abstract class BaseRepository implements RepositoryContract
*
* @return mixed
*/
protected function executeCallback($class, $method, $hash, $lifetime = null, $driver = null, Closure $closure)
protected function executeCallback($class, $method, $hash, $lifetime, $driver, Closure $closure)
{
$cacheKey = $class.'@'.$method.'.'.$hash;
$config = $this->getContainer('config')->get('rinvex.repository.cache');
$lifetime = $lifetime ?: $config['lifetime'];
$lifetime = ! is_null($lifetime) ? $lifetime : $config['lifetime'];

// Switch cache driver on runtime
if ($driver) {
// Switch cache driver on runtime
$this->getContainer('cache')->setDefaultDriver($driver);
}

if ($this->isCacheableMethod($config, $method, $lifetime)) {
if ($this->isCacheableMethod($config, $lifetime)) {
if (method_exists($this->getContainer('cache')->getStore(), 'tags')) {
return $lifetime === -1
? $this->getContainer('cache')->tags($this->getRepositoryId())->rememberForever($cacheKey, $closure)
Expand Down Expand Up @@ -365,16 +365,14 @@ protected function getCacheKeys($file)
/**
* Determine if repository method is cacheable.
*
* @param array $config
* @param string $method
* @param int $lifetime
* @param array $config
* @param int $lifetime
*
* @return bool
*/
protected function isCacheableMethod($config, $method, $lifetime)
protected function isCacheableMethod($config, $lifetime)
{
return $this->cacheEnabled && $lifetime
&& in_array($method, $config['methods'])
&& ! $this->getContainer('request')->has($config['skip_uri']);
}
}
80 changes: 40 additions & 40 deletions src/Repositories/EloquentRepository.php
Expand Up @@ -54,11 +54,11 @@ public function retrieveModel($model = null, array $data = [])
/**
* Find an entity by its primary key.
*
* @param int $id
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param int $id
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return object
*/
Expand All @@ -74,12 +74,12 @@ public function find($id, $columns = ['*'], $with = [], $lifetime = null, $drive
/**
* Find an entity by one of it's attributes.
*
* @param string $attribute
* @param string $value
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param string $attribute
* @param string $value
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return object
*/
Expand All @@ -95,10 +95,10 @@ public function findBy($attribute, $value, $columns = ['*'], $with = [], $lifeti
/**
* Find all entities.
*
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand All @@ -114,12 +114,12 @@ public function findAll($columns = ['*'], $with = [], $lifetime = null, $driver
/**
* Paginate all entities.
*
* @param int|null $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
* @param int $lifetime
* @param string $driver
* @param int|null $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
* @param int|null $lifetime
* @param string|null $driver
*
* @throws \InvalidArgumentException
*
Expand All @@ -137,11 +137,11 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
/**
* Find all entities matching where conditions.
*
* @param array $where
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param array $where
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand All @@ -153,9 +153,9 @@ public function findWhere(array $where, $columns = ['*'], $with = [], $lifetime
foreach ($where as $attribute => $value) {
if (is_array($value)) {
list($attribute, $condition, $value) = $value;
$this->model->where($attribute, $condition, $value);
$this->model = $this->model->where($attribute, $condition, $value);
} else {
$this->model->where($attribute, '=', $value);
$this->model = $this->model->where($attribute, '=', $value);
}
}

Expand All @@ -166,12 +166,12 @@ public function findWhere(array $where, $columns = ['*'], $with = [], $lifetime
/**
* Find all entities matching whereIn conditions.
*
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand All @@ -187,12 +187,12 @@ public function findWhereIn($attribute, array $values, $columns = ['*'], $with =
/**
* Find all entities matching whereNotIn conditions.
*
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int $lifetime
* @param string $driver
* @param string $attribute
* @param array $values
* @param array $columns
* @param array $with
* @param int|null $lifetime
* @param string|null $driver
*
* @return \Illuminate\Support\Collection
*/
Expand Down

0 comments on commit c840b87

Please sign in to comment.