当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setEtag方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setEtag方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setEtag方法的具体用法?PHP Response::setEtag怎么用?PHP Response::setEtag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Response的用法示例。


在下文中一共展示了Response::setEtag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 /**
  * {@inheritdoc}
  */
 public function update(Response $response)
 {
     // if we have no embedded Response, do nothing
     if (0 === $this->embeddedResponses) {
         return;
     }
     // Remove validation related headers in order to avoid browsers using
     // their own cache, because some of the response content comes from
     // at least one embedded response (which likely has a different caching strategy).
     if ($response->isValidateable()) {
         $response->setEtag(null);
         $response->setLastModified(null);
         $this->cacheable = false;
     }
     if (!$this->cacheable) {
         $response->headers->set('Cache-Control', 'no-cache, must-revalidate');
         return;
     }
     $this->ttls[] = $response->getTtl();
     $this->maxAges[] = $response->getMaxAge();
     if (null !== ($maxAge = min($this->maxAges))) {
         $response->setSharedMaxAge($maxAge);
         $response->headers->set('Age', $maxAge - min($this->ttls));
     }
     $response->setMaxAge(0);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:29,代码来源:ResponseCacheStrategy.php

示例2: setLastModified

 public function setLastModified($timestamp = 0, $max_age = 0)
 {
     $time = new \DateTime('@' . $timestamp);
     $etag = md5($this->builder->getTheme()->getDir() . $this->builder->getStyle() . '|' . $timestamp . '|' . $max_age);
     $this->response->headers->addCacheControlDirective('must-revalidate', true);
     $this->response->setLastModified($time);
     $this->response->setEtag($etag);
     $this->response->setMaxAge($max_age);
 }
开发者ID:procod3R,项目名称:FoolFuuka,代码行数:9,代码来源:Chan.php

示例3: setHeaders

 /**
  * {@inheritdoc}
  */
 protected function setHeaders(Response $response, ImageInterface $image, \DateTime $lastMod)
 {
     $response->headers->set('Content-type', $image->getMimeType());
     $response->setContent($content = $image->getContents());
     $response->setLastModified($lastMod);
     $response->setEtag(hash('md5', $response->getContent()));
     $response->headers->set('Accept-ranges', 'bytes');
     $response->headers->set('Keep-Alive', 'timeout=15, max=200');
     $response->headers->set('Connection', 'Keep-Alive', true);
 }
开发者ID:rulemaker,项目名称:jitimage,代码行数:13,代码来源:GenericFileResponse.php

示例4: setHttpCacheHeaders

 /**
  * Set the appripriate HTTP cache headers
  *
  * @param \DateTime $lastModified The last time the resource was modified.
  * @param String    $eTag         Unique eTag for the resource.
  * @param Integer   $maxAge       The max age (in seconds).
  * @return Void
  */
 private function setHttpCacheHeaders(\DateTime $lastModified, $eTag, $maxAge)
 {
     $this->response->setMaxAge($maxAge);
     $this->response->setPublic();
     if ($this->maxAge === 0) {
         $this->response->headers->set('Cache-Control', 'no-cache');
         return;
     }
     $this->response->setLastModified($lastModified);
     $this->response->setEtag($eTag);
 }
开发者ID:diarmuidie,项目名称:imagerack-kernel,代码行数:19,代码来源:Server.php

示例5: setHeaders

 /**
  * {@inheritdoc}
  */
 protected function setHeaders(Response $response, ImageInterface $image, \DateTime $lastMod)
 {
     $response->headers->set('Content-type', $image->getMimeType());
     $response->setLastModified($lastMod);
     $response->headers->set('Accept-ranges', 'bytes');
     $response->headers->set('Keep-Alive', 'timeout=5, max=99');
     $response->headers->set('Connection', 'keep-alive', true);
     // return normal by setting image contents;
     if ($image->isProcessed()) {
         $response->setContent($content = $image->getContents());
         $response->setEtag(hash('md5', $content));
     } else {
         // set the xsend header:
         $file = $image->getSource();
         $response->setEtag(md5_file($file));
         $response->headers->set('Content-Length', filesize($file));
         $response->headers->set('Content-Disposition', sprintf('inline; filename="%s"', basename($file)));
         $response->headers->set('X-Sendfile', $file);
     }
 }
开发者ID:rulemaker,项目名称:jitimage,代码行数:23,代码来源:XSendFileResponse.php

示例6: displayTextByIdAction

 /**
  * Display a text by its id
  *
  * @param Request $request
  * @param integer $textId
  *
  * @return Response
  */
 public function displayTextByIdAction(Request $request, $textId)
 {
     $textLastUpdate = $this->textRepository->findLastUpdate(null, null, $textId);
     $response = new Response();
     $response->setPublic();
     $response->setEtag($textId . $textLastUpdate);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $text = $this->textRepository->findOneBy(array('id' => $textId, 'active' => true));
     return $this->render('UnifikSystemBundle:Frontend/Text:displayTexts.html.twig', ['texts' => is_null($text) ? null : array($text), 'textId' => $textId], $response);
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:20,代码来源:TextController.php

示例7: execute

 public function execute(Request $request, Config $config, WorkingFolder $workingFolder, ResizedImageRepository $resizedImageRepository, CacheManager $cache)
 {
     $fileName = (string) $request->query->get('fileName');
     list($requestedWidth, $requestedHeight) = Image::parseSize((string) $request->get('size'));
     $downloadedFile = new DownloadedFile($fileName, $this->app);
     $downloadedFile->isValid();
     if (!Image::isSupportedExtension(pathinfo($fileName, PATHINFO_EXTENSION), $config->get('thumbnails.bmpSupported'))) {
         throw new InvalidExtensionException('Unsupported image type or not image file');
     }
     Utils::removeSessionCacheHeaders();
     $response = new Response();
     $response->setPublic();
     $response->setEtag(dechex($downloadedFile->getTimestamp()) . "-" . dechex($downloadedFile->getSize()));
     $lastModificationDate = new \DateTime();
     $lastModificationDate->setTimestamp($downloadedFile->getTimestamp());
     $response->setLastModified($lastModificationDate);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $imagePreviewCacheExpires = (int) $config->get('cache.imagePreview');
     if ($imagePreviewCacheExpires > 0) {
         $response->setMaxAge($imagePreviewCacheExpires);
         $expireTime = new \DateTime();
         $expireTime->modify('+' . $imagePreviewCacheExpires . 'seconds');
         $response->setExpires($expireTime);
     }
     $cachedInfoPath = Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName);
     $cachedInfo = $cache->get($cachedInfoPath);
     $resultImage = null;
     // Try to reuse existing resized image
     if ($cachedInfo && isset($cachedInfo['width']) && isset($cachedInfo['height'])) {
         // Fix received aspect ratio
         $size = Image::calculateAspectRatio($requestedWidth, $requestedHeight, $cachedInfo['width'], $cachedInfo['height']);
         $resizedImage = $resizedImageRepository->getResizedImageBySize($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $size['width'], $size['height']);
         if ($resizedImage) {
             $resultImage = Image::create($resizedImage->getImageData());
         }
     }
     // Fallback - get and resize the original image
     if (null === $resultImage) {
         $resultImage = Image::create($downloadedFile->getContents(), $config->get('thumbnails.bmpSupported'));
         $cache->set($cachedInfoPath, $resultImage->getInfo());
         $resultImage->resize($requestedWidth, $requestedHeight);
     }
     $mimeType = $resultImage->getMimeType();
     if (in_array($mimeType, array('image/bmp', 'image/x-ms-bmp'))) {
         $mimeType = 'image/jpeg';
         // Image::getData() by default converts resized images to JPG
     }
     $response->headers->set('Content-Type', $mimeType . '; name="' . $downloadedFile->getFileName() . '"');
     $response->setContent($resultImage->getData());
     return $response;
 }
开发者ID:knodejs,项目名称:ckfinder_gulp,代码行数:53,代码来源:ImagePreview.php

示例8: formAction

 /**
  * @Route("/submit/{id}", name="oro_embedded_form_submit", requirements={"id"="[-\d\w]+"})
  */
 public function formAction(EmbeddedForm $formEntity, Request $request)
 {
     $response = new Response();
     $response->setPublic();
     $response->setEtag($formEntity->getId() . $formEntity->getUpdatedAt()->format(\DateTime::ISO8601));
     if ($response->isNotModified($request)) {
         return $response;
     }
     /** @var EntityManager $em */
     $em = $this->get('doctrine.orm.entity_manager');
     /** @var EmbeddedFormManager $formManager */
     $formManager = $this->get('oro_embedded_form.manager');
     $form = $formManager->createForm($formEntity->getFormType());
     if (in_array($request->getMethod(), ['POST', 'PUT'])) {
         $dataClass = $form->getConfig()->getOption('data_class');
         if (isset($dataClass) && class_exists($dataClass)) {
             $ref = new \ReflectionClass($dataClass);
             $constructor = $ref->getConstructor();
             $data = $constructor && $constructor->getNumberOfRequiredParameters() ? $ref->newInstanceWithoutConstructor() : $ref->newInstance();
             $form->setData($data);
         } else {
             $data = [];
         }
         $event = new EmbeddedFormSubmitBeforeEvent($data, $formEntity);
         $eventDispatcher = $this->get('event_dispatcher');
         $eventDispatcher->dispatch(EmbeddedFormSubmitBeforeEvent::EVENT_NAME, $event);
         $form->submit($request);
         $event = new EmbeddedFormSubmitAfterEvent($data, $formEntity, $form);
         $eventDispatcher->dispatch(EmbeddedFormSubmitAfterEvent::EVENT_NAME, $event);
     }
     if ($form->isValid()) {
         $entity = $form->getData();
         /**
          * Set owner ID (current organization) to concrete form entity
          */
         $entityClass = ClassUtils::getClass($entity);
         $config = $this->get('oro_entity_config.provider.ownership');
         $entityConfig = $config->getConfig($entityClass);
         $formEntityConfig = $config->getConfig($formEntity);
         if ($entityConfig->get('owner_type') === OwnershipType::OWNER_TYPE_ORGANIZATION) {
             $accessor = PropertyAccess::createPropertyAccessor();
             $accessor->setValue($entity, $entityConfig->get('owner_field_name'), $accessor->getValue($formEntity, $formEntityConfig->get('owner_field_name')));
         }
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('oro_embedded_form_success', ['id' => $formEntity->getId()]));
     }
     /** @var EmbedFormLayoutManager $layoutManager */
     $layoutManager = $this->get('oro_embedded_form.embed_form_layout_manager');
     $response->setContent($layoutManager->getLayout($formEntity, $form)->render());
     return $response;
 }
