本文整理汇总了PHP中Symfony\Component\HttpFoundation\JsonResponse::isNotModified方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonResponse::isNotModified方法的具体用法?PHP JsonResponse::isNotModified怎么用?PHP JsonResponse::isNotModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\JsonResponse
的用法示例。
在下文中一共展示了JsonResponse::isNotModified方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defaultAction
static function defaultAction(Request $request, Service $service, $repositoryName)
{
$repository = $service->getRepository($repositoryName);
if ($repository) {
$response = new JsonResponse();
$etag = md5($repository->getLastModifiedDate());
$response->setEtag($etag);
if ($response->isNotModified($request)) {
$response->send();
return $response;
}
$result = [];
$result['content'] = [];
foreach ($repository->getContentTypeDefinitions() as $definition) {
$result['content'][$definition->getName()]['title'] = $definition->getTitle() ? $definition->getTitle() : $definition->getName();
$result['content'][$definition->getName()]['lastchange_content'] = $repository->getLastModifiedDate($definition->getName());
$result['content'][$definition->getName()]['lastchange_cmdl'] = 0;
// TODO
}
$response->setContent(json_encode($result, JSON_PRETTY_PRINT));
$response->setEtag($etag);
$response->setPublic();
return $response;
}
}
示例2: 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;
}
示例3: 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;
}