本文整理汇总了PHP中Symfony\Component\HttpFoundation\JsonResponse::setExpires方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonResponse::setExpires方法的具体用法?PHP JsonResponse::setExpires怎么用?PHP JsonResponse::setExpires使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\JsonResponse
的用法示例。
在下文中一共展示了JsonResponse::setExpires方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subtreesJsonp
/**
* Returns the rendered subtree of each top-level toolbar link.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function subtreesJsonp()
{
$subtrees = toolbar_get_rendered_subtrees();
$response = new JsonResponse($subtrees);
$response->setCallback('Drupal.toolbar.setSubtrees.resolve');
// The Expires HTTP header is the heart of the client-side HTTP caching. The
// additional server-side page cache only takes effect when the client
// accesses the callback URL again (e.g., after clearing the browser cache
// or when force-reloading a Drupal page).
$max_age = 365 * 24 * 60 * 60;
$response->setPrivate();
$response->setMaxAge($max_age);
$expires = new \DateTime();
$expires->setTimestamp(REQUEST_TIME + $max_age);
$response->setExpires($expires);
return $response;
}
示例2: statisticsJsonAction
/**
*
* @Route("/{_locale}/{_code}/statistics/{dataset}.json", requirements={"_locale" = "de|en|es|fr", "_code" = "[a-zA-Z0-9]{10}", "dataset" = "[a-zA-Z0-9_-]+"})
*/
public function statisticsJsonAction($_code, $dataset, Request $request)
{
try {
$context = $this->getContext($_code, 'statistics');
$stats = new Statistics($this, $this->account);
if (preg_match('!^wallet-([0-9]+)$!', $dataset, $m)) {
$method = 'getDatasetWallet';
if (method_exists($stats, $method)) {
$data = $stats->{$method}($m[1]);
if (!empty($data)) {
$response = new JsonResponse($data);
}
}
} else {
$method = 'getDataset' . $dataset;
if (method_exists($stats, $method)) {
$response = new JsonResponse($stats->{$method}());
}
}
if (isset($response)) {
$response->setMaxAge(900);
$response->setExpires(new \DateTime('@' . (time() + 900)));
$response->setPublic();
return $response;
}
} catch (\Exception $ex) {
return new JsonResponse(['error' => $ex->getMessage()]);
}
}
示例3: getJsonResponse
/**
* @param Request $request
* @param mixed $data
*
* @return JsonResponse
*/
protected function getJsonResponse(Request $request, $data = null)
{
$date = new \DateTime();
$date->modify('+1 day');
$response = new JsonResponse($data);
$response->setExpires($date);
$response->setETag(md5($response->getContent()));
$response->setPublic();
$response->isNotModified($request);
$response->headers->set('X-Proudly-Crafted-By', "LesPolypodes.com");
// It's nerdy, I know that.
return $response;
}
示例4: createAction
/**
* @Route("/create", name="api_create")
*/
public function createAction(Request $request)
{
if ($this->container->getParameter('secret') != $request->query->get('secret')) {
return new JsonResponse(['error' => 'Invalid Secret']);
}
// Create Short Code
$url = $request->query->get('url');
$code = $request->query->get('code', null);
$shortUrl = $this->get('short_url')->create($url, $code);
$response = new JsonResponse(['short_url' => $this->get('short_url')->shortUrl($shortUrl)]);
$response->setPublic();
$response->setExpires(new DateTime('+1 day'));
return $response;
}
示例5: getListAction
public function getListAction(Application $app)
{
$userList = $this->repository->findAll();
$date = new \DateTime();
$date->modify('+' . self::MAX_AGE . ' seconds');
$response = new JsonResponse($userList, JsonResponse::HTTP_OK);
$responseHash = sha1($response->getContent());
$response->setMaxAge(self::MAX_AGE);
$response->setSharedMaxAge(self::MAX_AGE);
$response->setExpires($date);
$response->setETag($responseHash);
$response->isNotModified($app['request']);
return $response;
}
示例6: registrationsAction
/**
* @Route("/api/data", name="public_edk_registration_data", defaults={"_localeFromQuery" = true})
*/
public function registrationsAction(Request $request)
{
try {
$repository = $this->get('wio.edk.repo.published_data');
$registrations = $repository->getOpenRegistrations($this->project, $this->getProjectSettings()->get(EdkSettings::PUBLISHED_AREA_STATUS)->getValue());
$response = new JsonResponse($registrations);
$response->setDate(new DateTime());
$exp = new DateTime();
$exp->add(new DateInterval('PT0H5M0S'));
$response->setExpires($exp);
return $response;
} catch (ItemNotFoundException $exception) {
return new JsonResponse(['success' => 0]);
}
}
示例7: respondWithArray
protected function respondWithArray($content = [], $status = 200, array $headers = [])
{
$response = new JsonResponse($content, $status, $headers);
$response->setExpires(new \DateTime('1924-10-10 12:00:00 UTC'));
$response->headers->addCacheControlDirective('no-cache', true);
$response->headers->addCacheControlDirective('private', true);
return $response;
}