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


PHP Response::setTtl方法代码示例

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


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

示例1: cachedPageAction

 public function cachedPageAction(Request $request, Application $app)
 {
     // this will be cached for 10 sec
     $response = new Response($app['twig']->render('page-with-cache.html.twig', array('date' => date('Y-M-d h:i:s'))));
     $response->setTtl(10);
     return $response;
 }
开发者ID:acrnogor,项目名称:sfp,代码行数:7,代码来源:StaticController.php

示例2: css

 /**
  * Return the stylesheets for the Debugbar
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function css()
 {
     $renderer = $this->app['debugbar']->getJavascriptRenderer();
     $content = $renderer->dumpAssetsToString('css');
     $response = new Response($content, 200, array('Content-Type' => 'text/css'));
     $response->setTtl($this->ttl);
     return $response;
 }
开发者ID:jairoserrano,项目名称:SimpleBlogClase,代码行数:13,代码来源:AssetController.php

示例3: relatedContentAction

 /**
  * Displays related content for given locationId, using legacy template.
  *
  * @param mixed $locationId
  *
  * @return Response
  */
 public function relatedContentAction($locationId)
 {
     $repository = $this->getRepository();
     $location = $repository->getLocationService()->loadLocation($locationId);
     $contentType = $repository->getContentTypeService()->loadContentType($location->getContentInfo()->contentTypeId);
     $response = new Response();
     $response->setTtl(strtotime('1 day'));
     return $this->render('file:' . __DIR__ . '/../ezpublish_legacy/metalfrance/design/mf/templates/parts/right_column/related_content.tpl', ['module_result' => ['content_info' => ['class_identifier' => $contentType->identifier, 'node_id' => $locationId]]], $response);
 }
开发者ID:obenyoussef,项目名称:metalfrance,代码行数:16,代码来源:SidebarController.php

示例4: indexAction

 /**
  * @param Request $request
  * @return Response
  */
 public function indexAction(Request $request)
 {
     if ($this->isLeapYear($request->attributes->get('year'))) {
         $response = new Response('Yes its leap year');
     } else {
         $response = new Response('No it\'s not leap year ' . rand(1, 1000) . ' ');
     }
     $response->setTtl(10);
     return $response;
 }
开发者ID:apoberez,项目名称:myOwnSymfony,代码行数:14,代码来源:LeapController.php

示例5: indexAction

 public function indexAction(Request $request, $year)
 {
     $leapyear = new LeapYear();
     if ($leapyear->isLeapYear($year)) {
         $response = new Response('Yep, this is a leap year!');
     } else {
         $response = new Response('Nope, this is not a leap year.');
     }
     $response->setTtl(10);
     return $response;
 }
开发者ID:Guillaume-RICHARD,项目名称:micro-framework,代码行数:11,代码来源:LeapYearController.php

示例6: alterResponse

 /**
  * {@inheritdoc}
  */
 public function alterResponse(Response $response)
 {
     if (!$response->isCacheable()) {
         // the controller flags the response as private so we keep it private!
         return;
     }
     // a block has a lower ttl that the current response, so we update the ttl to match
     // the one provided in the block
     if ($this->currentTtl < $response->getTtl()) {
         $response->setTtl($this->currentTtl);
     }
 }
开发者ID:serialken,项目名称:BugTracker,代码行数:15,代码来源:HttpCacheHandler.php

示例7: render

 /**
  * Renders a view and returns a Response.
  *
  * To stream a view, pass an instance of StreamedResponse as a third argument.
  *
  * @param string   $view       The view name
  * @param array    $parameters An array of parameters to pass to the view
  * @param Response $response   A Response instance
  *
  * @return Response A Response instance
  */
 public function render($view, array $parameters = [], Response $response = null)
 {
     $twig = $this['twig'];
     if ($response instanceof StreamedResponse) {
         $response->setCallback(function () use($twig, $view, $parameters) {
             $twig->display($view, $parameters);
         });
         return $response;
     }
     if (null === $response) {
         $response = new Response();
     }
     if ($this->hasCachingEnabled()) {
         $response->setTtl($this['http_cache.default_ttl']);
     }
     $response->setContent($twig->render($view, $parameters));
     return $response;
 }
开发者ID:jtallant,项目名称:skimpy-engine,代码行数:29,代码来源:CacheableTwigResponses.php

