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


PHP JsonResponse::setSharedMaxAge方法代码示例

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


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

示例1: getBySeedAction

 /**
  * @Route("/{_locale}/get/seed/{seed}", name="get_by_seed_locale")
  * @Route("/get/seed/{seed}", name="get_by_seed")
  */
 public function getBySeedAction(Request $request, $seed)
 {
     $return = array('status' => 1, 'message' => '', 'data' => null);
     // retorno padrão
     $router = $this->container->get('router');
     $translator = $this->get('translator');
     // da uma limpada
     $seed = md5($seed . $this->container->getParameter('secret'));
     // extrai um numero de 0~9
     $seed = substr(base_convert(md5($seed), 16, 10), -1);
     srand($seed);
     // usa pro rand
     // image path
     $image_path = $request->getUriForPath('/image/cenouro.png');
     $message = '';
     // são tão poucas opções que nem vale a pena criar DB
     // balanceia as chances um pouco
     switch (rand(1, 4)) {
         case 1:
             $message = 'Yes!';
             break;
         case 2:
             $message = 'No!';
             break;
         default:
             switch (rand(1, 6)) {
                 case 1:
                     $message = 'Maybe.';
                     break;
                 case 2:
                     $message = 'Sure!';
                     break;
                 case 3:
                     $message = "I really don't care.";
                     break;
                 case 4:
                     $message = "Of course not.";
                     break;
                 case 5:
                     $message = "Ask again.";
                     break;
                 case 6:
                     $message = "Screw you!";
                     break;
             }
             break;
     }
     // traduz, se precisar
     $message = $translator->trans($message);
     // responde
     $data = array('message' => $message, 'image' => $image_path);
     $return['data'] = $data;
     $response = new JsonResponse($return);
     // cache
     $response->setPublic();
     $response->setSharedMaxAge(600000);
     $response->headers->addCacheControlDirective('must-revalidate', true);
     return $response;
 }
开发者ID:pe77,项目名称:chan-module-cr,代码行数:63,代码来源:DefaultController.php

示例2: 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

示例3: indexAllJsonAction

 /**
  * Lists all Entities
  *
  * @Route("/data/index_all.json", name="servicios_index_json" )
  * @Method("GET")
  * @Template()
  */
 public function indexAllJsonAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $entities = $em->getRepository('BcTicCamIpalBundle:Servicio')->createQueryBuilder('s')->join('s.contratos', 'c')->join('c.empresas', 'e')->join('s.area', 'a')->join('a.pais', 'p')->where('c.visible = 1')->orderBy('s.nombre', 'ASC');
     $role = false;
     if ($role) {
         //Do Nothing
     } else {
         $paises = array();
         foreach ($this->get('security.context')->getToken()->getUser()->getPais() as $pais) {
             $paises[$pais->getId()] = $pais->getId();
         }
         $entities->andWhere('p.id IN (:paises)');
         $entities->setParameter('paises', $paises);
     }
     $data = array();
     foreach ($entities->getQuery()->getResult() as $entity) {
         $data[] = array('id' => $entity->getId(), 'nombre' => $entity->__toString());
     }
     $response = new JsonResponse($data);
     $response->setSharedMaxAge(600);
     //Cache 10 minutes
     return $response;
 }
开发者ID:ramiroavila,项目名称:SIOP-IPAL,代码行数:31,代码来源:ServicioController.php

示例4: overallStatsAction

 /**
  * @Route(
  *      "/packages/{name}/stats/all.json",
  *      name="package_stats",
  *      requirements={"name"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
  * )
  */
 public function overallStatsAction(Request $req, Package $package, Version $version = null)
 {
     if ($from = $req->query->get('from')) {
         $from = new DateTimeImmutable($from);
     } else {
         $from = $this->guessStatsStartDate($version ?: $package);
     }
     if ($to = $req->query->get('to')) {
         $to = new DateTimeImmutable($to);
     } else {
         $to = new DateTimeImmutable('-2days 00:00:00');
     }
     $average = $req->query->get('average', $this->guessStatsAverage($from, $to));
     $datePoints = $this->createDatePoints($from, $to, $average, $package, $version);
     $redis = $this->get('snc_redis.default');
     if ($average === 'Daily') {
         $datePoints = array_map(function ($vals) {
             return $vals[0];
         }, $datePoints);
         $datePoints = array('labels' => array_keys($datePoints), 'values' => $redis->mget(array_values($datePoints)));
     } else {
         $datePoints = array('labels' => array_keys($datePoints), 'values' => array_values(array_map(function ($vals) use($redis) {
             return array_sum($redis->mget(array_values($vals)));
         }, $datePoints)));
     }
     $datePoints['average'] = $average;
     if ($average !== 'daily') {
         $dividers = ['monthly' => 30.41, 'weekly' => 7];
         $divider = $dividers[$average];
         $datePoints['values'] = array_map(function ($val) use($divider) {
             return ceil($val / $divider);
         }, $datePoints['values']);
     }
     if (empty($datePoints['labels']) && empty($datePoints['values'])) {
         $datePoints['labels'][] = date('Y-m-d');
         $datePoints['values'][] = 0;
     }
     $response = new JsonResponse($datePoints);
     $response->setSharedMaxAge(1800);
     return $response;
 }
开发者ID:rawphp,项目名称:packagist,代码行数:48,代码来源:PackageController.php

示例5: array

<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
$app = new Silex\Application();
//$app['debug'] = true;
// Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// Cache
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/../cache/', 'http_cache.esi' => null));
// Weekend, where the magic happens.
$app['weekend'] = function () {
    return new \Ternel\Weekend();
};
// Website
$app->get('/', function () use($app) {
    $response = new Response($app['twig']->render('index.html.twig', ['text' => $app['weekend']->getText(), 'subtext' => $app['weekend']->getSubText()]), 200);
    $response->setPublic();
    $response->setSharedMaxAge(60);
    return $response;
});
// Api
$app->get('/api', function () use($app) {
    $response = new JsonResponse(['text' => $app['weekend']->getText(), 'subtext' => $app['weekend']->getSubText()], 200);
    $response->setPublic();
    $response->setSharedMaxAge(60);
    return $response;
});
$app['http_cache']->run();
开发者ID:pyrech-forks,项目名称:weekend-website,代码行数:30,代码来源:app.php

示例6: viewPackageAction

 /**
  * @Template()
  * @Route(
  *     "/packages/{name}.{_format}",
  *     name="view_package",
  *     requirements={"name"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?", "_format"="(json)"},
  *     defaults={"_format"="html"}
  * )
  * @Method({"GET"})
  */
 public function viewPackageAction(Request $req, $name)
 {
     $repo = $this->getDoctrine()->getRepository('PackagistWebBundle:Package');
     try {
         /** @var $package Package */
         $package = $repo->findOneByName($name);
     } catch (NoResultException $e) {
         if ('json' === $req->getRequestFormat()) {
             return new JsonResponse(array('status' => 'error', 'message' => 'Package not found'), 404);
         }
         if ($providers = $repo->findProviders($name)) {
             return $this->redirect($this->generateUrl('view_providers', array('name' => $name)));
         }
         return $this->redirect($this->generateUrl('search', array('q' => $name, 'reason' => 'package_not_found')));
     }
     if ('json' === $req->getRequestFormat()) {
         $data = $package->toArray();
         try {
             $data['downloads'] = $this->get('packagist.download_manager')->getDownloads($package);
             $data['favers'] = $this->get('packagist.favorite_manager')->getFaverCount($package);
         } catch (ConnectionException $e) {
             $data['downloads'] = null;
             $data['favers'] = null;
         }
         // TODO invalidate cache on update and make the ttl longer
         $response = new JsonResponse(array('package' => $data));
         $response->setSharedMaxAge(3600);
         return $response;
     }
     $version = null;
     $expandedVersion = null;
     $versions = $package->getVersions();
     if (is_object($versions)) {
         $versions = $versions->toArray();
     }
     usort($versions, Package::class . '::sortVersions');
     if (count($versions)) {
         $versionRepo = $this->getDoctrine()->getRepository('PackagistWebBundle:Version');
         $version = $versionRepo->getFullVersion(reset($versions)->getId());
         $expandedVersion = reset($versions);
         foreach ($versions as $v) {
             if (!$v->isDevelopment()) {
                 $expandedVersion = $v;
                 break;
             }
         }
         $expandedVersion = $versionRepo->getFullVersion($expandedVersion->getId());
     }
     $data = array('package' => $package, 'version' => $version, 'versions' => $versions, 'expandedVersion' => $expandedVersion);
     try {
         $data['downloads'] = $this->get('packagist.download_manager')->getDownloads($package);
         if ($this->getUser()) {
             $data['is_favorite'] = $this->get('packagist.favorite_manager')->isMarked($this->getUser(), $package);
         }
     } catch (ConnectionException $e) {
     }
     $data['dependents'] = $repo->getDependentCount($package->getName());
     if ($maintainerForm = $this->createAddMaintainerForm($package)) {
         $data['addMaintainerForm'] = $maintainerForm->createView();
     }
     if ($removeMaintainerForm = $this->createRemoveMaintainerForm($package)) {
         $data['removeMaintainerForm'] = $removeMaintainerForm->createView();
     }
     if ($deleteForm = $this->createDeletePackageForm($package)) {
         $data['deleteForm'] = $deleteForm->createView();
     }
     if ($this->getUser() && ($this->isGranted('ROLE_DELETE_PACKAGES') || $package->getMaintainers()->contains($this->getUser()))) {
         $data['deleteVersionCsrfToken'] = $this->get('security.csrf.token_manager')->getToken('delete_version');
     }
     return $data;
 }