开发者ID:Maksold,项目名称:platform,代码行数:55,代码来源:EmbedFormController.php

示例9: changelogAction

 /**
  * @param Request $request
  *
  * @return Response
  */
 public function changelogAction(Request $request)
 {
     $content = file_get_contents($this->kernelRootDir . '/../changelog.yml');
     $response = new Response();
     $response->setPublic();
     $response->setEtag(md5($content));
     $response->setVary('Accept-Encoding', 'User-Agent');
     if (!$response->isNotModified($request)) {
         $parser = new Parser();
         $response->setLastModified(new \DateTime());
         return $this->engine->renderResponse('@CertificationyWeb/Site/changelog.html.twig', ['changelog' => $parser->parse($content)]);
     }
     return $response;
 }
开发者ID:puterakahfi,项目名称:certificationy-web-platform,代码行数:19,代码来源:SiteController.php

示例10: getAction

 /**
  * Thumbnailing à la volée
  */
 public function getAction($storageKey, $size)
 {
     $file = $this->get('social.picture.storage')->getImagePath($storageKey, $size);
     $response = new Response();
     $lastModif = \DateTime::createFromFormat('U', filemtime($file));
     $response->setLastModified($lastModif);
     $response->setEtag(sha1(filesize($file)));
     $response->setSharedMaxAge(3600);
     if ($response->isNotModified($this->getRequest())) {
         return $response;
     }
     $response->headers->set('X-Sendfile', $file);
     $response->headers->set('Content-Type', 'image/' . pathinfo($storageKey, PATHINFO_EXTENSION));
     $this->get('logger')->debug("{$storageKey} xsended");
     return $response;
 }
