1 | <?php |
||
18 | final class Proxy |
||
19 | { |
||
20 | use \arc\traits\Proxy { |
||
21 | \arc\traits\Proxy::__construct as private ProxyConstruct; |
||
22 | } |
||
23 | |||
24 | private $cacheStore = null; |
||
25 | private $cacheControl = null; |
||
26 | private $targetObject = null; |
||
27 | |||
28 | /** |
||
29 | * Creates a new Caching Proxy object. |
||
30 | * @param object $targetObject The object to cache. |
||
31 | * @param object $cacheStore The cache store to use, e.g. \arc\cache\FileStore |
||
32 | * @param mixed $cacheControl Either an int with the number of seconds to cache results, or a Closure that returns an int. |
||
33 | * The Closure is called with a single array with the following entries: |
||
34 | * - target The cached object a method was called on. |
||
35 | * - method The method called |
||
36 | * - arguments The arguments to the method |
||
37 | * - output Any output generated by the method |
||
38 | * - result The result of the method |
||
39 | */ |
||
40 | 2 | public function __construct($targetObject, $cacheStore, $cacheControl = 7200) |
|
47 | |||
48 | /** |
||
49 | * Catches output and return values from a method call and returns them. |
||
50 | * @param string $method |
||
51 | * @param array $args |
||
52 | * @return array with keys 'output' and 'result' |
||
53 | */ |
||
54 | 2 | private function __callCatch($method, $args) |
|
67 | |||
68 | /** |
||
69 | * Checks if a fresh cache image for this method and these arguments is available |
||
70 | * and returns those. If not, it lets the call through and caches its output and results. |
||
71 | * @param string $method |
||
72 | * @param array $args |
||
73 | * @param string $path |
||
74 | * @return array |
||
75 | */ |
||
76 | 2 | private function __callCached($method, $args, $path) |
|
111 | |||
112 | /** |
||
113 | * Catches a call to the target object and caches it. If the result is an object, it creates a |
||
114 | * cache proxy for that as well. |
||
115 | * @param string $method |
||
116 | * @param array $args |
||
117 | * @return mixed |
||
118 | */ |
||
119 | 2 | public function __call($method, $args) |
|
133 | |||
134 | /** |
||
135 | * Catches any property access to the target object and caches it. If the property is an object |
||
136 | * it creates a cache proxy for that as well. |
||
137 | * @param string $name |
||
138 | * @return mixed |
||
139 | */ |
||
140 | public function __get($name) |
||
149 | } |
||
150 |