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


PHP GetResponseForControllerResultEvent::setControllerResult方法代码示例

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


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

示例1: serializeRawData

 /**
  * Tries to serialize data that are not API resources (e.g. the entrypoint or data returned by a custom controller).
  *
  * @param GetResponseForControllerResultEvent $event
  * @param Request                             $request
  * @param object                              $controllerResult
  *
  * @throws RuntimeException
  */
 private function serializeRawData(GetResponseForControllerResultEvent $event, Request $request, $controllerResult)
 {
     if (!$request->attributes->get('_api_respond')) {
         return;
     }
     if (is_object($controllerResult)) {
         $event->setControllerResult($this->serializer->serialize($controllerResult, $request->getRequestFormat()));
         return;
     }
     if (!$this->serializer instanceof EncoderInterface) {
         throw new RuntimeException(sprintf('The serializer instance must implements the "%s" interface.', EncoderInterface::class));
     }
     $event->setControllerResult($this->serializer->encode($controllerResult, $request->getRequestFormat()));
 }
开发者ID:api-platform,项目名称:core,代码行数:23,代码来源:SerializeListener.php

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

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

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

示例5: onHtmlFragment

 /**
  * Converts an HtmlFragment into an HtmlPage.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The Event to process.
  */
 public function onHtmlFragment(GetResponseForControllerResultEvent $event)
 {
     $fragment = $event->getControllerResult();
     if ($fragment instanceof HtmlFragment && !$fragment instanceof HtmlPage) {
         $page = $this->fragmentRenderer->render($fragment);
         $event->setControllerResult($page);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:HtmlViewSubscriber.php

示例6: onKernelView

 /**
  * Handles Kernel View events
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $parameters = $event->getControllerResult();
     if (!$response instanceof Response && ($template = $request->attributes->get('_template'))) {
         return $event->setControllerResult($this->templating->render($template, $parameters));
     }
 }
开发者ID:phpillip,项目名称:phpillip,代码行数:14,代码来源:TemplateListener.php

示例7: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $result = $event->getControllerResult();
     if (!$result instanceof SuccessResult) {
         return;
     }
     $metadata = $result->getMetadata();
     $response = empty($metadata) ? new Response('', 204) : new JsonResponse($metadata, 200);
     $event->setControllerResult($response);
 }
开发者ID:bburnichon,项目名称:rest-bundle,代码行数:10,代码来源:SuccessResultListener.php

示例8: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $result = $event->getControllerResult();
     $request = $event->getRequest();
     if (!$result instanceof ResourceCreatedResult) {
         return;
     }
     $transformerKey = $request->attributes->get('_rest[transform]', null, true);
     $transformedData = $this->transformer->transform($transformerKey, $result->getResource());
     $transformedData = $this->setMetadata($transformedData, $result);
     $event->setControllerResult(new JsonResponse($transformedData, 201));
 }
开发者ID:bburnichon,项目名称:rest-bundle,代码行数:12,代码来源:ResourceCreatedListener.php

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

示例10: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $_route = $event->getRequest()->attributes->get('_route');
     if ('oro_shortcut_actionslist' == $_route) {
         $controllerResult = $event->getControllerResult();
         foreach ($controllerResult['actionsList'] as $route => $data) {
             if (!$this->whitelistProvider->isItemWhitelisted($route)) {
                 unset($controllerResult['actionsList'][$route]);
             }
         }
         $event->setControllerResult($controllerResult);
     }
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:16,代码来源:ShortcutListener.php

示例11: __invoke

 public function __invoke(GetResponseForControllerResultEvent $event)
 {
     $controllerResult = $event->getControllerResult();
     $callback = $this->app['callback_resolver']->resolveCallback($this->callback);
     if (!$this->shouldRun($callback, $controllerResult)) {
         return;
     }
     $response = call_user_func($callback, $controllerResult, $event->getRequest());
     if ($response instanceof Response) {
         $event->setResponse($response);
     } elseif (null !== $response) {
         $event->setControllerResult($response);
     }
 }
开发者ID:shomimn,项目名称:builder,代码行数:14,代码来源:ViewListenerWrapper.php

示例12: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $_route = $event->getRequest()->attributes->get('_route');
     if ('oro_config_configuration_system' !== $_route) {
         return;
     }
     $result = $event->getControllerResult();
     /** @var AbstractNodeDefinition $data */
     $data = clone $result['data'];
     $this->cleanTree($data);
     $form = clone $result['form'];
     $this->clearForm($form);
     $result['data'] = $data;
     $result['form'] = $form;
     $event->setControllerResult($result);
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:19,代码来源:ConfigurationListener.php

示例13: onKernelView

 /**
  * Persists, updates or delete data return by the controller if applicable.
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $user = $event->getControllerResult();
     if (!$user instanceof UserInterface) {
         return;
     }
     switch ($event->getRequest()->getMethod()) {
         case Request::METHOD_POST:
         case Request::METHOD_PUT:
             $this->userManager->updateUser($user, false);
             break;
         case Request::METHOD_DELETE:
             $this->userManager->deleteUser($user);
             $event->setControllerResult(null);
             break;
     }
 }
开发者ID:ZeBigDuck,项目名称:DunglasApiBundle,代码行数:22,代码来源:EventListener.php

示例14: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $response = $event->getControllerResult();
     if ($response instanceof Response) {
         // If it's a response, just continue
         return;
     }
     $request = $event->getRequest();
     if ($request->attributes->has('_template')) {
         //template is already set
         return;
     }
     $nodeTranslation = $request->attributes->get('_nodeTranslation');
     if ($nodeTranslation) {
         $entity = $request->attributes->get('_entity');
         $url = $request->attributes->get('url');
         $nodeMenu = $request->attributes->get('_nodeMenu');
         $parameters = $request->attributes->get('_renderContext');
         if ($request->get('preview') === true) {
             $version = $request->get('version');
             if (!empty($version) && is_numeric($version)) {
                 $nodeVersion = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->find($version);
                 if (!is_null($nodeVersion)) {
                     $entity = $nodeVersion->getRef($this->em);
                 }
             }
         }
         $renderContext = array('nodetranslation' => $nodeTranslation, 'slug' => $url, 'page' => $entity, 'resource' => $entity, 'nodemenu' => $nodeMenu);
         if (is_array($parameters) || $parameters instanceof \ArrayObject) {
             $parameters = array_merge($renderContext, (array) $parameters);
         } else {
             $parameters = $renderContext;
         }
         if (is_array($response)) {
             // If the response is an array, merge with rendercontext
             $parameters = array_merge($parameters, $response);
         }
         //set the rendercontext with all params as response, plus the template in the request attribs
         //the SensioFrameworkExtraBundle kernel.view will handle everything else
         $event->setControllerResult((array) $parameters);
         $template = new Template(array());
         $template->setTemplate($entity->getDefaultView());
         $request->attributes->set('_template', $template);
     }
 }
开发者ID:VickyDeschrijver,项目名称:KunstmaanBundlesCMS,代码行数:48,代码来源:RenderContextListener.php

示例15: onKernelView

 /**
  * Persists, updates or delete data return by the controller if applicable.
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     try {
         RequestAttributesExtractor::extractAttributes($request);
     } catch (RuntimeException $e) {
         return;
     }
     $user = $event->getControllerResult();
     if (!$user instanceof UserInterface || $request->isMethodSafe(false)) {
         return;
     }
     switch ($request->getMethod()) {
         case Request::METHOD_DELETE:
             $this->userManager->deleteUser($user);
             $event->setControllerResult(null);
             break;
         default:
             $this->userManager->updateUser($user);
             break;
     }
 }
开发者ID:api-platform,项目名称:core,代码行数:27,代码来源:EventListener.php


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