mirror of
https://0xacab.org/radar/radar-wp.git
synced 2025-06-09 13:16:26 +02:00
Initial import.
This commit is contained in:
commit
86383280c9
428 changed files with 68738 additions and 0 deletions
53
vendor/guzzle/plugin-cache/Guzzle/Plugin/Cache/CallbackCanCacheStrategy.php
vendored
Normal file
53
vendor/guzzle/plugin-cache/Guzzle/Plugin/Cache/CallbackCanCacheStrategy.php
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Guzzle\Plugin\Cache;
|
||||
|
||||
use Guzzle\Common\Exception\InvalidArgumentException;
|
||||
use Guzzle\Http\Message\RequestInterface;
|
||||
use Guzzle\Http\Message\Response;
|
||||
|
||||
/**
|
||||
* Determines if a request can be cached using a callback
|
||||
*/
|
||||
class CallbackCanCacheStrategy extends DefaultCanCacheStrategy
|
||||
{
|
||||
/** @var callable Callback for request */
|
||||
protected $requestCallback;
|
||||
|
||||
/** @var callable Callback for response */
|
||||
protected $responseCallback;
|
||||
|
||||
/**
|
||||
* @param \Closure|array|mixed $requestCallback Callable method to invoke for requests
|
||||
* @param \Closure|array|mixed $responseCallback Callable method to invoke for responses
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct($requestCallback = null, $responseCallback = null)
|
||||
{
|
||||
if ($requestCallback && !is_callable($requestCallback)) {
|
||||
throw new InvalidArgumentException('Method must be callable');
|
||||
}
|
||||
|
||||
if ($responseCallback && !is_callable($responseCallback)) {
|
||||
throw new InvalidArgumentException('Method must be callable');
|
||||
}
|
||||
|
||||
$this->requestCallback = $requestCallback;
|
||||
$this->responseCallback = $responseCallback;
|
||||
}
|
||||
|
||||
public function canCacheRequest(RequestInterface $request)
|
||||
{
|
||||
return $this->requestCallback
|
||||
? call_user_func($this->requestCallback, $request)
|
||||
: parent::canCacheRequest($request);
|
||||
}
|
||||
|
||||
public function canCacheResponse(Response $response)
|
||||
{
|
||||
return $this->responseCallback
|
||||
? call_user_func($this->responseCallback, $response)
|
||||
: parent::canCacheResponse($response);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue