1 | <?php |
||
10 | class Storage implements StorageInterface |
||
11 | { |
||
12 | /** |
||
13 | * List of stored objects |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | private $storage = []; |
||
18 | /** |
||
19 | * List of objects marked as "dirty" |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $dirty = []; |
||
24 | /** |
||
25 | * Storage backend |
||
26 | * |
||
27 | * @var BackendInterface |
||
28 | */ |
||
29 | private $backend; |
||
30 | |||
31 | /** |
||
32 | * Register given object in storage |
||
33 | * |
||
34 | * @param StorableInterface $object |
||
35 | * @return $this |
||
36 | */ |
||
37 | 84 | public function register(StorableInterface $object) |
|
43 | |||
44 | /** |
||
45 | * Check if given object is registered into storage |
||
46 | * |
||
47 | * @param StorableInterface $object |
||
48 | * @return boolean |
||
49 | */ |
||
50 | 4 | public function has(StorableInterface $object) |
|
55 | |||
56 | /** |
||
57 | * Remove given object from storage |
||
58 | * |
||
59 | * @param StorableInterface $object |
||
60 | * @return $this |
||
61 | */ |
||
62 | 2 | public function remove(StorableInterface $object) |
|
68 | |||
69 | /** |
||
70 | * Load contents of given object from storage |
||
71 | * |
||
72 | * @param string $key Storage key |
||
73 | * @return mixed |
||
74 | */ |
||
75 | 78 | public function load($key) |
|
84 | |||
85 | /** |
||
86 | * Get storage backend |
||
87 | * |
||
88 | * @return BackendInterface |
||
89 | */ |
||
90 | 84 | public function getBackend() |
|
97 | |||
98 | /** |
||
99 | * Set storage backend |
||
100 | * |
||
101 | * @param BackendInterface $backend |
||
102 | * @return $this |
||
103 | */ |
||
104 | 3 | public function setBackend(BackendInterface $backend) |
|
109 | |||
110 | /** |
||
111 | * Mark given object as "dirty" |
||
112 | * |
||
113 | * @param StorableInterface $object |
||
114 | * @return $this |
||
115 | */ |
||
116 | 30 | public function markAsDirty(StorableInterface $object) |
|
122 | |||
123 | /** |
||
124 | * Mark given object as "not dirty" |
||
125 | * |
||
126 | * @param StorableInterface $object |
||
127 | * @return $this |
||
128 | */ |
||
129 | 3 | public function markAsNotDirty(StorableInterface $object) |
|
135 | |||
136 | /** |
||
137 | * Check if given object is "dirty" |
||
138 | * |
||
139 | * @param StorableInterface $object |
||
140 | * @return boolean |
||
141 | */ |
||
142 | 4 | public function isDirty(StorableInterface $object) |
|
147 | |||
148 | /** |
||
149 | * Flush all changes in objects into storage |
||
150 | * |
||
151 | * @throws \RuntimeException |
||
152 | * @return $this |
||
153 | */ |
||
154 | 7 | public function flush() |
|
174 | } |
||
175 |