本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getETags方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getETags方法的具体用法?PHP Request::getETags怎么用?PHP Request::getETags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getETags方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createContexts
public function createContexts(Request $request)
{
$map = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_route' => $request->attributes->get('_route'), 'request_host' => $request->getHost(), 'request_port' => $request->getPort(), 'request_scheme' => $request->getScheme(), 'request_client_ip' => $request->getClientIp(), 'request_content_type' => $request->getContentType(), 'request_acceptable_content_types' => $request->getAcceptableContentTypes(), 'request_etags' => $request->getETags(), 'request_charsets' => $request->getCharsets(), 'request_languages' => $request->getLanguages(), 'request_locale' => $request->getLocale(), 'request_auth_user' => $request->getUser(), 'request_auth_has_password' => !is_null($request->getPassword()));
// Attributes from newer versions.
if (method_exists($request, 'getEncodings')) {
$map['request_encodings'] = $request->getEncodings();
}
if (method_exists($request, 'getClientIps')) {
$map['request_client_ips'] = $request->getClientIps();
}
return $map;
}
示例2: logRequest
protected function logRequest(Request $request)
{
$msg = 'Request "{request_method} {request_uri}"';
$map = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_host' => $request->getHost(), 'request_port' => $request->getPort(), 'request_scheme' => $request->getScheme(), 'request_client_ip' => $request->getClientIp(), 'request_content_type' => $request->getContentType(), 'request_acceptable_content_types' => $request->getAcceptableContentTypes(), 'request_etags' => $request->getETags(), 'request_charsets' => $request->getCharsets(), 'request_languages' => $request->getLanguages(), 'request_locale' => $request->getLocale(), 'request_auth_user' => $request->getUser(), 'request_auth_has_password' => !is_null($request->getPassword()));
// Attributes from newer versions.
if (method_exists($request, 'getEncodings')) {
$map['request_encodings'] = $request->getEncodings();
}
if (method_exists($request, 'getClientIps')) {
$map['request_client_ips'] = $request->getClientIps();
}
$this->logger->log($this->logLevel, $msg, $map);
}
示例3: validate
/**
* Validates that a cache entry is fresh.
*
* The original request is used as a template for a conditional
* GET request with the backend.
*
* @param Request $request A Request instance
* @param Response $entry A Response instance to validate
* @param bool $catch Whether to process exceptions
*
* @return Response A Response instance
*/
protected function validate(Request $request, Response $entry, $catch = false)
{
$subRequest = clone $request;
// send no head requests because we want content
$subRequest->setMethod('GET');
// add our cached last-modified validator
$subRequest->headers->set('if_modified_since', $entry->headers->get('Last-Modified'));
// Add our cached etag validator to the environment.
// We keep the etags from the client to handle the case when the client
// has a different private valid entry which is not cached here.
$cachedEtags = $entry->getEtag() ? array($entry->getEtag()) : array();
$requestEtags = $request->getETags();
if ($etags = array_unique(array_merge($cachedEtags, $requestEtags))) {
$subRequest->headers->set('if_none_match', implode(', ', $etags));
}
$response = $this->forward($subRequest, $catch, $entry);
if (304 == $response->getStatusCode()) {
$this->record($request, 'valid');
// return the response and not the cache entry if the response is valid but not cached
$etag = $response->getEtag();
if ($etag && in_array($etag, $requestEtags) && !in_array($etag, $cachedEtags)) {
return $response;
}
$entry = clone $entry;
$entry->headers->remove('Date');
foreach (array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified') as $name) {
if ($response->headers->has($name)) {
$entry->headers->set($name, $response->headers->get($name));
}
}
$response = $entry;
} else {
$this->record($request, 'invalid');
}
if ($response->isCacheable()) {
$this->store($request, $response);
}
return $response;
}
示例4: convertVersion
/**
* @param Request $request
* @param ParamConfiguration $configuration
* @return integer
* @throws BadRequestHttpException
* @throws PreconditionFailedHttpException
*/
protected function convertVersion(Request $request, ParamConfiguration $configuration)
{
$eTags = (array) $request->getETags();
$eTag = reset($eTags);
if (empty($eTag)) {
throw new BadRequestHttpException("Expected version header.");
}
$id = $request->attributes->get($configuration->getOptions()['id']);
$retrieverMethod = $this->inflectRetrieverMethod($configuration);
$entity = $this->{$retrieverMethod}($id);
$tag = hash('sha256', $entity->getId() . $entity->getVersion());
if ($eTag !== $tag) {
throw new PreconditionFailedHttpException("Expected version does not match actual version.");
}
return $entity->getVersion();
}