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


PHP GetResponseForControllerResultEvent::isMasterRequest方法代码示例

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


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

示例1: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     if ('json' !== $request->getRequestFormat()) {
         return;
     }
     $result = $event->getControllerResult();
     if (null === $result) {
         $event->setResponse(new JsonResponse(null, 204));
         return;
     }
     if ($result instanceof Response) {
         return;
     }
     $response = new JsonResponse();
     if ($request->isMethod('POST')) {
         $response->setStatusCode(201);
     }
     if (!is_scalar($result)) {
         $result = $this->getSerializer()->normalize($result, null, ['groups' => $this->options['serialization_default_groups']]);
     }
     $response->setData($result);
     $event->setResponse($response);
 }
开发者ID:chrisyue,项目名称:auto-json-response-bundle,代码行数:27,代码来源:AutoJsonResponseListener.php

示例2: onKernelView

 /**
  * Persists, updates or delete data return by the controller if applicable.
  *
  * @param GetResponseForControllerResultEvent $event
  *
  * @return mixed
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     if (!in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_DELETE])) {
         return;
     }
     $resourceType = $request->attributes->get('_resource_type');
     if (!$resourceType) {
         return;
     }
     $controllerResult = $event->getControllerResult();
     if (null === ($objectManager = $this->getManager($resourceType, $controllerResult))) {
         return $controllerResult;
     }
     switch ($request->getMethod()) {
         case Request::METHOD_POST:
             $objectManager->persist($controllerResult);
             break;
         case Request::METHOD_DELETE:
             $objectManager->remove($controllerResult);
             $event->setControllerResult(null);
             break;
     }
     $objectManager->flush();
 }
开发者ID:rolebi,项目名称:DunglasApiBundle,代码行数:35,代码来源:ManagerViewListener.php

示例3: onKernelView

 /**
  * In an API context, converts any data to a JSON-LD response.
  *
  * @param GetResponseForControllerResultEvent $event
  *
  * @return JsonLdResponse|mixed
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $controllerResult = $event->getControllerResult();
     if ($controllerResult instanceof Response) {
         return;
     }
     $request = $event->getRequest();
     $format = $request->attributes->get('_api_format');
     if (self::FORMAT !== $format) {
         return;
     }
     switch ($request->getMethod()) {
         case Request::METHOD_POST:
             $status = 201;
             break;
         case Request::METHOD_DELETE:
             $status = 204;
             break;
         default:
             $status = 200;
             break;
     }
     $resourceType = $request->attributes->get('_resource_type');
     $response = new JsonLdResponse($resourceType ? $this->normalizer->normalize($controllerResult, self::FORMAT, $resourceType->getNormalizationContext() + ['request_uri' => $request->getRequestUri()]) : $controllerResult, $status);
     $event->setResponse($response);
 }
开发者ID:rolebi,项目名称:DunglasApiBundle,代码行数:36,代码来源:ResponderViewListener.php

示例4: onKernelView

 /**
  * Auto-convert to JsonResponse whether the controller result is a ProgressBar instance.
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $result = $event->getControllerResult();
     if (!$event->isMasterRequest() || !$request->isXmlHttpRequest() || !$result instanceof ProgressBar) {
         return;
     }
     $event->setResponse($this->createResponse($result));
 }
开发者ID:ynloultratech,项目名称:framework,代码行数:14,代码来源:ProgressBarListener.php

示例5: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $this->logger->debug('Response builder listener: catch kernel.request event');
     // If this is not a master request, skip handling
     if (!$event->isMasterRequest()) {
         $this->logger->debug('Response builder listener: this is not master request, skip');
         return;
     }
     // If content already prepared
     if ($event->hasResponse()) {
         $this->logger->debug('Response builder listener: event already has response, skip');
         return;
     }
     // Getting controller result
     $result = $event->getControllerResult();
     // If result is Response instance
     if ($result instanceof Response) {
         $this->logger->debug('Response builder listener: controller result is already an instance of Response, skip');
         return;
     }
     // Getting action
     $apiServerAction = $event->getRequest()->attributes->get('apiAction');
     /* @var $apiServerAction ApiServerAction */
     // Something wrong
     if (!$apiServerAction) {
         $this->logger->error('Response parser listener: request has no apiAction attribute, throwing access denied exception');
         throw new AccessDeniedHttpException();
     }
     // Getting api server interface
     $apiServerInterface = $apiServerAction->getApiServerInterface();
     // Getting connection
     $apiServerConnection = $event->getRequest()->attributes->get('apiConnection');
     /* @var $apiServerConnection ApiServerConnection */
     // Something wrong
     if (!$apiServerConnection) {
         $this->logger->error('Response parser listener: request has no apiConnection attribute, throwing access denied exception');
         throw new AccessDeniedHttpException();
     }
     // Creating api response
     try {
         $apiResponse = $apiServerInterface->getApiResponse($result);
         $newApiUserToken = $apiServerConnection->getNewApiUserToken();
         if ($newApiUserToken) {
             $this->logger->debug('Response builder listener: applying new api user token to response');
             $apiResponse->setUserToken($newApiUserToken);
         }
     } catch (\Exception $e) {
         $this->logger->error(sprintf('Response parser listener: problem with building response ("%s"), sending exception response', $e->getMessage()));
         $apiResponse = $apiServerInterface->getExceptionResponse($e->getMessage());
     }
     // Setting response
     $event->setResponse(new JsonResponse($apiResponse->export()));
     $this->logger->debug('Response builder listener: response built');
 }
开发者ID:leoza,项目名称:api-server-bundle,代码行数:54,代码来源:ResponseBuilder.php

示例6: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $apiResponse = $event->getControllerResult();
     if (!$apiResponse instanceof ApiResponse) {
         return;
     }
     $response = $this->toSymfonyResponse($apiResponse, $event->getRequest());
     $event->setResponse($response);
 }
开发者ID:alcalyn,项目名称:serializable-api-response,代码行数:15,代码来源:ApiResponseFilter.php

示例7: onKernelView

 /**
  * Validates data returned by the controller if applicable.
  *
  * @param GetResponseForControllerResultEvent $event
  *
  * @return mixed
  *
  * @throws ValidationException
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $resourceType = $event->getRequest()->attributes->get('_resource_type');
     if (!$resourceType || !in_array($event->getRequest()->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT])) {
         return;
     }
     $violations = $this->validator->validate($event->getControllerResult(), null, $resourceType->getValidationGroups());
     if (0 !== count($violations)) {
         throw new ValidationException($violations);
     }
 }
开发者ID:rolebi,项目名称:DunglasApiBundle,代码行数:23,代码来源:ValidationViewListener.php

示例8: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $result = $event->getControllerResult();
     if (!$result instanceof ControllerResult) {
         return;
     }
     $attributes = $event->getRequest()->attributes;
     $app = array_replace($this->appDefaults, $attributes->get('_app', []), $result->app->all());
     $result->app->replace($app);
     $attributes->set('_app', $app);
 }
开发者ID:supportyard,项目名称:framework-bundle,代码行数:17,代码来源:RouteAppListener.php

示例9: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $result = $event->getControllerResult();
     if (!$result instanceof ControllerResult) {
         return;
     }
     $content = '';
     $template = $result->app->get('page_template');
     if ($template) {
         $content = trim($this->templating->render($template, $result->view->all()));
     }
     $event->setResponse(new Response($content));
 }
开发者ID:supportyard,项目名称:framework-bundle,代码行数:19,代码来源:ViewRendererListener.php


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