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


PHP GetResponseForControllerResultEvent::hasResponse方法代码示例

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


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

示例1: onKernelResponse

 /**
  * @param GetResponseForControllerResultEvent $event
  *
  * @return GetResponseForControllerResultEvent
  */
 public function onKernelResponse(GetResponseForControllerResultEvent $event)
 {
     if ($event->hasResponse()) {
         return $event;
     }
     $accept = $event->getRequest()->get('_accept');
     $responseFactory = new Factory($accept);
     $response = $responseFactory->create($event->getControllerResult());
     $event->setResponse($response);
     return $event;
 }
开发者ID:dafiti,项目名称:contentnegotiation-service-provider,代码行数:16,代码来源:Response.php

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

示例3: postController

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function postController(GetResponseForControllerResultEvent $event)
 {
     if ($this->viewModelService->getViewModel()->getTemplate() === null) {
         return;
     }
     if (is_array($event->getControllerResult())) {
         $this->viewModelService->set($event->getControllerResult());
     }
     if (!$event->hasResponse()) {
         $event->setResponse($this->viewModelService->render());
     }
 }
开发者ID:aequasi,项目名称:view-model-bundle,代码行数:15,代码来源:ControllerListener.php

示例4: filterResponse

 public function filterResponse(GetResponseForControllerResultEvent $event)
 {
     /* @var $request \Symfony\Component\HttpFoundation\Request */
     $request = $event->getRequest();
     if ($request->attributes->has('zend_compat_controller') && !$event->hasResponse()) {
         /* @var $zendController ZendController */
         $zendController = $request->attributes->get('zend_compat_controller');
         $zendController->postDispatch();
         /* @var $zendRequest ZendRequest */
         $zendRequest = $zendController->getRequest();
         /* @var $response Symfony\Component\HttpFoundation\Response */
         $response = new Response();
         /* @var $zendResponse ZendResponse */
         $zendResponse = $zendController->getResponse();
         $response->headers->add($zendResponse->getHeaders());
         $response->setStatusCode($zendResponse->getHttpResponseCode());
         if ($zendController->getHelper('viewrenderer')->getNoRender() === false) {
             // TODO: "html" => ContextSwitch
             $viewName = sprintf("%sBundle:%s:%s.%s.%s", $zendRequest->getModuleName(), $zendRequest->getControllerName(), $zendRequest->getActionName(), "html", "phtml");
             $vars = $zendController->view->allVars();
             foreach ($vars as $k => $v) {
                 if ($v instanceof \Zend_Form) {
                     $v->setView($this->zendView);
                     foreach ($v->getElements() as $element) {
                         $element->setView($this->zendView);
                     }
                 }
             }
             $content = $this->templating->render($viewName, $vars);
             if ($zendController->getHelper('layout')->isEnabled()) {
                 $content = $this->templating->render($zendController->getHelper('layout')->getLayout(), array('content' => $content));
             }
             $response->setContent($content);
         }
         $event->setResponse($response);
     }
 }
开发者ID:richardfullmer,项目名称:WhitewashingZFMvcCompatBundle,代码行数:37,代码来源:CoreViewListener.php

示例5: wrapPromise

 public static function wrapPromise(GetResponseForControllerResultEvent $event)
 {
     if (!$event->hasResponse() && $event->getControllerResult() instanceof PromiseInterface) {
         $event->setResponse(new self($event->getControllerResult()));
     }
 }
开发者ID:jakubkulhan,项目名称:reactphp-symfony,代码行数:6,代码来源:PromiseResponse.php


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