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


PHP JsonResponse::prepare方法代码示例

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


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

示例1: run

 /**
  * Run the queue web runner.
  *
  * @param Request $request The request.
  *
  * @return JsonResponse|mixed
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function run(Request $request)
 {
     $queueRepository = EntityHelper::getRepository('Avisota\\Contao:Queue');
     $queueId = $request->get('id');
     $queue = $queueRepository->find($queueId);
     /** @var \Avisota\Contao\Entity\Queue $queue */
     if (!$queue) {
         header("HTTP/1.0 404 Not Found");
         echo '<h1>404 Not Found</h1>';
         exit;
     }
     $user = \BackendUser::getInstance();
     $user->authenticate();
     try {
         return $this->execute($request, $queue, $user);
     } catch (\Exception $exception) {
         // Todo i can't find where this output
         $response = new JsonResponse(array('error' => sprintf('%s in %s:%d', $exception->getMessage(), $exception->getFile(), $exception->getLine())), 500);
         $response->prepare($request);
         return $response;
     }
 }
开发者ID:avisota,项目名称:contao-core,代码行数:31,代码来源:AbstractQueueWebRunner.php

示例2: execute

 /**
  * Execute the queue.
  *
  * @param Request      $request   The request.
  * @param Queue        $queueData The queue data.
  * @param \BackendUser $user      The user.
  *
  * @return JsonResponse
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 protected function execute(Request $request, Queue $queueData, \BackendUser $user)
 {
     global $container;
     if (!$queueData->getAllowManualSending()) {
         $response = new JsonResponse(array('error' => 'manual sending is forbidden'), 403);
         $response->prepare($request);
         return $response;
     }
     $serviceName = sprintf('avisota.queue.%s', $queueData->getId());
     /** @var QueueInterface $queue */
     $queue = $container[$serviceName];
     $transportServiceName = sprintf('avisota.transport.%s', $queueData->getTransport()->getId());
     $transport = $container[$transportServiceName];
     $config = new ExecutionConfig();
     if ($queueData->getMaxSendTime() > 0) {
         $config->setTimeLimit($queueData->getMaxSendTime());
     }
     if ($queueData->getMaxSendCount() > 0) {
         $config->setMessageLimit($queueData->getMaxSendCount());
     }
     $event = new PreQueueExecuteEvent($queue, $transport, $config);
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
     $eventDispatcher->dispatch(PreQueueExecuteEvent::NAME, $event);
     $queue = $event->getQueue();
     $transport = $event->getTransport();
     $config = $event->getConfig();
     $status = $queue->execute($transport, $config);
     $jsonData = array('success' => 0, 'failed' => 0);
     foreach ($status as $stat) {
         $jsonData['success'] += $stat->getSuccessfullySend();
         $jsonData['failed'] += count($stat->getFailedRecipients());
     }
     $response = new JsonResponse($jsonData);
     $response->prepare($request);
     return $response;
 }
开发者ID:avisota,项目名称:contao-core,代码行数:49,代码来源:QeueueExecuteController.php

示例3: prepare

 /**
  * Method prepare response - add Cache directives and etag
  * @author Krzysztof Bednarczyk
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  */
 public function prepare(Request $request)
 {
     $this->setPrivate();
     $this->setMaxAge(0);
     $this->setSharedMaxAge(0);
     $this->headers->addCacheControlDirective('no-cache', true);
     $this->headers->addCacheControlDirective('max-age', 0);
     $this->headers->addCacheControlDirective('must-revalidate', true);
     $this->headers->addCacheControlDirective('no-store', true);
     $this->headers->set("X-Powered-By", "XV-Server v1.0");
     $this->setData(array("handlers" => array_values($this->handlers)));
     $this->setEtag(uniqid());
     $this->setMaxAge(0);
     $this->setLastModified(new DateTime());
     return parent::prepare($request);
 }
开发者ID:xvengine,项目名称:symfony-bridge,代码行数:23,代码来源:XvResponse.php

示例4: __construct

 /**
  * Instantiate Symfony HTTP Foundation's JsonResponse
  * using Symfony's HTTP Foundation Request
  *
  * The Response Interface is used to populate RAISe Response
  */
 public function __construct()
 {
     $this->httpResponse = new JsonResponse();
     $this->httpResponse->prepare(Request::createFromGlobals());
     $this->httpResponse->setEncodingOptions(JSON_PRETTY_PRINT);
 }
开发者ID:uiot,项目名称:middleware_mc_srvcl_rest_raise,代码行数:12,代码来源:ResponseHandler.php


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