|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of slick/orm package |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Slick\Orm\Entity; |
|
11
|
|
|
|
|
12
|
|
|
use Slick\Cache\Cache; |
|
13
|
|
|
use Slick\Cache\CacheStorageInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Collections Map store |
|
17
|
|
|
* |
|
18
|
|
|
* @package Slick\Orm\Entity |
|
19
|
|
|
* @author Filipe Silva <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class CollectionsMap implements CollectionsMapInterface |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var CacheStorageInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $cache; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Set an entity |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $collectionId |
|
33
|
|
|
* @param EntityCollection $collection |
|
34
|
|
|
* |
|
35
|
|
|
* @return self|$this|CollectionsMapInterface |
|
36
|
|
|
*/ |
|
37
|
2 |
|
public function set($collectionId, EntityCollection $collection) |
|
38
|
|
|
{ |
|
39
|
2 |
|
$this->getCache()->set($collectionId, $collection); |
|
40
|
2 |
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Gets the entity with provided id |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $collectionId |
|
47
|
|
|
* |
|
48
|
|
|
* @param null $default |
|
49
|
|
|
* |
|
50
|
|
|
* @return EntityCollection |
|
51
|
|
|
*/ |
|
52
|
2 |
|
public function get($collectionId, $default = null) |
|
53
|
|
|
{ |
|
54
|
2 |
|
return $this->getCache()->get($collectionId, $default); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Set cache storage for this identity map |
|
59
|
|
|
* |
|
60
|
|
|
* @param CacheStorageInterface $cache |
|
61
|
|
|
* |
|
62
|
|
|
* @return $this|self|CollectionsMap |
|
63
|
|
|
*/ |
|
64
|
6 |
|
public function setCache(CacheStorageInterface $cache) |
|
65
|
|
|
{ |
|
66
|
6 |
|
$this->cache = $cache; |
|
67
|
6 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Gets cache storage for this identity map |
|
72
|
|
|
* |
|
73
|
|
|
* @return CacheStorageInterface |
|
74
|
|
|
*/ |
|
75
|
6 |
|
public function getCache() |
|
76
|
|
|
{ |
|
77
|
6 |
|
if (null == $this->cache) { |
|
78
|
2 |
|
$this->setCache(Cache::get(Cache::CACHE_MEMORY)); |
|
79
|
2 |
|
} |
|
80
|
6 |
|
return $this->cache; |
|
81
|
|
|
} |
|
82
|
|
|
} |