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


PHP Response::setPrivate方法代码示例

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


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

示例1: indexAction

 public function indexAction(Request $request)
 {
     $response = new Response();
     $response->setPrivate();
     $response->setContent($this->twig->render('www/Index.twig', array()));
     return $response;
 }
开发者ID:myurasov,项目名称:spa-bootstrap,代码行数:7,代码来源:IndexController.php

示例2: handleResponse

 /**
  * Update a valid non cacheable Response with http cache headers
  *
  * @see http://symfony.com/fr/doc/current/book/http_cache.html
  */
 public function handleResponse(Response $response)
 {
     // do not handle invalid response
     if (!$response->isOk()) {
         return $response;
     }
     // do not handle response with http cache headers
     if ($response->isCacheable()) {
         return $response;
     }
     // seek for optional configuration
     $this->readRoutingConfiguration();
     // mark the response as private
     $response->setPrivate();
     // set the private or shared max age
     $response->setMaxAge($this->duration);
     $response->setSharedMaxAge($this->duration);
     // set expires
     $date = new \DateTime();
     $date->modify(sprintf('+%d seconds', $this->duration));
     $response->setExpires($date);
     // set a custom Cache-Control directive
     $response->headers->addCacheControlDirective('must-revalidate', true);
     return $response;
 }
开发者ID:kmelia,项目名称:fresh-symfony,代码行数:30,代码来源:HttpCacheResponseHandler.php

示例3: render

 /**
  * {@inheritdoc}
  */
 public function render(BlockInterface $block, Response $response = null)
 {
     if ($this->logger) {
         $this->logger->info(sprintf('[cms::renderBlock] block.id=%d, block.type=%s ', $block->getId(), $block->getType()));
     }
     try {
         $service = $this->blockServiceManager->get($block);
         $service->load($block);
         // load the block
         $response = $service->execute($block, $response);
         if (!$response instanceof Response) {
             throw new \RuntimeException('A block service must return a Response object');
         }
     } catch (\Exception $e) {
         if ($this->logger) {
             $this->logger->crit(sprintf('[cms::renderBlock] block.id=%d - error while rendering block - %s', $block->getId(), $e->getMessage()));
         }
         if ($this->debug) {
             throw $e;
         }
         $response = new Response();
         $response->setPrivate();
     }
     return $response;
 }
开发者ID:r1pp3rj4ck,项目名称:SonataBlockBundle,代码行数:28,代码来源:BlockRenderer.php

示例4: setResponseStatus

 /**
  * Set response status
  * 
  * @param Response $response
  * @param string   $status
  */
 protected function setResponseStatus(Response $response, $status)
 {
     if (CacheableInterface::CACHE_PUBLIC == $status) {
         $response->setPublic();
     } else {
         $response->setPrivate();
     }
 }
开发者ID:open-orchestra,项目名称:open-orchestra-display-bundle,代码行数:14,代码来源:CacheableManager.php

示例5: after

 /**
  * {@inheritdoc}
  */
 public function after(Request $request, Response $response)
 {
     if ($this->session()->isStarted()) {
         $response->setPrivate();
     } else {
         $sharedMaxAge = $this->getOption('general/caching/duration', 10) * 60;
         $response->setPublic()->setSharedMaxAge($sharedMaxAge);
     }
 }
开发者ID:bolt,项目名称:bolt,代码行数:12,代码来源:Frontend.php

示例6: setCacheHeaders

 /**
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 public function setCacheHeaders(Request $request, Response $response)
 {
     $response->setMaxAge($this->defaultMaxAge);
     if ($this->isLoggedIn($request) || $this->isWordpressAdminPage($request)) {
         $response->setPrivate();
     } else {
         $response->setPublic();
     }
     return $response;
 }
开发者ID:mindgruve,项目名称:mg-reverse-proxy,代码行数:15,代码来源:WordPressAdapter.php

示例7: embedAction

 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function embedAction(Request $request)
 {
     $response = new Response();
     $response->setPrivate();
     $response->setMaxAge(0);
     $response->setSharedMaxAge(0);
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $response->headers->addCacheControlDirective('no-store', true);
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, 0);
     return $this->render($this->getTemplate(Configuration::TYPE_LOGIN, Configuration::TEMPLATE_FORM_EMBED), ['user' => $this->getUser()], $response);
 }
开发者ID:alexander-schranz,项目名称:sulu-website-user-bundle,代码行数:16,代码来源:LoginController.php

示例8: setPrivateCache

 /**
  * @param Response $response
  * @param Request $request
  *
  * @return ResponseConfigurator
  */
 protected function setPrivateCache(Response $response, Request $request)
 {
     if (!$response->headers->hasCacheControlDirective('private')) {
         $response->setPublic();
         foreach ($this->private_headers as $private_header) {
             if ($request->headers->has($private_header)) {
                 $response->setPrivate();
                 break;
             }
         }
     }
     return $this;
 }