开发者ID:xtrasmal,项目名称:iinano,代码行数:19,代码来源:PictureController.php

示例11: execute

 public function execute(Request $request, WorkingFolder $workingFolder, Config $config, ThumbnailRepository $thumbnailRepository)
 {
     if (!$config->get('thumbnails.enabled')) {
         throw new CKFinderException('Thumbnails feature is disabled', Error::THUMBNAILS_DISABLED);
     }
     $fileName = $request->get('fileName');
     $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
     if (!Image::isSupportedExtension($ext, $thumbnailRepository->isBitmapSupportEnabled())) {
         throw new InvalidNameException('Invalid source file name');
     }
     if (null === $fileName || !File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException('Invalid file name');
     }
     list($requestedWidth, $requestedHeight) = Image::parseSize($request->get('size'));
     $thumbnail = $thumbnailRepository->getThumbnail($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $requestedWidth, $requestedHeight);
     /**
      * This was added on purpose to reset any Cache-Control headers set
      * for example by session_start(). Symfony Session has a workaround,
      * but but we can't rely on this as application may not use Symfony
      * components to handle sessions.
      */
     header('Cache-Control:');
     $response = new Response();
     $response->setPublic();
     $response->setEtag(dechex($thumbnail->getTimestamp()) . "-" . dechex($thumbnail->getSize()));
     $lastModificationDate = new \DateTime();
     $lastModificationDate->setTimestamp($thumbnail->getTimestamp());
     $response->setLastModified($lastModificationDate);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $thumbnailsCacheExpires = (int) $config->get('cache.thumbnails');
     if ($thumbnailsCacheExpires > 0) {
         $response->setMaxAge($thumbnailsCacheExpires);
         $expireTime = new \DateTime();
         $expireTime->modify('+' . $thumbnailsCacheExpires . 'seconds');
         $response->setExpires($expireTime);
     }
     $response->headers->set('Content-Type', $thumbnail->getMimeType() . '; name="' . $thumbnail->getFileName() . '"');
     $response->setContent($thumbnail->getImageData());
     return $response;
 }
