Open Journal Systems  3.3.0
CallbackCanCacheStrategy.php
1 <?php
2 
3 namespace Guzzle\Plugin\Cache;
4 
8 
13 {
15  protected $requestCallback;
16 
18  protected $responseCallback;
19 
26  public function __construct($requestCallback = null, $responseCallback = null)
27  {
28  if ($requestCallback && !is_callable($requestCallback)) {
29  throw new InvalidArgumentException('Method must be callable');
30  }
31 
32  if ($responseCallback && !is_callable($responseCallback)) {
33  throw new InvalidArgumentException('Method must be callable');
34  }
35 
36  $this->requestCallback = $requestCallback;
37  $this->responseCallback = $responseCallback;
38  }
39 
40  public function canCacheRequest(RequestInterface $request)
41  {
42  return $this->requestCallback
43  ? call_user_func($this->requestCallback, $request)
44  : parent::canCacheRequest($request);
45  }
46 
47  public function canCacheResponse(Response $response)
48  {
49  return $this->responseCallback
50  ? call_user_func($this->responseCallback, $response)
51  : parent::canCacheResponse($response);
52  }
53 }
Guzzle\Http\Message\RequestInterface
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestInterface.php:16
Guzzle\Plugin\Cache\CallbackCanCacheStrategy\$responseCallback
$responseCallback
Definition: CallbackCanCacheStrategy.php:24
Guzzle\Plugin\Cache\CallbackCanCacheStrategy\__construct
__construct($requestCallback=null, $responseCallback=null)
Definition: CallbackCanCacheStrategy.php:32
Guzzle\Plugin\Cache\CallbackCanCacheStrategy\canCacheRequest
canCacheRequest(RequestInterface $request)
Definition: CallbackCanCacheStrategy.php:46
Guzzle\Plugin\Cache
Definition: CacheKeyProviderInterface.php:3
Guzzle\Plugin\Cache\DefaultCanCacheStrategy
Definition: DefaultCanCacheStrategy.php:11
Guzzle\Http\Message\Response
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Plugin\Cache\CallbackCanCacheStrategy\$requestCallback
$requestCallback
Definition: CallbackCanCacheStrategy.php:18
Guzzle\Common\Exception\InvalidArgumentException
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Exception/InvalidArgumentException.php:5
Guzzle\Plugin\Cache\CallbackCanCacheStrategy
Definition: CallbackCanCacheStrategy.php:12
Guzzle\Plugin\Cache\CallbackCanCacheStrategy\canCacheResponse
canCacheResponse(Response $response)
Definition: CallbackCanCacheStrategy.php:53