Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • CachePlugin
  • CallbackCacheKeyProvider
  • CallbackCanCacheStrategy
  • DefaultCacheKeyProvider
  • DefaultCacheStorage
  • DefaultCanCacheStrategy
  • DefaultRevalidation
  • DenyRevalidation
  • SkipRevalidation

Interfaces

  • CacheKeyProviderInterface
  • CacheStorageInterface
  • CanCacheStrategyInterface
  • RevalidationInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Plugin\Cache;
 4: 
 5: use Guzzle\Common\Exception\InvalidArgumentException;
 6: use Guzzle\Http\Message\RequestInterface;
 7: use Guzzle\Http\Message\Response;
 8: 
 9: /**
10:  * Determines if a request can be cached using a callback
11:  */
12: class CallbackCanCacheStrategy extends DefaultCanCacheStrategy
13: {
14:     /**
15:      * @var callable Callback for request
16:      */
17:     protected $requestCallback;
18: 
19:     /**
20:      * @var callable Callback for response
21:      */
22:     protected $responseCallback;
23: 
24:     /**
25:      * @param \Closure|array|mixed $requestCallback  Callable method to invoke for requests
26:      * @param \Closure|array|mixed $responseCallback Callable method to invoke for responses
27:      *
28:      * @throws InvalidArgumentException
29:      */
30:     public function __construct($requestCallback = null, $responseCallback = null)
31:     {
32:         if ($requestCallback && !is_callable($requestCallback)) {
33:             throw new InvalidArgumentException('Method must be callable');
34:         }
35: 
36:         if ($responseCallback && !is_callable($responseCallback)) {
37:             throw new InvalidArgumentException('Method must be callable');
38:         }
39: 
40:         $this->requestCallback = $requestCallback;
41:         $this->responseCallback = $responseCallback;
42:     }
43: 
44:     /**
45:      * {@inheritdoc}
46:      */
47:     public function canCacheRequest(RequestInterface $request)
48:     {
49:         return $this->requestCallback
50:             ? call_user_func($this->requestCallback, $request)
51:             : parent::canCache($request);
52:     }
53: 
54:     /**
55:      * {@inheritdoc}
56:      */
57:     public function canCacheResponse(Response $response)
58:     {
59:         return $this->responseCallback
60:             ? call_user_func($this->responseCallback, $response)
61:             : parent::canCacheResponse($response);
62:     }
63: }
64: 
php-coveralls API documentation generated by ApiGen 2.8.0