开发者ID:SevenMonks,项目名称:100cities-dev,代码行数:42,代码来源:Thumbnail.php

示例12: serialize

 /**
  * @param mixed  $value   to be serialized
  * @param mixed  $context Serialization context
  * @param string $format
  *
  * @return Response
  */
 protected function serialize($value, $context = null, $format = null, Response $response = null)
 {
     $request = $this->get('request_stack')->getCurrentRequest();
     if ($format === null) {
         $format = $this->getParameter('exsyst_api.serializer.default_format');
     }
     if ($response === null) {
         $response = new Response();
     }
     $serializedValue = $this->serializeView($value, $context, $format);
     $response->setContent($serializedValue);
     $response->headers->set('Content-Type', $request->getMimeType($format));
     $etagGenerator = $this->get('exsyst_api.etag_generator');
     $etag = $etagGenerator->generate($response->getContent());
     if ($etag !== false) {
         $response->setEtag($etag->getValue(), $etag->isWeak());
         $response->isNotModified($request);
     }
     return $response;
 }
开发者ID:EXSyst,项目名称:ApiBundle,代码行数:27,代码来源:ApiController.php

示例13: execute

 public function execute(Request $request, WorkingFolder $workingFolder, Config $config, ThumbnailRepository $thumbnailRepository)
 {
     if (!$config->get('thumbnails.enabled')) {
         throw new CKFinderException('Thumbnails feature is disabled', Error::THUMBNAILS_DISABLED);
     }
     $fileName = (string) $request->get('fileName');
     $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
     if (!Image::isSupportedExtension($ext, $thumbnailRepository->isBitmapSupportEnabled())) {
         throw new InvalidNameException('Invalid source file name');
     }
     if (null === $fileName || !File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
         throw new InvalidRequestException('Invalid file name');
     }
     if (!$workingFolder->containsFile($fileName)) {
         throw new FileNotFoundException();
     }
     list($requestedWidth, $requestedHeight) = Image::parseSize((string) $request->get('size'));
     $thumbnail = $thumbnailRepository->getThumbnail($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $requestedWidth, $requestedHeight);
     Utils::removeSessionCacheHeaders();
     $response = new Response();
     $response->setPublic();
     $response->setEtag(dechex($thumbnail->getTimestamp()) . "-" . dechex($thumbnail->getSize()));
     $lastModificationDate = new \DateTime();
     $lastModificationDate->setTimestamp($thumbnail->getTimestamp());
     $response->setLastModified($lastModificationDate);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $thumbnailsCacheExpires = (int) $config->get('cache.thumbnails');
     if ($thumbnailsCacheExpires > 0) {
         $response->setMaxAge($thumbnailsCacheExpires);
         $expireTime = new \DateTime();
         $expireTime->modify('+' . $thumbnailsCacheExpires . 'seconds');
         $response->setExpires($expireTime);
     }
     $response->headers->set('Content-Type', $thumbnail->getMimeType() . '; name="' . $thumbnail->getFileName() . '"');
     $response->setContent($thumbnail->getImageData());
     return $response;
 }
开发者ID:knodejs,项目名称:ckfinder_gulp,代码行数:39,代码来源:Thumbnail.php

示例14: buildResponse

 /**
  * Build the response so that depending on settings it's cacheable
  *
  * @param string|null $etag
  * @param \DateTime|null $lastModified
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function buildResponse($etag = null, DateTime $lastModified = null)
 {
     $request = $this->getRequest();
     $response = new Response();
     if ($this->getParameter('content.view_cache') === true) {
         $response->setPublic();
         if ($etag !== null) {
             $response->setEtag($etag);
         }
         if ($this->getParameter('content.ttl_cache') === true) {
             $response->setSharedMaxAge($this->getParameter('content.default_ttl'));
         }
         // Make the response vary against X-User-Hash header ensures that an HTTP
         // reverse proxy caches the different possible variations of the
         // response as it can depend on user role for instance.
         if ($request->headers->has('X-User-Hash')) {
             $response->setVary('X-User-Hash');
         }
         if ($lastModified != null) {
             $response->setLastModified($lastModified);
         }
     }
     return $response;
 }
开发者ID:Open-Wide,项目名称:OwPublishServiceBundle,代码行数:32,代码来源:ViewController.php

示例15: getForumTopicAction

 /**
  * Get the topic of MAL.
  *
  * @param Request $request HTTP Request object
  * @param int     $id      The ID of the forum topic as assigned by MyAnimeList
  *
  * @return View
  */
 public function getForumTopicAction(Request $request, $id)
 {
     // http://myanimelist.net/forum/?topicid=#{id}
     $page = (int) $request->query->get('page');
     if ($page <= 0) {
         $page = 1;
     }
     if ((int) $id == '') {
         return $this->view(array('error' => 'Invalid topic ID'), 200);
     }
     $downloader = $this->get('atarashii_api.communicator');
     try {
         $forumcontent = $downloader->fetch('/forum/?topicid=' . $id . '&show=' . ($page * 50 - 50));
     } catch (Exception\CurlException $e) {
         return $this->view(array('error' => 'network-error'), 500);
     }
     $forumtopic = ForumParser::parseTopic($forumcontent);
     $response = new Response();
     $response->setPublic();
     $response->setMaxAge(300);
     //5 minutes
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $response->setEtag('forum/topic/' . $id);
     //Also, set "expires" header for caches that don't understand Cache-Control
     $date = new \DateTime();
     $date->modify('+300 seconds');
     //5 minutes
     $response->setExpires($date);
     $view = $this->view($forumtopic);
     $view->setResponse($response);
     $view->setStatusCode(200);
     return $view;
 }
开发者ID:AnimeNeko,项目名称:atarashii-mal-api,代码行数:41,代码来源:ForumController.php


注:本文中的Symfony\Component\HttpFoundation\Response::setEtag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。