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


PHP JsonResponse::setMaxAge方法代码示例

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


在下文中一共展示了JsonResponse::setMaxAge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:ToolbarController.php

示例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()]);
     }
 }
开发者ID:arnapou,项目名称:gw2tools,代码行数:33,代码来源:PageController.php

示例3: ajaxGetLastMessageAction

 public function ajaxGetLastMessageAction()
 {
     $this->onlyAjaxRequest();
     $repo = $this->get('social.private_message.repository');
     /* @var $lastPm \Trismegiste\Socialist\PrivateMessage */
     $lastPm = $repo->getLastReceived();
     $lastUpdate = is_null($lastPm) ? null : $lastPm->getSentAt();
     $response = new JsonResponse(['lastUpdate' => $lastUpdate]);
     $response->setMaxAge(60);
     return $response;
 }
开发者ID:xtrasmal,项目名称:iinano,代码行数:11,代码来源:PrivateMessageController.php

示例4: 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;
 }
开发者ID:tecnom1k3,项目名称:insta-api,代码行数:14,代码来源:User.php

示例5: rateAction

 public function rateAction(Request $request)
 {
     // Retreive and normalise query parameters
     // Epic security here, this would obviously be the current logged in user's ID
     $user_id = $request->query->get('user_id');
     $id = $request->query->get('comment_id');
     $vote = $request->query->get('vote');
     switch ($vote) {
         case 'up':
             $value = 1;
             break;
         case 'down':
             $value = -1;
             break;
         default:
             $value = false;
     }
     $makeResponse = function ($data, $statusCode = 200) use($user_id, $id, $vote) {
         $output = $this->presentResponse($data, 'comment_rating_add', array('vote' => $vote, 'user_id' => $user_id, 'comment_id' => $id));
         $resp = new JsonResponse($output, $statusCode);
         $resp->setPrivate();
         $resp->setMaxAge(0);
         return $resp;
     };
     // Make sure the vote is valid
     if ($value === false) {
         return $makeResponse('Param "vote" invalid. Expected "up" or "down"', Response::HTTP_BAD_REQUEST);
     }
     // Make sure it's a valid comment we're voting on
     $comment = $this->getCommentById($id);
     if (!$comment) {
         return $makeResponse('Comment not found for id ' . $id, Response::HTTP_NOT_FOUND);
     }
     // Make sure they haven't already voted on the comment
     $ratingRepo = $this->getDoctrine()->getRepository('AppBundle:CommentRating');
     $rating = $ratingRepo->findBy(array('user_id' => $user_id));
     if (!!$rating) {
         return $makeResponse('User has already submitted rating', Response::HTTP_BAD_REQUEST);
     }
     try {
         // If we made it here, everything looks good
         $result = $ratingRepo->addNewVote(array('comment_id' => $id, 'value' => $value, 'user_id' => $user_id));
     } catch (Exception $e) {
         return $makeResponse('Failed to save vote', Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     return $makeResponse('Vote Added');
 }
开发者ID:joshrp,项目名称:comment-rating-test,代码行数:47,代码来源:CommentsRatingController.php


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