示例8: statsJson

 /**
  * Creates the JSON used to render the stats.
  *
  * @param Request $request
  *
  * @return Response
  */
 protected function statsJson(Request $request)
 {
     $response = new Response();
     $response->setTtl(60 * 5);
     $response->setPublic();
     if ($response->isNotModified($request)) {
         return $response;
     }
     $event = $this->eventRepo->getNextEvent()->getOrThrow(new AccesDeniedHttpException('No event.'));
     $tickets = $this->ticketRepo->getTicketsForEvent($event);
     $unregistrations = $this->unregistrationRepo->getUnregistrationsForEvent($event);
     $stats = array('checkins' => array('sa' => $this->getCheckinsPerDay($tickets, Ticket::DAY_SATURDAY), 'sa_hour' => $this->getCheckinsPerHour($tickets, Ticket::DAY_SATURDAY), 'su' => $this->getCheckinsPerDay($tickets, Ticket::DAY_SUNDAY), 'su_hour' => $this->getCheckinsPerHour($tickets, Ticket::DAY_SUNDAY), 'unique' => array('sa' => $this->getUniqueDayCheckins($tickets, Ticket::DAY_SATURDAY), 'su' => $this->getUniqueDayCheckins($tickets, Ticket::DAY_SUNDAY), 'both' => $this->getUniqueDayCheckins($tickets, Ticket::DAY_SUNDAY, true)), 'noshows' => array('sa' => $this->getNoShows($tickets, Ticket::DAY_SATURDAY), 'su' => $this->getNoShows($tickets, Ticket::DAY_SUNDAY))), 'unregistrations' => $this->getUnregistrationsPerDay($unregistrations));
     $data = array('stats' => $stats);
     $response->setContent(json_encode($data));
     $response->setCharset('utf-8');
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
开发者ID:Ravetracer,项目名称:www,代码行数:25,代码来源:StatsController.php

示例9: testIsCacheableWithSetTtl

 public function testIsCacheableWithSetTtl()
 {
     $response = new Response();
     $response->setTtl(10);
     $this->assertTrue($response->isCacheable());
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:6,代码来源:ResponseTest.php

示例10: fooAction

 public function fooAction()
 {
     $response = new Response('cached response (10 sec): ' . time());
     $response->setTtl(10);
     return $response;
 }
开发者ID:vanekt,项目名称:framework,代码行数:6,代码来源:HelloController.php

示例11: addMetaInformation

 /**
  * This method is responsible to cascade ttl to the parent block.
  *
  * @param Response              $response
  * @param BlockContextInterface $blockContext
  * @param BlockServiceInterface $service
  *
  * @return Response
  */
 protected function addMetaInformation(Response $response, BlockContextInterface $blockContext, BlockServiceInterface $service)
 {
     // a response exists, use it
     if ($this->lastResponse && $this->lastResponse->isCacheable()) {
         $response->setTtl($this->lastResponse->getTtl());
         $response->setPublic();
     } elseif ($this->lastResponse) {
         // not cacheable
         $response->setPrivate();
         $response->setTtl(0);
         $response->headers->removeCacheControlDirective('s-maxage');
         $response->headers->removeCacheControlDirective('maxage');
     }
     // no more children available in the stack, reseting the state object
     if (!$blockContext->getBlock()->hasParent()) {
         $this->lastResponse = null;
     } else {
         // contains a parent so storing the response
         $this->lastResponse = $response;
     }
     return $response;
 }
开发者ID:karousn,项目名称:SonataBlockBundle,代码行数:31,代码来源:BlockRenderer.php

示例12: rssAction

 public function rssAction($uri = null)
 {
     if (null === $this->application) {
         throw new FrontControllerException('A valid BackBee application is required.', FrontControllerException::INTERNAL_ERROR);
     }
     if (false === $this->application->getContainer()->has('site')) {
         throw new FrontControllerException('A BackBee\\Site instance is required.', FrontControllerException::INTERNAL_ERROR);
     }
     $site = $this->application->getContainer()->get('site');
     if (false !== ($ext = strrpos($uri, '.'))) {
         $uri = substr($uri, 0, $ext);
     }
     if ('_root_' == $uri) {
         $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($site);
     } else {
         $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->findOneBy(array('_site' => $site, '_url' => '/' . $uri, '_state' => Page::getUndeletedStates()));
     }
     try {
         $this->application->info(sprintf('Handling URL request `rss%s`.', $uri));
         $response = new Response($this->application->getRenderer()->render($page, 'rss', null, 'rss.phtml', false));
         $response->headers->set('Content-Type', 'text/xml');
         $response->setClientTtl(15);
         $response->setTtl(15);
         $this->send($response);
     } catch (\Exception $e) {
         $this->defaultAction('/rss/' . $uri);
     }
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:28,代码来源:FrontController.php

示例13: messagesAction

 public function messagesAction(Application $app)
 {
     $response = new Response();
     return $app->render('messages.twig', ['guestbook' => $app['guestbook']->get()], $response->setTtl(10));
 }
开发者ID:nix5longhorn,项目名称:silex-guestbook,代码行数:5,代码来源:Index.php

示例14: FormError

        if ($form->isValid()) {
            $app['session']->setFlash('success', 'The form is valid');
        } else {
            $form->addError(new FormError('This is a global error'));
            $app['session']->setFlash('info', 'The form is bind, but not valid');
        }
    }
    return $app['twig']->render('form.html.twig', array('form' => $form->createView()));
})->bind('form');
$app->match('/logout', function () use($app) {
    $app['session']->clear();
    return $app->redirect($app['url_generator']->generate('homepage'));
})->bind('logout');
$app->get('/page-with-cache', function () use($app) {
    $response = new Response($app['twig']->render('page-with-cache.html.twig', array('date' => date('Y-M-d h:i:s'))));
    $response->setTtl(10);
    return $response;
})->bind('page_with_cache');
$app->error(function (\Exception $e, $code) use($app) {
    if ($app['debug']) {
        return;
    }
    switch ($code) {
        case 404:
            $message = 'The requested page could not be found.';
            break;
        default:
            $message = 'We are sorry, but something went terribly wrong.';
    }
    return new Response($message, $code);
});
开发者ID:nicolas-mary,项目名称:PxTemple,代码行数:31,代码来源:controllers.php

示例15: cache

 public function cache(App $app)
 {
     $response = new Response($app['twig']->render('cache.html.twig', array('date' => date('Y-M-d h:i:s'))));
     $response->setTtl(10);
     return $response;
 }
开发者ID:lyrixx,项目名称:silex-kitchen-edition,代码行数:6,代码来源:ControllerProvider.php


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