本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::expire方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::expire方法的具体用法?PHP Response::expire怎么用?PHP Response::expire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::expire方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderTemporaryAction
/**
* Renders temporary file
*
* @return Response
*/
public function renderTemporaryAction()
{
$name = $this->getRequest()->get('name');
$fileManager = $this->container->get('thrace_media.filemanager');
$content = $fileManager->getTemporaryFileBlobByName($name);
$response = new Response($content);
$response->headers->set('Accept-Ranges', 'bytes');
$response->headers->set('Content-Length', mb_strlen($content));
$response->headers->set('Content-Type', $this->getMimeType($content));
$response->expire();
return $response;
}
示例2: showPageAction
public function showPageAction($id, $extraParams = null, $currentpage = null, $totalpageitems = null, $linkUrlParams = null)
{
// Get data to display
$page = $this->getDoctrine()->getRepository('BlogBundle:Blog')->find($id);
$userRole = $this->get('sonata_user.services.helpers')->getLoggedUserHighestRole();
$settings = $this->get('bardiscms_settings.load_settings')->loadSettings();
// Simple ACL for publishing
if ($page->getPublishState() == 0) {
return $this->render404Page();
}
if ($page->getPublishState() == 2 && $userRole == '') {
return $this->render404Page();
}
if ($userRole == "") {
$publishStates = array(1);
} else {
$publishStates = array(1, 2);
}
if ($this->container->getParameter('kernel.environment') == 'prod' && $settings->getActivateHttpCache()) {
$response = new Response();
// set a custom Cache-Control directive
$response->headers->addCacheControlDirective('must-revalidate', true);
// set multiple vary headers
$response->setVary(array('Accept-Encoding', 'User-Agent'));
// create a Response with a Last-Modified header
$response->setLastModified($page->getDateLastModified());
// Set response as public. Otherwise it will be private by default.
$response->setPublic();
//var_dump($response->isNotModified($this->getRequest()));
//var_dump($response->getStatusCode());
if (!$response->isNotModified($this->getRequest())) {
// Marks the Response stale
$response->expire();
} else {
// return the 304 Response immediately
$response->setSharedMaxAge(3600);
return $response;
}
}
// Set the website settings and metatags
$page = $this->get('bardiscms_settings.set_page_settings')->setPageSettings($page);
// Set the pagination variables
if (!$totalpageitems) {
if (is_object($settings)) {
$totalpageitems = $settings->getBlogItemsPerPage();
} else {
$totalpageitems = 10;
}
}
// Render the correct view depending on pagetype
return $this->renderPage($page, $id, $publishStates, $extraParams, $currentpage, $totalpageitems, $linkUrlParams);
}
示例3: testExpire
public function testExpire()
{
$response = new Response();
$response->headers->set('Cache-Control', 'max-age=100');
$response->expire();
$this->assertEquals(100, $response->headers->get('Age'), '->expire() sets the Age to max-age when present');
$response = new Response();
$response->headers->set('Cache-Control', 'max-age=100, s-maxage=500');
$response->expire();
$this->assertEquals(500, $response->headers->get('Age'), '->expire() sets the Age to s-maxage when both max-age and s-maxage are present');
$response = new Response();
$response->headers->set('Cache-Control', 'max-age=5, s-maxage=500');
$response->headers->set('Age', '1000');
$response->expire();
$this->assertEquals(1000, $response->headers->get('Age'), '->expire() does nothing when the response is already stale/expired');
$response = new Response();
$response->expire();
$this->assertFalse($response->headers->has('Age'), '->expire() does nothing when the response does not include freshness information');
}
示例4: processNoCache
/**
* Set the no-cache headers for all responses, if requested.
*
* <b>NOTE</b> - This header will be overridden automatically if a
* <samp>RequestDispatcher->doForward</samp> call is ultimately
* invoked.
*
* @param \Symfony\Component\HttpFoundation\Request $request The kernel request we are
* processing
* @param \Symfony\Component\HttpFoundation\Response $response The kernel response we are
* creating
*/
protected function processNoCache(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response)
{
if ($this->moduleConfig->getControllerConfig()->getNocache()) {
$response->headers->set('Pragma', 'No-cache');
$response->headers->set('Cache-Control', 'no-cache');
$response->expire();
}
}
示例5: renderThumbnailTemporaryAction
/**
* Renders temporary image
*
* @param string $name
* @return Response
*/
public function renderThumbnailTemporaryAction()
{
$name = $this->getRequest()->get('name');
$filter = $this->getRequest()->get('filter');
$imageManager = $this->container->get('thrace_media.imagemanager');
$filterManager = $this->container->get('liip_imagine.filter.manager');
try {
$content = $filterManager->applyFilter($imageManager->loadTemporaryImageByName($name), $filter);
} catch (FileNotFound $e) {
throw new NotFoundHttpException();
}
$response = new Response($content);
$response->headers->set('Accept-Ranges', 'bytes');
$response->headers->set('Content-Length', mb_strlen($content));
$response->headers->set('Content-Type', $this->getMimeType($content));
$response->expire();
return $response;
}
示例6: getResponse
/**
* gets the export Response
*
* @return Response
*/
public function getResponse()
{
// Response
$kernelCharset = $this->container->getParameter('kernel.charset');
if ($this->charset != $kernelCharset && function_exists('mb_strlen')) {
$this->content = mb_convert_encoding($this->content, $this->charset, $kernelCharset);
$filesize = mb_strlen($this->content, '8bit');
} else {
$filesize = strlen($this->content);
$this->charset = $kernelCharset;
}
$headers = array('Content-Description' => 'File Transfer', 'Content-Type' => $this->getMimeType(), 'Content-Disposition' => sprintf('attachment; filename="%s"', $this->getBaseName()), 'Content-Transfer-Encoding' => 'binary', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public', 'Content-Length' => $filesize);
$response = new Response($this->content, 200, $headers);
$response->setCharset($this->charset);
$response->expire();
return $response;
}
示例7: indexAction
/**
* @Route("")
* @Theme("admin")
*
* view items
*
* @param Request $request
*
* @return Response HTML output
*/
public function indexAction(Request $request)
{
// Get parameters
$startnum = $request->query->get('startnum', 1);
$orderBy = $request->query->get('orderby', 'pageid');
$currentSortDirection = $request->query->get('sdir', Column::DIRECTION_DESCENDING);
$filterForm = $this->createForm(new FilterType(), $request->query->all(), array('action' => $this->generateUrl('zikulapagesmodule_admin_index'), 'method' => 'POST', 'entityCategoryRegistries' => CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'PageEntity', 'id')));
$filterForm->handleRequest($request);
$filterData = $filterForm->isSubmitted() ? $filterForm->getData() : $request->query->all();
$sortableColumns = new SortableColumns($this->get('router'), 'zikulapagesmodule_admin_index', 'orderby', 'sdir');
$sortableColumns->addColumn(new Column('pageid'));
// first added is automatically the default
$sortableColumns->addColumn(new Column('title'));
$sortableColumns->addColumn(new Column('cr_date'));
$sortableColumns->setOrderBy($sortableColumns->getColumn($orderBy), $currentSortDirection);
$sortableColumns->setAdditionalUrlParameters(array('language' => isset($filterData['language']) ? $filterData['language'] : null, 'filtercats_serialized' => isset($filterData['categories']) ? serialize($filterData['categories']) : null));
$pages = new PageCollectionManager($this->container->get('doctrine.entitymanager'));
$pages->setStartNumber($startnum);
$pages->setItemsPerPage(\ModUtil::getVar($this->name, 'itemsperpage'));
$pages->setOrder($orderBy, $currentSortDirection);
$pages->enablePager();
$pages->setFilterBy($filterData);
$templateParameters = array();
$templateParameters['filter_active'] = isset($filterData['category']) && count($filterData['category']) > 0 || !empty($filterData['language']);
$templateParameters['sort'] = $sortableColumns->generateSortableColumns();
$templateParameters['pages'] = $pages->get();
$templateParameters['lang'] = ZLanguage::getLanguageCode();
$templateParameters['pager'] = $pages->getPager();
$templateParameters['modvars'] = \ModUtil::getModvars();
// temporary solution
$templateParameters['filterForm'] = $filterForm->createView();
// attempt to disable caching for this only
$response = new Response();
$response->expire();
return $this->render('ZikulaPagesModule:Admin:view.html.twig', $templateParameters, $response);
}