1: <?php
2:
3: namespace Guzzle\Plugin\Cache;
4:
5: use Guzzle\Common\Exception\InvalidArgumentException;
6: use Guzzle\Http\Message\RequestInterface;
7:
8: /**
9: * Determines a request's cache key using a callback
10: */
11: class CallbackCacheKeyProvider implements CacheKeyProviderInterface
12: {
13: /**
14: * @var \Closure|array|mixed Callable method
15: */
16: protected $callback;
17:
18: /**
19: * @param \Closure|array|mixed $callback Callable method to invoke
20: * @throws InvalidArgumentException
21: */
22: public function __construct($callback)
23: {
24: if (!is_callable($callback)) {
25: throw new InvalidArgumentException('Method must be callable');
26: }
27: $this->callback = $callback;
28: }
29:
30: /**
31: * {@inheritdoc}
32: */
33: public function getCacheKey(RequestInterface $request)
34: {
35: return call_user_func($this->callback, $request);
36: }
37: }
38: