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


PHP ControllerResolverInterface::getInstanceFromDefinition方法代码示例

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


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

示例1: onViewRenderArray

 /**
  * Sets a response given a (main content) render array.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The event to process.
  */
 public function onViewRenderArray(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $result = $event->getControllerResult();
     // Render the controller result into a response if it's a render array.
     if (is_array($result) && ($request->query->has(static::WRAPPER_FORMAT) || $request->getRequestFormat() == 'html')) {
         $wrapper = $request->query->get(static::WRAPPER_FORMAT, 'html');
         // Fall back to HTML if the requested wrapper envelope is not available.
         $wrapper = isset($this->mainContentRenderers[$wrapper]) ? $wrapper : 'html';
         $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$wrapper]);
         $event->setResponse($renderer->renderResponse($result, $request, $this->routeMatch));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:19,代码来源:MainContentViewSubscriber.php

示例2: onViewRenderArray

 /**
  * Sets a response given a (main content) render array.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The event to process.
  */
 public function onViewRenderArray(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $result = $event->getControllerResult();
     $format = $request->getRequestFormat();
     // Render the controller result into a response if it's a render array.
     if (is_array($result)) {
         if (isset($this->mainContentRenderers[$format])) {
             $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$format]);
             $event->setResponse($renderer->renderResponse($result, $request, $this->routeMatch));
         } else {
             $supported_formats = array_keys($this->mainContentRenderers);
             $supported_mimetypes = array_map([$request, 'getMimeType'], $supported_formats);
             $event->setResponse(new JsonResponse(['message' => 'Not Acceptable.', 'supported_mime_types' => $supported_mimetypes], 406));
         }
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:23,代码来源:MainContentViewSubscriber.php

示例3: onViewRenderArray

 /**
  * Sets a response given a (main content) render array.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The event to process.
  */
 public function onViewRenderArray(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $result = $event->getControllerResult();
     // Render the controller result into a response if it's a render array.
     if (is_array($result) && ($request->query->has(static::WRAPPER_FORMAT) || $request->getRequestFormat() == 'html')) {
         $wrapper = $request->query->get(static::WRAPPER_FORMAT, 'html');
         // Fall back to HTML if the requested wrapper envelope is not available.
         $wrapper = isset($this->mainContentRenderers[$wrapper]) ? $wrapper : 'html';
         $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$wrapper]);
         $response = $renderer->renderResponse($result, $request, $this->routeMatch);
         // The main content render array is rendered into a different Response
         // object, depending on the specified wrapper format.
         if ($response instanceof CacheableResponseInterface) {
             $main_content_view_subscriber_cacheability = (new CacheableMetadata())->setCacheContexts(['url.query_args:' . static::WRAPPER_FORMAT]);
             $response->addCacheableDependency($main_content_view_subscriber_cacheability);
         }
         $event->setResponse($response);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:26,代码来源:MainContentViewSubscriber.php


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