Drupal 8  8.0.2
FinishResponseSubscriber Class Reference
Inheritance diagram for FinishResponseSubscriber:

Public Member Functions

 __construct (LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory, RequestPolicyInterface $request_policy, ResponsePolicyInterface $response_policy, CacheContextsManager $cache_contexts_manager, $http_response_debug_cacheability_headers=FALSE)
 
 onRespond (FilterResponseEvent $event)
 

Static Public Member Functions

static getSubscribedEvents ()
 

Protected Member Functions

 isCacheControlCustomized (Response $response)
 
 setResponseNotCacheable (Response $response, Request $request)
 
 setResponseCacheable (Response $response, Request $request)
 
 setCacheControlNoCache (Response $response)
 
 setExpiresNoCache (Response $response)
 

Protected Attributes

 $languageManager
 
 $config
 
 $requestPolicy
 
 $responsePolicy
 
 $cacheContexts
 
 $debugCacheabilityHeaders = FALSE
 

Detailed Description

Response subscriber to handle finished responses.

Constructor & Destructor Documentation

__construct ( LanguageManagerInterface  $language_manager,
ConfigFactoryInterface  $config_factory,
RequestPolicyInterface  $request_policy,
ResponsePolicyInterface  $response_policy,
CacheContextsManager  $cache_contexts_manager,
  $http_response_debug_cacheability_headers = FALSE 
)

Constructs a FinishResponseSubscriber object.

Parameters
\Drupal\Core\Language\LanguageManagerInterface$language_managerThe language manager object for retrieving the correct language code.
\Drupal\Core\Config\ConfigFactoryInterface$config_factoryA config factory for retrieving required config objects.
\Drupal\Core\PageCache\RequestPolicyInterface$request_policyA policy rule determining the cacheability of a request.
\Drupal\Core\PageCache\ResponsePolicyInterface$response_policyA policy rule determining the cacheability of a response.
\Drupal\Core\Cache\Context\CacheContextsManager$cache_contexts_managerThe cache contexts manager service.
bool$http_response_debug_cacheability_headers(optional) Whether to send cacheability headers for debugging purposes.

References Drupal\config(), ConfigFactoryInterface\get(), and Drupal\languageManager().

Here is the call graph for this function:

Member Function Documentation

static getSubscribedEvents ( )
static

Registers the methods in this class that should be listeners.

Returns
array An array of event listener definitions.
isCacheControlCustomized ( Response  $response)
protected

Determine whether the given response has a custom Cache-Control header.

Upon construction, the ResponseHeaderBag is initialized with an empty Cache-Control header. Consequently it is not possible to check whether the header was set explicitly by simply checking its presence. Instead, it is necessary to examine the computed Cache-Control header and compare with values known to be present only when Cache-Control was never set explicitly.

When neither Cache-Control nor any of the ETag, Last-Modified, Expires headers are set on the response, ::get('Cache-Control') returns the value 'no-cache'. If any of ETag, Last-Modified or Expires are set but not Cache-Control, then 'private, must-revalidate' (in exactly this order) is returned.

See Also
::computeCacheControlValue()
Parameters
\Symfony\Component\HttpFoundation\Response$response
Returns
bool TRUE when Cache-Control header was set explicitly on the given response.

Referenced by FinishResponseSubscriber\onRespond().

Here is the caller graph for this function:

onRespond ( FilterResponseEvent  $event)

Sets extra headers on successful responses.

Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent$eventThe event to process.

References RequestPolicyInterface\ALLOW, Drupal\config(), ResponsePolicyInterface\DENY, FinishResponseSubscriber\isCacheControlCustomized(), Drupal\languageManager(), FinishResponseSubscriber\setExpiresNoCache(), FinishResponseSubscriber\setResponseCacheable(), and FinishResponseSubscriber\setResponseNotCacheable().

Here is the call graph for this function:

setCacheControlNoCache ( Response  $response)
protected

Disable caching in the browser and for HTTP/1.1 proxies and clients.

Parameters
\Symfony\Component\HttpFoundation\Response$responseA response object.

Referenced by FinishResponseSubscriber\setResponseNotCacheable().

Here is the caller graph for this function:

setExpiresNoCache ( Response  $response)
protected

Disable caching in ancient browsers and for HTTP/1.0 proxies and clients.

HTTP/1.0 proxies do not support the Vary header, so prevent any caching by sending an Expires date in the past. HTTP/1.1 clients ignore the Expires header if a Cache-Control: max-age= directive is specified (see RFC 2616, section 14.9.3).

Parameters
\Symfony\Component\HttpFoundation\Response$responseA response object.

Referenced by FinishResponseSubscriber\onRespond(), FinishResponseSubscriber\setResponseCacheable(), and FinishResponseSubscriber\setResponseNotCacheable().

Here is the caller graph for this function:

setResponseCacheable ( Response  $response,
Request  $request 
)
protected

Add Cache-Control and Expires headers to a cacheable response.

Parameters
\Symfony\Component\HttpFoundation\Response$responseA response object.
\Symfony\Component\HttpFoundation\Request$requestA request object.

References Drupal\config(), Settings\get(), DateTimePlus\RFC7231, and FinishResponseSubscriber\setExpiresNoCache().

Referenced by FinishResponseSubscriber\onRespond().

Here is the call graph for this function:

Here is the caller graph for this function:

setResponseNotCacheable ( Response  $response,
Request  $request 
)
protected

Add Cache-Control and Expires headers to a response which is not cacheable.

Parameters
\Symfony\Component\HttpFoundation\Response$responseA response object.
\Symfony\Component\HttpFoundation\Request$requestA request object.

References FinishResponseSubscriber\setCacheControlNoCache(), and FinishResponseSubscriber\setExpiresNoCache().

Referenced by FinishResponseSubscriber\onRespond().

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: