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


PHP GetResponseForControllerResultEvent::getControllerResult方法代码示例

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


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

示例1: onControllerView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onControllerView(GetResponseForControllerResultEvent $event)
 {
     if (!$event->getControllerResult() instanceof XmlRpcResponse) {
         return;
     }
     $event->setResponse($this->responseGenerator->fromXmlRpcResponse($event->getControllerResult()));
 }
开发者ID:bdunogier,项目名称:xmlrpcbundle,代码行数:10,代码来源:ResponseEventListener.php

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

示例3: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->has('_rest') || $event->getControllerResult() instanceof Response) {
         return;
     }
     $config = $this->normalizeConfig($request->attributes->get('_rest', array(), true));
     $includes = $request->query->get('include', null);
     $data = $event->getControllerResult();
     $transformedData = $this->transformResult($config, $data, $includes, $request);
     $event->setControllerResult($transformedData);
 }
开发者ID:alchemy-fr,项目名称:rest-bundle,代码行数:12,代码来源:TransformResponseListener.php

示例4: onKernelView

 /**
  * Perform standard rendering.  This event only fires if the previous (REQUEST) event did not generate a response.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     LoggerRegistry::debug('EngineRendererListener performing render() on VIEW event');
     $request = $event->getRequest();
     $path = explode(':', $request->attributes->get('_route'));
     // Set the module attribute.
     $request->attributes->set('_module', $path[0]);
     // Use either the controller result or the 'natural' name of the view based on the route specifier.
     $request->attributes->set('_view', is_null($event->getControllerResult()) ? $path[1] : $event->getControllerResult());
     // Let the engine render the response and add instrumentation headers; set back to the event.
     $response = $this->getEngine()->renderPage($request);
     $event->setResponse($this->getEngine()->instrumentResponse($response));
 }
开发者ID:sitegear,项目名称:sitegear,代码行数:18,代码来源:EngineRendererListener.php

示例5: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (!$this->enabled) {
         return;
     }
     $response = $event->getControllerResult();
     if ($response !== null) {
         return;
     }
     $request = $event->getRequest();
     $routeName = $request->attributes->get('_route');
     if (!($route = $this->routes->get($routeName))) {
         return;
     }
     if (!($args = $route->getOption('_redirect'))) {
         return;
     }
     $uri = isset($args['uri']) ? $args['uri'] : null;
     if (isset($args['callable'])) {
         $arguments = $this->resolver->getArguments($request, $args['callable']);
         $resolved = call_user_func_array($args['callable'], $arguments);
         if (null == $uri) {
             $uri = $resolved;
         } else {
             if (null === $this->urlGenerator) {
                 throw new \InvalidArgumentException("The UrlGeneratorServiceProvider must be registered to use named routes");
             }
             $uri = $this->urlGenerator->generate($uri, $resolved);
         }
     }
     if (!is_string($uri)) {
         throw new \InvalidArgumentException("Could not resolve uri for redirect");
     }
     $event->setResponse(new RedirectResponse($uri));
 }
开发者ID:davedevelopment,项目名称:tinder,代码行数:35,代码来源:RedirectListener.php

示例6: decorateView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 protected function decorateView(GetResponseForControllerResultEvent $event)
 {
     $params = $event->getRequest()->attributes;
     array_walk($this->decorators, function (DecoratorInterface $decorator) use($event, $params) {
         $event->setControllerResult($decorator->decorate($params, $event->getControllerResult()));
     });
 }
开发者ID:ibrows,项目名称:rest-bundle,代码行数:10,代码来源:CollectionDecorationListener.php

示例7: onKernelView

 /**
  * Renders the layout and initializes the content of a new response object
  * with the rendered layout.
  *
  * @param GetResponseForControllerResultEvent $event
  *
  * @throws LogicException if @Layout annotation is used in incorrect way
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     /** @var LayoutAnnotation|null $layoutAnnotation */
     $layoutAnnotation = $request->attributes->get('_layout');
     if (!$layoutAnnotation) {
         return;
     }
     if ($request->attributes->get('_template')) {
         throw new LogicException('The @Template() annotation cannot be used together with the @Layout() annotation.');
     }
     $parameters = $event->getControllerResult();
     if (is_array($parameters)) {
         $context = new LayoutContext();
         foreach ($parameters as $key => $value) {
             $context->set($key, $value);
         }
         $this->configureContext($context, $layoutAnnotation);
         $layout = $this->getLayout($context, $layoutAnnotation);
     } elseif ($parameters instanceof ContextInterface) {
         $this->configureContext($parameters, $layoutAnnotation);
         $layout = $this->getLayout($parameters, $layoutAnnotation);
     } elseif ($parameters instanceof Layout) {
         if (!$layoutAnnotation->isEmpty()) {
             throw new LogicException('The empty @Layout() annotation must be used when ' . 'the controller returns an instance of "Oro\\Component\\Layout\\Layout".');
         }
         $layout = $parameters;
     } else {
         return;
     }
     $response = new Response();
     $response->setContent($layout->render());
     $event->setResponse($response);
 }