开发者ID:anime-db,项目名称:cache-time-keeper-bundle,代码行数:19,代码来源:ResponseConfigurator.php

示例9: addEntryAction

 /**
  * /token/event.pixel
  *
  * @param string $token Event
  * @param string $event Token
  *
  * @return Response Empty response
  */
 public function addEntryAction($token, $event)
 {
     $requestQuery = $this->requestStack->getCurrentRequest()->query;
     $value = $requestQuery->get('i', 0);
     $type = (int) $requestQuery->get('t', ElcodiMetricTypes::TYPE_BEACON_ALL);
     $this->metricManager->addEntry($token, $event, $value, $type, $this->dateTimeFactory->create());
     $content = base64_decode(self::IMAGE_CONTENT);
     $response = new Response($content);
     $response->setPrivate();
     $response->headers->addCacheControlDirective('no-cache', true);
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $response->headers->set('Content-Type', 'image/png');
     return $response;
 }
开发者ID:axelvnk,项目名称:elcodi,代码行数:22,代码来源:InputController.php

示例10: getResponse

 /**
  * @return Response
  */
 public function getResponse()
 {
     if (null !== $this->response) {
         $this->response->setPublic();
         $this->response->setPrivate();
         $this->response->setMaxAge($this->configuration->getTtl());
         $this->response->setSharedMaxAge($this->configuration->getTtl());
         $this->response->setCharset('UTF-8');
         $this->response->prepare($this->request);
         return $this->response;
     } else {
         throw new \RuntimeException("Request had not been handled. Use handle() method before getResponse()", 1);
     }
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:17,代码来源:InterventionRequest.php

示例11: testIsPrivate

 public function testIsPrivate()
 {
     $response = new Response();
     $response->headers->set('Cache-Control', 'max-age=100');
     $response->setPrivate();
     $this->assertEquals(100, $response->headers->getCacheControlDirective('max-age'), '->isPrivate() adds the private Cache-Control directive when set to true');
     $this->assertTrue($response->headers->getCacheControlDirective('private'), '->isPrivate() adds the private Cache-Control directive when set to true');
     $response = new Response();
     $response->headers->set('Cache-Control', 'public, max-age=100');
     $response->setPrivate();
     $this->assertEquals(100, $response->headers->getCacheControlDirective('max-age'), '->isPrivate() adds the private Cache-Control directive when set to true');
     $this->assertTrue($response->headers->getCacheControlDirective('private'), '->isPrivate() adds the private Cache-Control directive when set to true');
     $this->assertFalse($response->headers->hasCacheControlDirective('public'), '->isPrivate() removes the public Cache-Control directive');
 }
开发者ID:neokensou,项目名称:symfony,代码行数:14,代码来源:ResponseTest.php

示例12: getImagePreviewAction

 /**
  * @param $id
  * @param $size
  * @return Response
  */
 public function getImagePreviewAction($id, $size)
 {
     /**
      * @var Piece $piece
      */
     $piece = $this->get('jahller.artlas.repository.piece')->find($id);
     /**
      * @var Image $image
      */
     $image = $piece->getImage();
     $content = $this->get('jahller.attachment.manager.image')->getPreview($image, $size);
     $response = new Response($content, 202, array('Content-type' => 'image/png'));
     $response->setPrivate();
     /* 1 month = 2.628.000 seconds */
     $response->setMaxAge(2628000);
     return $response;
 }
开发者ID:jahller,项目名称:streetartlas,代码行数:22,代码来源:ImageController.php

示例13: filterAction

 /**
  * This action applies a given filter to a given image, saves the image and
  * outputs it to the browser at the same time
  *
  * @param string $path
  * @param string $filter
  *
  * @return Response
  *
  * @throws Exception
  */
 public function filterAction($path, $filter)
 {
     $baseUrl = $this->request->getBaseUrl();
     try {
         try {
             $cachedPath = $this->cacheManager->cacheImage($baseUrl, $path, $filter);
         } catch (RuntimeException $e) {
             if (!isset($this->notFoundImages[$filter])) {
                 throw $e;
             }
             $path = $this->notFoundImages[$filter];
             $cachedPath = $this->cacheManager->cacheImage($baseUrl, $path, $filter);
         }
     } catch (RouteNotFoundException $e) {
         throw new NotFoundHttpException('Filter doesn\'t exist.');
     }
     // if cache path cannot be determined, return 404
     if (null === $cachedPath) {
         throw new NotFoundHttpException('Image doesn\'t exist');
     }
     try {
         // Using File instead of Imagine::open(), because i.e. image/x-icon is not widely supported.
         $file = new ImageFile($cachedPath, false);
         // TODO: add more media headers
         $headers = ['content-type' => $file->getMimeType(), 'content-length' => $file->getSize()];
         $response = new Response($file->getContents(), 201, $headers);
         // Cache
         if (!($cacheType = $this->filterManager->getOption($filter, 'cache_type', false))) {
             return $response;
         }
         $cacheType === 'public' ? $response->setPublic() : $response->setPrivate();
         $cacheExpires = $this->filterManager->getOption($filter, 'cache_expires', '1 day');
         $expirationDate = new DateTime('+' . $cacheExpires);
         $maxAge = $expirationDate->format('U') - time();
         if ($maxAge < 0) {
             throw new InvalidArgumentException('Invalid cache expiration date');
         }
         $response->setExpires($expirationDate);
         $response->setMaxAge($maxAge);
         return $response;
     } catch (Exception $e) {
         throw $e;
     }
 }
开发者ID:jmcclell,项目名称:AvalancheImagineBundle,代码行数:55,代码来源:ImagineController.php

示例14: infoAction

 public function infoAction(Request $request)
 {
     $jsonp = $request->query->get('jsonp');
     $locale = $request->query->get('_locale');
     if (isset($locale)) {
         $request->setLocale($locale);
     }
     $locale = $request->getLocale();
     $decklist_id = $request->query->get('decklist_id');
     $content = null;
     /* @var $user \Netrunnerdb\UserBundle\Entity\User */
     $user = $this->getUser();
     if ($user) {
         $user_id = $user->getId();
         $public_profile_url = $this->get('router')->generate('user_profile_view', array('_locale' => $this->getRequest()->getLocale(), 'user_id' => $user_id, 'user_name' => urlencode($user->getUsername())));
         $content = array('public_profile_url' => $public_profile_url, 'id' => $user_id, 'name' => $user->getUsername(), 'faction' => $user->getFaction(), 'locale' => $locale);
         if (isset($decklist_id)) {
             /* @var $em \Doctrine\ORM\EntityManager */
             $em = $this->get('doctrine')->getManager();
             /* @var $decklist \Netrunnerdb\BuilderBundle\Entity\Decklist */
             $decklist = $em->getRepository('NetrunnerdbBuilderBundle:Decklist')->find($decklist_id);
             if ($decklist) {
                 $decklist_id = $decklist->getId();
                 $dbh = $this->get('doctrine')->getConnection();
                 $content['is_liked'] = (bool) $dbh->executeQuery("SELECT\n        \t\t\t\tcount(*)\n        \t\t\t\tfrom decklist d\n        \t\t\t\tjoin vote v on v.decklist_id=d.id\n        \t\t\t\twhere v.user_id=?\n        \t\t\t\tand d.id=?", array($user_id, $decklist_id))->fetch(\PDO::FETCH_NUM)[0];
                 $content['is_favorite'] = (bool) $dbh->executeQuery("SELECT\n        \t\t\t\tcount(*)\n        \t\t\t\tfrom decklist d\n        \t\t\t\tjoin favorite f on f.decklist_id=d.id\n        \t\t\t\twhere f.user_id=?\n        \t\t\t\tand d.id=?", array($user_id, $decklist_id))->fetch(\PDO::FETCH_NUM)[0];
                 $content['is_author'] = $user_id == $decklist->getUser()->getId();
                 $content['can_delete'] = $decklist->getNbcomments() == 0 && $decklist->getNbfavorites() == 0 && $decklist->getNbvotes() == 0;
             }
         }
     }
     $content = json_encode($content);
     $response = new Response();
     $response->setPrivate();
     if (isset($jsonp)) {
         $content = "{$jsonp}({$content})";
         $response->headers->set('Content-Type', 'application/javascript');
     } else {
         $response->headers->set('Content-Type', 'application/json');
     }
     $response->setContent($content);
     return $response;
 }
开发者ID:adamcieslicki,项目名称:netrunnerdb,代码行数:43,代码来源:DefaultController.php

示例15: apply

 /**
  * @param Response $response
  */
 public function apply(Response $response)
 {
     if (empty($this->parameters['enabled'])) {
         return;
     }
     $this->parameters['public'] ? $response->setPublic() : $response->setPrivate();
     if (is_integer($this->parameters['maxage'])) {
         $response->setMaxAge($this->parameters['maxage']);
     }
     if (is_integer($this->parameters['smaxage'])) {
         $response->setSharedMaxAge($this->parameters['smaxage']);
     }
     if ($this->parameters['expires'] !== null) {
         $response->setExpires(new \DateTime($this->parameters['expires']));
     }
     if (!empty($this->parameters['vary'])) {
         $response->setVary($this->parameters['vary']);
     }
 }
开发者ID:jdeniau,项目名称:FOSJsRoutingBundle,代码行数:22,代码来源:CacheControlConfig.php


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