开发者ID:paulgreenstreet,项目名称:packagist,代码行数:81,代码来源:WebController.php

示例7: showJsonAction

 /**
  * List a Contrato
  *
  * @Route("/data/show.json", name="contrato_json" )
  * @Method("POST")
  * @Template()
  */
 public function showJsonAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('BcTicCamIpalBundle:Contrato')->find($request->request->get('id'));
     if (!$entity) {
         return new JsonResponse(array());
     }
     $data = array('id' => $entity->getId(), 'nombre' => $entity->__toString(), 'empresas' => $entity->getEmpresas(), 'area' => $entity->getArea()->getId(), 'servicio' => $entity->getServicio()->getId(), 'subgerencia' => $entity->getSubGerencia()->getId(), 'gerencia' => $entity->getSubGerencia()->getGerencia()->getId(), 'mandante' => $entity->getMandante()->getId(), 'subcontrato' => $entity->getSubcontrato(), 'pais' => $entity->getPais()->getId());
     $response = new JsonResponse($data);
     $response->setSharedMaxAge(600);
     //Cache 10 minutes
     return $response;
 }
开发者ID:ramiroavila,项目名称:SIOP-IPAL,代码行数:20,代码来源:ContratoController.php

示例8: indexPrevencionistaJsonAction

 /**
  * Lists all Prevencionistas by Query
  *
  * @Route("/data/prevencionistas.json", name="registros_prevencionistas_json")
  * @Method("GET")
  * @Template()
  */
 public function indexPrevencionistaJsonAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $entities = $em->getRepository('BcTicCamIpalBundle:Registro')->createQueryBuilder('r')->where('r.visible = 1')->join('r.roles', 'rol')->where('rol.nombre = :rol')->andWhere('r.nombre LIKE :query')->setParameters(array('rol' => 'PREVENCIONISTA', 'query' => '%' . $request->request->get('query', '') . '%'))->orderBy('r.nombre', 'ASC')->getQuery();
     $data = array();
     foreach ($entities->getResult() as $entity) {
         $data[] = array('id' => $entity->getId(), 'nombre' => ucwords(strtolower($entity->__toString())));
     }
     //AHora todos los usuarios que sean Inspectores
     $entities = $em->getRepository('BcTicCamIpalBundle:Usuario')->createQueryBuilder('u')->join('u.roles', 'rol')->join('u.pais', 'p')->where('rol.nombre = :rol AND u.visible = 1')->andWhere('u.nombre LIKE :query')->setParameters(array('rol' => 'PREVENCIONISTA', 'query' => '%' . $request->request->get('query', '') . '%'))->orderBy('u.nombre', 'ASC');
     $role = false;
     if ($role) {
         //Do Nothing
     } else {
         $entities->andWhere('p.id IN (:paises)');
         $paises = array();
         foreach ($this->get('security.context')->getToken()->getUser()->getPais() as $pais) {
             $paises[$pais->getId()] = $pais->getId();
         }
         $entities->setParameter(':paises', $paises);
     }
     foreach ($entities->getQuery()->getResult() as $entity) {
         $data[] = array('id' => $entity->getId(), 'nombre' => ucwords(strtolower($entity->__toString())));
     }
     $response = new JsonResponse($data);
     $response->setSharedMaxAge(600);
     //Cache 10 minutes
     return $response;
 }
开发者ID:ramiroavila,项目名称:SIOP-IPAL,代码行数:36,代码来源:RegistroController.php

示例9: indexSupervisoresJsonAction

 /**
  * Lists all Empleados by Query
  *
  * @Route("/data/supervisores.json", name="registros_supervisores_json")
  * @Method("POST")
  * @Template()
  */
 public function indexSupervisoresJsonAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $entities = $em->getRepository('BcTicCamIpalBundle:Empleado')->createQueryBuilder('r')->where(' (p.id = :pais) AND (  (r.rut LIKE :query) OR (r.nombre LIKE :query) ) ')->orderBy('r.nombre', 'ASC')->join('r.pais', 'p')->setParameters(array('pais' => $request->get('pais'), 'query' => '%' . $request->get('query') . '%'))->getQuery();
     $data = array();
     foreach ($entities->getResult() as $entity) {
         $data[] = array('id' => $entity->getId(), 'nombre' => ucwords(strtolower($entity->__toString())));
     }
     $response = new JsonResponse($data);
     $response->setSharedMaxAge(600);
     //Cache 10 minutes
     return $response;
 }
开发者ID:ramiroavila,项目名称:SIOP-IPAL,代码行数:20,代码来源:EmpleadoController.php


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