开发者ID:Maksold,项目名称:platform,代码行数:42,代码来源:LayoutListener.php

示例8: onKernelView

 /**
  * Converts a PSR-7 response to a Symfony response.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The Event to process.
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $controller_result = $event->getControllerResult();
     if ($controller_result instanceof ResponseInterface) {
         $event->setResponse($this->httpFoundationFactory->createResponse($controller_result));
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:PsrResponseSubscriber.php

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

示例10: onView

 public function onView(GetResponseForControllerResultEvent $event)
 {
     $response = $event->getControllerResult();
     if (is_string($response)) {
         $event->setResponse(new Response($response));
     }
 }
开发者ID:poiuke,项目名称:framework,代码行数:7,代码来源:StringResponseListener.php

示例11: onKernelView

 /**
  * Persists, updates or delete data return by the controller if applicable.
  *
  * @param GetResponseForControllerResultEvent $event
  *
  * @return mixed
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     if ($request->isMethodSafe()) {
         return;
     }
     $resourceClass = $request->attributes->get('_api_resource_class');
     if (null === $resourceClass) {
         return;
     }
     $controllerResult = $event->getControllerResult();
     if (null === ($objectManager = $this->getManager($resourceClass, $controllerResult))) {
         return;
     }
     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:soyuka,项目名称:core,代码行数:32,代码来源:WriteListener.php

示例12: onKernelView

 /**
  * In an API context, converts any data to a JSON-LD response.
  *
  * @param GetResponseForControllerResultEvent $event
  *
  * @return JsonLdResponse|mixed
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $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:PaskR,项目名称:DunglasApiBundle,代码行数:33,代码来源:ResponderViewListener.php

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

示例14: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event The event to handle
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     /**
      * Anytime we don't find what we're looking for, return and let other
      * listeners handle things
      */
     $response = $event->getControllerResult();
     if (!is_array($response)) {
         return;
     }
     $request = $event->getRequest();
     $routeName = $request->attributes->get('_route');
     if (!($route = $this->app['routes']->get($routeName))) {
         return;
     }
     if (!($args = $route->getOption('_view'))) {
         return;
     }
     $template = $args['template'];
     $callable = $args['callable'];
     if ($callable) {
         $response = $callable($response, $request);
     }
     if ($response instanceof Response) {
         $event->setResponse($response);
         return;
     }
     if (null !== $template) {
         $output = $this->render($template, $response);
         $event->setResponse(new Response($output));
     }
 }
开发者ID:davedevelopment,项目名称:tinder,代码行数:35,代码来源:ViewListener.php

示例15: onKernelView

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $e
  */
 public function onKernelView(GetResponseForControllerResultEvent $e)
 {
     $queryset = $e->getControllerResult();
     $routeName = $e->getRequest()->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $interface = 'SDispatcher\\Common\\PaginatorInterface';
     $paginatorClass = $route->getOption(RouteOptions::PAGINATOR_CLASS);
     if (!$paginatorClass || !is_subclass_of($paginatorClass, $interface)) {
         return;
     }
     try {
         /* @var \SDispatcher\Common\PaginatorInterface $paginator */
         $paginator = new $paginatorClass();
         if (!$paginator->supports($queryset)) {
             return;
         }
         list($headers, $data) = $paginator->paginate($e->getRequest(), $queryset, 0, $route->getOption(RouteOptions::PAGE_LIMIT), $route->getOption(RouteOptions::PAGINATED_META_CONTAINER_NAME), $route->getOption(RouteOptions::PAGINATED_DATA_CONTAINER_NAME));
     } catch (\Exception $ex) {
         list($headers, $data) = array(array(), array());
     }
     $response = new DataResponse($data);
     $response->headers->add($headers);
     $e->setResponse($response);
 }
开发者ID:bcen,项目名称:silex-dispatcher,代码行数:30,代码来源:PaginationListener.php


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