1 | <?php |
||
25 | class CacheManager |
||
26 | { |
||
27 | /** |
||
28 | * @var FilterConfiguration |
||
29 | */ |
||
30 | protected $filterConfig; |
||
31 | |||
32 | /** |
||
33 | * @var RouterInterface |
||
34 | */ |
||
35 | protected $router; |
||
36 | |||
37 | /** |
||
38 | * @var ResolverInterface[] |
||
39 | */ |
||
40 | protected $resolvers = []; |
||
41 | |||
42 | /** |
||
43 | * @var SignerInterface |
||
44 | */ |
||
45 | protected $signer; |
||
46 | |||
47 | /** |
||
48 | * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
||
49 | */ |
||
50 | protected $dispatcher; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $defaultResolver; |
||
56 | |||
57 | /** |
||
58 | * Constructs the cache manager to handle Resolvers based on the provided FilterConfiguration. |
||
59 | * |
||
60 | * @param FilterConfiguration $filterConfig |
||
61 | * @param RouterInterface $router |
||
62 | * @param SignerInterface $signer |
||
63 | * @param EventDispatcherInterface $dispatcher |
||
64 | * @param string $defaultResolver |
||
65 | */ |
||
66 | public function __construct( |
||
79 | |||
80 | /** |
||
81 | * Adds a resolver to handle cached images for the given filter. |
||
82 | * |
||
83 | * @param string $filter |
||
84 | * @param ResolverInterface $resolver |
||
85 | */ |
||
86 | public function addResolver($filter, ResolverInterface $resolver) |
||
94 | |||
95 | /** |
||
96 | * Gets filtered path for rendering in the browser. |
||
97 | * It could be the cached one or an url of filter action. |
||
98 | * |
||
99 | * @param string $path The path where the resolved file is expected |
||
100 | * @param string $filter |
||
101 | * @param array $runtimeConfig |
||
102 | * @param string $resolver |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getBrowserPath($path, $filter, array $runtimeConfig = [], $resolver = null) |
||
120 | |||
121 | /** |
||
122 | * Get path to runtime config image. |
||
123 | * |
||
124 | * @param string $path |
||
125 | * @param array $runtimeConfig |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getRuntimePath($path, array $runtimeConfig) |
||
133 | |||
134 | /** |
||
135 | * Returns a web accessible URL. |
||
136 | * |
||
137 | * @param string $path The path where the resolved file is expected |
||
138 | * @param string $filter The name of the imagine filter in effect |
||
139 | * @param array $runtimeConfig |
||
140 | * @param string $resolver |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function generateUrl($path, $filter, array $runtimeConfig = [], $resolver = null) |
||
166 | |||
167 | /** |
||
168 | * Checks whether the path is already stored within the respective Resolver. |
||
169 | * |
||
170 | * @param string $path |
||
171 | * @param string $filter |
||
172 | * @param string $resolver |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function isStored($path, $filter, $resolver = null) |
||
180 | |||
181 | /** |
||
182 | * Resolves filtered path for rendering in the browser. |
||
183 | * |
||
184 | * @param string $path |
||
185 | * @param string $filter |
||
186 | * @param string $resolver |
||
187 | * |
||
188 | * @throws NotFoundHttpException if the path can not be resolved |
||
189 | * |
||
190 | * @return string The url of resolved image |
||
191 | */ |
||
192 | public function resolve($path, $filter, $resolver = null) |
||
208 | |||
209 | /** |
||
210 | * BC Layer for Symfony < 4.3 |
||
211 | * |
||
212 | * @param CacheResolveEvent $event |
||
213 | * @param string $eventName |
||
214 | */ |
||
215 | private function dispatchWithBC(CacheResolveEvent $event, string $eventName): void |
||
223 | |||
224 | /** |
||
225 | * @see ResolverInterface::store |
||
226 | * |
||
227 | * @param BinaryInterface $binary |
||
228 | * @param string $path |
||
229 | * @param string $filter |
||
230 | * @param string $resolver |
||
231 | */ |
||
232 | public function store(BinaryInterface $binary, $path, $filter, $resolver = null) |
||
236 | |||
237 | /** |
||
238 | * @param string|string[]|null $paths |
||
239 | * @param string|string[]|null $filters |
||
240 | */ |
||
241 | public function remove($paths = null, $filters = null) |
||
270 | |||
271 | /** |
||
272 | * Gets a resolver for the given filter. |
||
273 | * |
||
274 | * In case there is no specific resolver, but a default resolver has been configured, the default will be returned. |
||
275 | * |
||
276 | * @param string $filter |
||
277 | * @param string $resolver |
||
278 | * |
||
279 | * @throws \OutOfBoundsException If neither a specific nor a default resolver is available |
||
280 | * |
||
281 | * @return ResolverInterface |
||
282 | */ |
||
283 | protected function getResolver($filter, $resolver) |
||
304 | } |
||
305 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: