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


PHP Response::isNotModified方法代码示例

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


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

示例1: intercept

 public function intercept(MethodInvocation $invocation)
 {
     /*
      * First let's make sure we can even bother caching this
      * if we can't then just return the controller response
      */
     if (!$this->decider->decide()) {
         return $invocation->proceed();
     }
     /* @var $controller ResourceController */
     $controller = $invocation->object;
     /* @var $request Request */
     $request = $invocation->arguments[0];
     // Current Resource
     $resource = $controller->findOr404($request);
     // Cache Options
     $options = $request->attributes->get('_sylius', []);
     $cacheOptions = array_key_exists('cache', $options) ? $options['cache'] : [];
     // Build the actual cache options since we'll need to use it twice
     $this->parser->process($cacheOptions, $resource);
     // Create a preliminary response to see if it is already cached
     $cachedResponse = new Response();
     $cachedResponse->setCache($cacheOptions);
     if ($cachedResponse->isNotModified($request)) {
         return $cachedResponse;
     }
     // If not we take the response back from the controller and modify it again
     $controllerResponse = $invocation->proceed();
     $controllerResponse->setCache($cacheOptions);
     return $controllerResponse;
 }
开发者ID:symedit,项目名称:symedit,代码行数:31,代码来源:SyliusResourceInterceptor.php

示例2: handle

 function handle(Request $request, $type = HttpFoundation::MASTER_REQUEST, $catch = true)
 {
     $pathinfo = $request->getPathInfo();
     if (preg_match('{^/_pipe/(.+)$}', $pathinfo, $matches)) {
         $path = $matches[1];
         if (!$path or !($asset = $this->env->find($path, array('bundled' => true)))) {
             $this->log->error("pipe: Asset '{$path}' not found");
             return new Response('Not Found', 404);
         }
         $lastModified = new \DateTime();
         $lastModified->setTimestamp($asset->getLastModified());
         $response = new Response();
         $response->setPublic();
         $response->setLastModified($lastModified);
         if ($response->isNotModified($request)) {
             $this->log->info("pipe: 302 {$path}");
             return $response;
         }
         $start = microtime(true);
         $response->setContent($asset->getBody());
         $this->log->info(sprintf('pipe: Rendered "%s" in %d seconds', $path, microtime(true) - $start));
         $response->headers->set('Content-Type', $asset->getContentType());
         $response->prepare($request);
         return $response;
     }
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:chh,项目名称:pipe,代码行数:27,代码来源:Middleware.php

示例3: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $annotation = $this->findAnnotation($controller);
     if (!$annotation) {
         return;
     }
     $lastTouched = $annotation->calculateLastModified($this->metaQueryFactory);
     if (!$lastTouched) {
         return;
     }
     $this->lastTouchedResults[$request] = $lastTouched;
     /*
      * Für kernel.debug = 1 senden wir niemals
      * 304-Responses, anstatt den Kernel auszuführen:
      *
      * Das Ergebnis hängt auch von vielen Dingen außerhalb
      * wfd_meta ab (z. B. template-Code), die wir hier nicht
      * berücksichtigen können.
      */
     if ($this->debug) {
         return;
     }
     $response = new Response();
     $response->setLastModified($lastTouched);
     if ($response->isNotModified($request)) {
         $event->setController(function () use($response) {
             return $response;
         });
     }
 }
开发者ID:webfactory,项目名称:wfdmeta-bundle,代码行数:32,代码来源:EventListener.php

示例4: resultatAction

 public function resultatAction(Request $request, AbstractTerritoire $territoire)
 {
     $response = new Response();
     $response->setLastModified($this->get('repository.cache_info')->getLastModified($territoire));
     $response->setPublic();
     if ($response->isNotModified($request)) {
         return $response;
     }
     $allEcheances = $this->get('repository.echeance')->getAll();
     $form = $this->createForm(new EcheanceChoiceType($allEcheances), array(), array('method' => 'GET'));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid() && ($data = $form->getData())) {
         $reference = $data['comparaison'] ? $data['comparaison']->getNom() : null;
         $echeances = $data['echeances'];
         if (!in_array($reference, $echeances->toArray(), true)) {
             $reference = null;
         }
     } else {
         $echeances = array_filter($allEcheances, function ($element) {
             return $element->getType() !== Echeance::MUNICIPALES;
         });
         $reference = null;
         $form->get('echeances')->setData(new ArrayCollection($echeances));
     }
     $results = $this->getResults($territoire, $echeances);
     return $this->render('resultat.html.twig', array('form' => $form->createView(), 'resultats' => $results, 'territoire' => $territoire->getNom(), 'reference' => $reference), $response);
 }
开发者ID:AlexisEidelman,项目名称:dataelections.fr,代码行数:27,代码来源:ResultatController.php

示例5: getResponse

 /**
  * Handle a request for a file
  *
  * @param Request $request HTTP request
  * @return Response
  */
 public function getResponse(Request $request)
 {
     $response = new Response();
     $response->prepare($request);
     $path = implode('/', $request->getUrlSegments());
     if (!preg_match('~serve-file/e(\\d+)/l(\\d+)/d([ia])/c([01])/([a-zA-Z0-9\\-_]+)/(.*)$~', $path, $m)) {
         return $response->setStatusCode(400)->setContent('Malformatted request URL');
     }
     list(, $expires, $last_updated, $disposition, $use_cookie, $mac, $path_from_dataroot) = $m;
     if ($expires && $expires < time()) {
         return $response->setStatusCode(403)->setContent('URL has expired');
     }
     $hmac_data = array('expires' => (int) $expires, 'last_updated' => (int) $last_updated, 'disposition' => $disposition, 'path' => $path_from_dataroot, 'use_cookie' => (int) $use_cookie);
     if ((bool) $use_cookie) {
         $hmac_data['cookie'] = $this->getCookieValue($request);
     }
     ksort($hmac_data);
     $hmac = $this->crypto->getHmac($hmac_data);
     if (!$hmac->matchesToken($mac)) {
         return $response->setStatusCode(403)->setContent('HMAC mistmatch');
     }
     $dataroot = $this->config->getDataPath();
     $filenameonfilestore = "{$dataroot}{$path_from_dataroot}";
     if (!is_readable($filenameonfilestore)) {
         return $response->setStatusCode(404)->setContent('File not found');
     }
     $actual_last_updated = filemtime($filenameonfilestore);
     if ($actual_last_updated != $last_updated) {
         return $response->setStatusCode(403)->setContent('URL has expired');
     }
     $if_none_match = $request->headers->get('if_none_match');
     if (!empty($if_none_match)) {
         // strip mod_deflate suffixes
         $request->headers->set('if_none_match', str_replace('-gzip', '', $if_none_match));
     }
     $etag = '"' . $actual_last_updated . '"';
     $response->setPublic()->setEtag($etag);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $public = $use_cookie ? false : true;
     $content_disposition = $disposition == 'i' ? 'inline' : 'attachment';
     $headers = ['Content-Type' => (new MimeTypeDetector())->getType($filenameonfilestore)];
     $response = new BinaryFileResponse($filenameonfilestore, 200, $headers, $public, $content_disposition);
     $sendfile_type = $this->config->getVolatile('X-Sendfile-Type');
     if ($sendfile_type) {
         $request->headers->set('X-Sendfile-Type', $sendfile_type);
         $mapping = (string) $this->config->getVolatile('X-Accel-Mapping');
         $request->headers->set('X-Accel-Mapping', $mapping);
         $response->trustXSendfileTypeHeader();
     }
     $response->prepare($request);
     if (empty($expires)) {
         $expires = strtotime('+1 year');
     }
     $expires_dt = (new DateTime())->setTimestamp($expires);
     $response->setExpires($expires_dt);
     $response->setEtag($etag);
     return $response;
 }
开发者ID:elgg,项目名称:elgg,代码行数:66,代码来源:ServeFileHandler.php

示例6: getResponse

 /**
  * Handle a request for a file
  *
  * @param Request $request HTTP request
  * @return Response
  */
 public function getResponse($request)
 {
     $response = new Response();
     $response->prepare($request);
     $path = implode('/', $request->getUrlSegments());
     if (!preg_match('~download-file/g(\\d+)$~', $path, $m)) {
         return $response->setStatusCode(400)->setContent('Malformatted request URL');
     }
     $this->application->start();
     $guid = (int) $m[1];
     $file = get_entity($guid);
     if (!$file instanceof ElggFile) {
         return $response->setStatusCode(404)->setContent("File with guid {$guid} does not exist");
     }
     $filenameonfilestore = $file->getFilenameOnFilestore();
     if (!is_readable($filenameonfilestore)) {
         return $response->setStatusCode(404)->setContent('File not found');
     }
     $last_updated = filemtime($filenameonfilestore);
     $etag = '"' . $last_updated . '"';
     $response->setPublic()->setEtag($etag);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $response = new BinaryFileResponse($filenameonfilestore, 200, array(), false, 'attachment');
     $response->prepare($request);
     $expires = strtotime('+1 year');
     $expires_dt = (new DateTime())->setTimestamp($expires);
     $response->setExpires($expires_dt);
     $response->setEtag($etag);
     return $response;
 }
开发者ID:nirajkaushal,项目名称:Elgg,代码行数:38,代码来源:DownloadFileHandler.php

示例7: createFileResponse

 /**
  * @param Request $request
  * @param $storageKey
  *
  * @return Response
  */
 protected function createFileResponse(Request $request, $storageKey)
 {
     $response = new Response();
     $parts = explode('/', $storageKey);
     $file = $this->getFile($parts[0]);
     if (!$file) {
         return $response->setContent('File not found.')->setStatusCode(Response::HTTP_NOT_FOUND);
     }
     if ($request->get('dl') !== null) {
         $filename = $file->getFilename();
         if (count($parts) > 1) {
             $filename = $parts[count($parts) - 1];
         }
         $filenameFallback = filter_var($filename, FILTER_SANITIZE_URL);
         if ($filenameFallback != $filename) {
             $guesser = ExtensionGuesser::getInstance();
             $extension = filter_var($guesser->guess($file->getMimeType()) ?: $file->getExtension(), FILTER_SANITIZE_URL);
             $filenameFallback = $file->getStorageKey() . ($extension ? '.' . $extension : '');
         }
         $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, $filenameFallback));
     } else {
         $response->setCache(array('etag' => $file->getStorageKey(), 'last_modified' => $file->getCreatedAt()));
         if ($response->isNotModified($request)) {
             return $response;
         }
     }
     $response->setContent($file->getContents());
     $response->headers->set('Content-type', $file->getMimeType());
     $response->headers->set('Content-length', $file->getSize());
     return $response;
 }
开发者ID:modera,项目名称:foundation,代码行数:37,代码来源:StoredFileController.php

示例8: viewAction

 /**
  * View a single content page
  *
  * This Controller action is being routed to from either our custom ContentRouter,
  * or the ExceptionController.
  * @see Opifer\SiteBundle\Router\ContentRouter
  *
  * @param Request          $request
  * @param ContentInterface $content
  * @param int              $statusCode
  *
  * @return Response
  *
  * @throws \Exception
  */
 public function viewAction(Request $request, ContentInterface $content, $statusCode = 200)
 {
     $version = $request->query->get('_version');
     $debug = $this->getParameter('kernel.debug');
     $contentDate = $content->getUpdatedAt();
     $templateDate = $content->getTemplate()->getUpdatedAt();
     $date = $contentDate > $templateDate ? $contentDate : $templateDate;
     $response = new Response();
     $response->setLastModified($date);
     $response->setPublic();
     if (null === $version && false == $debug && $response->isNotModified($request)) {
         // return the 304 Response immediately
         return $response;
     }
     $version = $request->query->get('_version');
     /** @var Environment $environment */
     $environment = $this->get('opifer.content.block_environment');
     $environment->setObject($content);
     $response->setStatusCode($statusCode);
     if (null !== $version && $this->isGranted('ROLE_ADMIN')) {
         $environment->setDraft(true);
     }
     $environment->load();
     return $this->render($environment->getView(), $environment->getViewParameters(), $response);
 }
开发者ID:Opifer,项目名称:Cms,代码行数:40,代码来源:ContentController.php

示例9: getResponse

 private function getResponse(Request $request, $name, array $files, $content_type)
 {
     if (!isset($files[$name])) {
         return new Response('Not Found', 404, array('Content-Type' => 'text/plain'));
     }
     $file = $files[$name];
     $response = new Response();
     $response->setPublic();
     $response->setMaxAge(self::EXPIRED_TIME);
     $response->setSharedMaxAge(self::EXPIRED_TIME);
     $response->headers->set('Content-Type', $content_type);
     // set a custom Cache-Control directive
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $date = new \DateTime();
     $date->setTimestamp(strtotime($this->container->getParameter('sf.version')));
     $response->setETag($date->getTimestamp());
     $response->setLastModified($date);
     if ($response->isNotModified($request)) {
         return $response;
     }
     if (!file_exists($file)) {
         throw new \Exception(sprintf("file `%s`, `%s` not exists", $name, $file));
     }
     $response->setContent(file_get_contents($file));
     return $response;
 }
开发者ID:symforce,项目名称:symforce-admin,代码行数:26,代码来源:IeController.php

示例10: get_post

 public function get_post()
 {
     if (!$this->check_board()) {
         return $this->response->setData(['error' => _i('No board was selected.')])->setStatusCode(422);
     }
     $num = $this->getQuery('num');
     if (!$num) {
         return $this->response->setData(['error' => _i('The "num" parameter is missing.')])->setStatusCode(422);
     }
     if (!Board::isValidPostNumber($num)) {
         return $this->response->setData(['error' => _i('The value for "num" is invalid.')])->setStatusCode(422);
     }
     try {
         $board = Board::forge($this->getContext())->getPost($num)->setRadix($this->radix);
         $comment = current($board->getComments());
         $this->apify($comment);
         $last_modified = $comment->comment->timestamp_expired ?: $comment->comment->timestamp;
         $this->setLastModified($last_modified);
         if (!$this->response->isNotModified($this->request)) {
             $this->response->setData($comment);
         }
     } catch (\Foolz\Foolslide\Model\BoardPostNotFoundException $e) {
         return $this->response->setData(['error' => _i('Post not found.')]);
     } catch (\Foolz\Foolslide\Model\BoardException $e) {
         return $this->response->setData(['error' => $e->getMessage()])->setStatusCode(500);
     }
     return $this->response;
 }
开发者ID:KasaiDot,项目名称:FoolSlide2,代码行数:28,代码来源:Chan.php

示例11: onKernelController

 /**
  * Handles HTTP validation headers.
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     if (!($configuration = $request->attributes->get('_cache'))) {
         return;
     }
     $response = new Response();
     $lastModifiedDate = '';
     if ($configuration->getLastModified()) {
         $lastModifiedDate = $this->getExpressionLanguage()->evaluate($configuration->getLastModified(), $request->attributes->all());
         $response->setLastModified($lastModifiedDate);
     }
     $etag = '';
     if ($configuration->getETag()) {
         $etag = hash('sha256', $this->getExpressionLanguage()->evaluate($configuration->getETag(), $request->attributes->all()));
         $response->setETag($etag);
     }
     if ($response->isNotModified($request)) {
         $event->setController(function () use($response) {
             return $response;
         });
     } else {
         if ($etag) {
             $this->etags[$request] = $etag;
         }
         if ($lastModifiedDate) {
             $this->lastModifiedDates[$request] = $lastModifiedDate;
         }
     }
 }
开发者ID:raphydev,项目名称:onep,代码行数:33,代码来源:HttpCacheListener.php

示例12: indexAction

 public function indexAction()
 {
     $response = new Response();
     $response->setPublic();
     if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) {
         $response->setETag(md5((string) $this->getUser()->getType()));
         switch ($this->getUser()->getType()) {
             case 'publisher':
                 $homepage = 'Publisher';
                 break;
             case 'advertiser':
                 $homepage = 'Advertiser';
                 break;
         }
         $response->setMaxAge(60 * 30);
     } else {
         $response->setETag(md5('public'));
         $homepage = 'Public';
         $response->setMaxAge(60 * 60 * 10);
     }
     $response->headers->set('Vary', 'Cookie');
     // $response->headers->addCacheControlDirective('must-revalidate', true);
     if ($response->isNotModified($this->getRequest())) {
         return $response;
     }
     return $this->render('VifeedFrontendBundle:' . $homepage . ':homepage.html.twig', [], $response);
 }
开发者ID:bzis,项目名称:zomba,代码行数:27,代码来源:DefaultController.php

示例13: handle

 function handle(HttpFoundation\Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $path = ltrim($request->getPathInfo(), '/');
     $asset = $this->environment->find($path, array("bundled" => true));
     $debug = $request->query->get("debug", false);
     $cache = !$request->query->get("nocache", false);
     if (!$asset or $path == '') {
         return $this->renderNotFound($request);
     }
     if ($debug) {
         $this->environment->bundleProcessors->clear();
     }
     $lastModified = new \DateTime();
     $lastModified->setTimestamp($asset->getLastModified());
     $response = new HttpFoundation\Response();
     $response->setPublic();
     $response->setLastModified($lastModified);
     if ($cache and $response->isNotModified($request)) {
         return $response;
     }
     $response->setContent($asset->getBody());
     $response->headers->set('Content-Type', $asset->getContentType());
     $response->prepare($request);
     return $response;
 }
开发者ID:chh,项目名称:pipe,代码行数:25,代码来源:Server.php

示例14: hasCachedResponse

 public function hasCachedResponse(Request $request, DateTime $lastWriteTime)
 {
     $response = new Response();
     $response->setLastModified($lastWriteTime);
     if ($response->isNotModified($request)) {
         return $response;
     }
     return false;
 }
开发者ID:vbessonov,项目名称:fsrapi,代码行数:9,代码来源:FileSystemTrait.php

示例15: renderAction

 public function renderAction(Request $request, $ulClass = null)
 {
     $lastUpdated = $this->getPageRepository()->getLastUpdated();
     $response = new Response();
     $response->setLastModified($lastUpdated)->setPublic();
     if ($response->isNotModified($request)) {
         return $response;
     }
     return $this->render('@SymEdit/Menu/render.html.twig', ['ulClass' => $ulClass], $response);
 }
开发者ID:symedit,项目名称:symedit,代码行数:10,代码来源:MenuController.php


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