Skip to content

Commit 32e808b

Browse files
committed
Merge branch 'release/v2.0.1'
2 parents 2cb525f + 4c18557 commit 32e808b

File tree

9 files changed

+450
-314
lines changed

9 files changed

+450
-314
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
This project adheres to [Semantic Versioning](CONTRIBUTING.md).
66

77

8+
## [v2.0.1] - 2016-08-06
9+
- Add missing argument to simplePaginate method (#54)
10+
- Add config option for default model directory (close #55)
11+
- Extract Cache methods to a Contract / Trait (close #57)
12+
- Fix spelling typos & fix docs
13+
- Added extra logic to paginate and simplePaginate methods, fixes #61 (#62)
14+
815
## [v2.0.0] - 2016-07-01
916
- Drop `findOrCreate` method (close #33)
1017
- Change `retrieveModel` behavior (close #34)
@@ -56,6 +63,7 @@ This project adheres to [Semantic Versioning](CONTRIBUTING.md).
5663
## v1.0.0 - 2016-06-18
5764
- Commit first draft
5865

66+
[v2.0.1]: https://github.com/rinvex/repository/compare/v2.0.0...v2.0.1
5967
[v2.0.0]: https://github.com/rinvex/repository/compare/v1.0.5...v2.0.0
6068
[v1.0.5]: https://github.com/rinvex/repository/compare/v1.0.4...v1.0.5
6169
[v1.0.4]: https://github.com/rinvex/repository/compare/v1.0.3...v1.0.4

README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ Config options are very expressive and self explanatory, as follows:
161161
```php
162162
return [
163163

164+
/*
165+
|--------------------------------------------------------------------------
166+
| Models Directory
167+
|--------------------------------------------------------------------------
168+
|
169+
| Here you may specify the default models directory, just write
170+
| directory name, like 'Models' not the full path.
171+
|
172+
| Default: 'Models'
173+
|
174+
*/
175+
176+
'models' => 'Models',
177+
164178
/*
165179
|--------------------------------------------------------------------------
166180
| Caching Strategy
@@ -249,6 +263,21 @@ The `Rinvex\Repository\Repositories\EloquentRepository` is currently the only av
249263
```php
250264
namespace App\Repositories;
251265

266+
use Rinvex\Repository\Repositories\EloquentRepository;
267+
268+
class FooRepository extends EloquentRepository
269+
{
270+
protected $repositoryId = 'rinvex.repository.uniqueid';
271+
272+
protected $model = 'App\User';
273+
}
274+
```
275+
That's it, you're done! Yes, it's that simple.
276+
277+
But if you'd like more control over the container instance, or would like to pass model name dynamically you can alternatively to as follow:
278+
```php
279+
namespace App\Repositories;
280+
252281
use Illuminate\Contracts\Container\Container;
253282
use Rinvex\Repository\Repositories\EloquentRepository;
254283

@@ -265,7 +294,7 @@ class FooRepository extends EloquentRepository
265294
}
266295
```
267296

268-
Now inside your controller, you can either instantiate the repository traditionaly through `$repository = new \App\Repositories\FooRepository();` or to use Laravel's awesome dependency injection and let the IoC do the magic:
297+
Now inside your controller, you can either instantiate the repository traditionally through `$repository = new \App\Repositories\FooRepository();` or to use Laravel's awesome dependency injection and let the IoC do the magic:
269298
```php
270299
namespace App\Http\Controllers;
271300

@@ -312,10 +341,10 @@ ___
312341
The `setContainer` method sets the IoC container instance, while `getContainer` returns it:
313342
```php
314343
// Set the IoC container instance
315-
$this->setContainer(new \Illuminate\Container\Container());
344+
$repository->setContainer(new \Illuminate\Container\Container());
316345

317346
// Get the IoC container instance:
318-
$container = $this->getContainer();
347+
$container = $repository->getContainer();
319348
```
320349

321350
#### `setModel()`, `getModel()`
@@ -466,8 +495,9 @@ $allEntities = $repository->findAll();
466495

467496
The `paginate` method paginates all entities:
468497
```php
469-
$entitiesPagination = $repository->paginate(15);
498+
$entitiesPagination = $repository->paginate(15, ['*'], 'page', 2);
470499
```
500+
As you can guess, this query the first 15 records, in the second page.
471501

472502
#### `simplePaginate()`
473503

@@ -544,9 +574,10 @@ As a best practice, it's recommended to code for an interface, specifically for
544574

545575
First, create an interface (abstract) for every entity you've:
546576
```php
577+
use Rinvex\Repository\Contracts\CacheableContract;
547578
use Rinvex\Repository\Contracts\RepositoryContract;
548579

549-
interface UserRepositoryContract extends RepositoryContract
580+
interface UserRepositoryContract extends RepositoryContract, CacheableContract
550581
{
551582
//
552583
}
@@ -592,7 +623,7 @@ Repositories fire events at every action, like `create`, `update`, `delete`. All
592623

593624
For your convenience, the events suffixed with `.entity.created`, `.entity.updated`, or `.entity.deleted` have listeners that take actions accordingly. Usually we need to flush cache -if enabled & exists- upon every success action.
594625

595-
There's one more event `rinvex.repository.uniqueid.entity.cache.flushed` that's fired on cache flush. It has no listeners by default, but you may need to listen to it if you've model relashions for further actions.
626+
There's one more event `rinvex.repository.uniqueid.entity.cache.flushed` that's fired on cache flush. It has no listeners by default, but you may need to listen to it if you've model relations for further actions.
596627

597628
### Mandatory Repository Conventions
598629

@@ -644,7 +675,7 @@ Here some conventions important to know while using this package. This package a
644675
645676
### Automatic Guessing
646677

647-
While it's **recomended** to explicitly set IoC container, repository identifier, and repository model; This package is smart enough to guess any of these required data whenever missing.
678+
While it's **recommended** to explicitly set IoC container, repository identifier, and repository model; This package is smart enough to guess any of these required data whenever missing.
648679

649680
- **IoC Container** `app()` helper is used as a fallback if IoC container instance not provided explicitly.
650681
- **Repository Identifier** It's recommended to set repository identifier as a doted name like `rinvex.repository.uniqueid`, but if it's missing fully qualified repository class name will be used (actually the result of `get_called_class()` function).

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
"illuminate/container": "5.1.*|5.2.*|5.3.*",
4747
"illuminate/contracts": "5.1.*|5.2.*|5.3.*"
4848
},
49+
"suggest": {
50+
"illuminate/pagination": "Required to paginate the result set."
51+
},
4952
"autoload": {
5053
"psr-4": {
5154
"Rinvex\\Repository\\": "src/"

config/config.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515

1616
return [
1717

18+
/*
19+
|--------------------------------------------------------------------------
20+
| Models Directory
21+
|--------------------------------------------------------------------------
22+
|
23+
| Here you may specify the default models directory, just write
24+
| directory name, like 'Models' not the full path.
25+
|
26+
| Default: 'Models'
27+
|
28+
*/
29+
30+
'models' => 'Models',
31+
1832
/*
1933
|--------------------------------------------------------------------------
2034
| Caching Strategy
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/*
4+
* NOTICE OF LICENSE
5+
*
6+
* Part of the Rinvex Repository Package.
7+
*
8+
* This source file is subject to The MIT License (MIT)
9+
* that is bundled with this package in the LICENSE file.
10+
*
11+
* Package: Rinvex Repository Package
12+
* License: The MIT License (MIT)
13+
* Link: https://rinvex.com
14+
*/
15+
16+
namespace Rinvex\Repository\Contracts;
17+
18+
interface CacheableContract
19+
{
20+
/**
21+
* Set the repository cache lifetime.
22+
*
23+
* @param float|int $cacheLifetime
24+
*
25+
* @return $this
26+
*/
27+
public function setCacheLifetime($cacheLifetime);
28+
29+
/**
30+
* Get the repository cache lifetime.
31+
*
32+
* @return float|int
33+
*/
34+
public function getCacheLifetime();
35+
36+
/**
37+
* Set the repository cache driver.
38+
*
39+
* @param string $cacheDriver
40+
*
41+
* @return $this
42+
*/
43+
public function setCacheDriver($cacheDriver);
44+
45+
/**
46+
* Get the repository cache driver.
47+
*
48+
* @return string
49+
*/
50+
public function getCacheDriver();
51+
52+
/**
53+
* Enable repository cache clear.
54+
*
55+
* @param bool $status
56+
*
57+
* @return $this
58+
*/
59+
public function enableCacheClear($status);
60+
61+
/**
62+
* Determine if repository cache clear is enabled.
63+
*
64+
* @return bool
65+
*/
66+
public function isCacheClearEnabled();
67+
68+
/**
69+
* Forget the repository cache.
70+
*
71+
* @return $this
72+
*/
73+
public function forgetCache();
74+
}

src/Contracts/RepositoryContract.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -69,54 +69,6 @@ public function setModel($model);
6969
*/
7070
public function getModel();
7171

72-
/**
73-
* Set the repository cache lifetime.
74-
*
75-
* @param float|int $cacheLifetime
76-
*
77-
* @return $this
78-
*/
79-
public function setCacheLifetime($cacheLifetime);
80-
81-
/**
82-
* Get the repository cache lifetime.
83-
*
84-
* @return float|int
85-
*/
86-
public function getCacheLifetime();
87-
88-
/**
89-
* Set the repository cache driver.
90-
*
91-
* @param string $cacheDriver
92-
*
93-
* @return $this
94-
*/
95-
public function setCacheDriver($cacheDriver);
96-
97-
/**
98-
* Get the repository cache driver.
99-
*
100-
* @return string
101-
*/
102-
public function getCacheDriver();
103-
104-
/**
105-
* Enable repository cache clear.
106-
*
107-
* @param bool $status
108-
*
109-
* @return $this
110-
*/
111-
public function enableCacheClear($status);
112-
113-
/**
114-
* Determine if repository cache clear is enabled.
115-
*
116-
* @return bool
117-
*/
118-
public function isCacheClearEnabled();
119-
12072
/**
12173
* Create a new repository model instance.
12274
*
@@ -126,13 +78,6 @@ public function isCacheClearEnabled();
12678
*/
12779
public function createModel();
12880

129-
/**
130-
* Forget the repository cache.
131-
*
132-
* @return $this
133-
*/
134-
public function forgetCache();
135-
13681
/**
13782
* Set the relationships that should be eager loaded.
13883
*

0 commit comments

Comments
 (0)