當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。