1 | <?php |
||
38 | class StorageProxy { |
||
39 | |||
40 | /** @var string */ |
||
41 | const BREAK_ITERATION_CALLBACK = "BIC"; |
||
42 | |||
43 | /** @var \Brickoo\Component\Storage\Adapter\Adapter */ |
||
44 | private $adapter; |
||
45 | |||
46 | /** @var \Brickoo\Component\Storage\Adapter\AdapterPoolIterator */ |
||
47 | private $adapterPoolIterator; |
||
48 | |||
49 | /** |
||
50 | * Class constructor. |
||
51 | * @param \Brickoo\Component\Storage\Adapter\AdapterPoolIterator $adapterPoolIterator |
||
52 | */ |
||
53 | 1 | public function __construct(AdapterPoolIterator $adapterPoolIterator) { |
|
57 | |||
58 | /** |
||
59 | * Returns a stored content or if the stored content is not available, |
||
60 | * it will be retrieved by the provided callback and stored back into the storage. |
||
61 | * @param string $identifier the identifier to retrieve/store the content from/to |
||
62 | * @param callable $callback the callback to call if the content is not stored |
||
63 | * @param array $callbackArguments the arguments to pass forward to the callback |
||
64 | * @param integer $lifetime the lifetime of the stored content in seconds |
||
65 | * @throws \InvalidArgumentException if an argument is not valid |
||
66 | * @throws \Brickoo\Component\Storage\Exception\AdapterNotFoundException |
||
67 | * @return mixed the stored content |
||
68 | */ |
||
69 | 3 | public function getByCallback($identifier, callable $callback, array $callbackArguments, $lifetime) { |
|
79 | |||
80 | /** |
||
81 | * Returns the stored content hold by the identifier. |
||
82 | * @param string $identifier the identifier to retrieve the content |
||
83 | * @throws \InvalidArgumentException if an argument is not valid |
||
84 | * @throws \Brickoo\Component\Storage\Exception\AdapterNotFoundException |
||
85 | * @return mixed the stored content |
||
86 | */ |
||
87 | 4 | public function get($identifier) { |
|
91 | |||
92 | /** |
||
93 | * Sets the content hold by the given identifier. |
||
94 | * If the identifier already exists the content will be replaced. |
||
95 | * @param string $identifier the identifier which holds the content |
||
96 | * @param mixed $content the content to store |
||
97 | * @param integer $lifetime the lifetime of the stored content |
||
98 | * @throws \InvalidArgumentException if an argument is not valid |
||
99 | * @throws \Brickoo\Component\Storage\Exception\AdapterNotFoundException |
||
100 | * @return \Brickoo\Component\Storage\StorageProxy |
||
101 | */ |
||
102 | 3 | public function set($identifier, $content, $lifetime) { |
|
108 | |||
109 | /** |
||
110 | * Deletes the stored content which is hold by the identifier. |
||
111 | * Removes the local stored content. |
||
112 | * @param string $identifier the identifier which holds the content |
||
113 | * @throws \InvalidArgumentException if an argument is not valid |
||
114 | * @return \Brickoo\Component\Storage\StorageProxy |
||
115 | */ |
||
116 | 2 | public function delete($identifier) { |
|
126 | |||
127 | /** |
||
128 | * Flushes the storage of all ready adapters. |
||
129 | * @return \Brickoo\Component\Storage\StorageProxy |
||
130 | */ |
||
131 | 1 | public function flush() { |
|
140 | |||
141 | /** |
||
142 | * Returns a ready adapter entry from the adapter pool. |
||
143 | * @throws \Brickoo\Component\Storage\Exception\AdapterNotFoundException |
||
144 | * @return \Brickoo\Component\Storage\Adapter\Adapter |
||
145 | */ |
||
146 | 5 | private function getAdapter() { |
|
152 | |||
153 | /** |
||
154 | * Returns an adapter which is ready to use. |
||
155 | * @throws \Brickoo\Component\Storage\Exception\AdapterNotFoundException |
||
156 | * @return \Brickoo\Component\Storage\Adapter\Adapter |
||
157 | */ |
||
158 | 5 | private function getReadyAdapter() { |
|
173 | |||
174 | /** |
||
175 | * Execute a callback on every ready adapter. |
||
176 | * @param \Closure $callbackFunction |
||
177 | * @return \Brickoo\Component\Storage\StorageProxy |
||
178 | */ |
||
179 | 5 | private function executeIterationCallback(\Closure $callbackFunction) { |
|
191 | |||
192 | /** |
||
193 | * Rewind the adapter pool. |
||
194 | * @return \Brickoo\Component\Storage\StorageProxy |
||
195 | */ |
||
196 | 4 | private function rewindAdapterPool() { |
|
200 | |||
201 | } |
||
202 |