當前位置: 首頁>>代碼示例>>PHP>>正文


PHP GetResponseForControllerResultEvent::getRequestType方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent::getRequestType方法的典型用法代碼示例。如果您正苦於以下問題:PHP GetResponseForControllerResultEvent::getRequestType方法的具體用法?PHP GetResponseForControllerResultEvent::getRequestType怎麽用?PHP GetResponseForControllerResultEvent::getRequestType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent的用法示例。


在下文中一共展示了GetResponseForControllerResultEvent::getRequestType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onView

 /**
  * Processes a successful controller into an HTTP 200 response.
  *
  * Some controllers may not return a response object but simply the body of
  * one.  The VIEW event is called in that case, to allow us to mutate that
  * body into a Response object.  In particular we assume that the return
  * from an JSON-type response is a JSON string, so just wrap it into a
  * Response object.
  *
  * @param Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The Event to process.
  */
 public function onView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     // For a master request, we process the result and wrap it as needed.
     // For a subrequest, all we want is the string value.  We assume that
     // is just an HTML string from a controller, so wrap that into a response
     // object.  The subrequest's response will get dissected and placed into
     // the larger page as needed.
     if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
         $method = 'on' . $this->negotiation->getContentType($request);
         if (method_exists($this, $method)) {
             $event->setResponse($this->{$method}($event));
         } else {
             $event->setResponse(new Response('Not Acceptable', 406));
         }
     } else {
         // This is a new-style Symfony-esque subrequest, which means we assume
         // the body is not supposed to be a complete page but just a page
         // fragment.
         $page_result = $event->getControllerResult();
         if ($page_result instanceof HtmlPage || $page_result instanceof Response) {
             return $page_result;
         }
         if (!is_array($page_result)) {
             $page_result = array('#markup' => $page_result);
         }
         // If no title was returned fall back to one defined in the route.
         if (!isset($page_result['#title'])) {
             $page_result['#title'] = $this->titleResolver->getTitle($request, $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT));
         }
         $event->setResponse(new Response(drupal_render_root($page_result)));
     }
 }
開發者ID:anyforsoft,項目名稱:csua_d8,代碼行數:45,代碼來源:ViewSubscriber.php

示例2: onKernelResultView

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *
  * @throws \Exception
  */
 public function onKernelResultView(GetResponseForControllerResultEvent $event)
 {
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     if (!$this->isRestRequest($event->getRequest())) {
         return;
     }
     $result = $event->getControllerResult();
     $event->setResponse($this->visitResult($result));
     $event->stopPropagation();
 }
開發者ID:brookinsconsulting,項目名稱:ezecosystem,代碼行數:17,代碼來源:RestListener.php

示例3: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $result = $event->getControllerResult();
     if (!is_array($result)) {
         return;
     }
     $result = $this->factory->create($this->resolver->resolve($event->getRequest(), $result), $result);
     $event->setResponse(new Response($result));
 }
開發者ID:gigablah,項目名稱:silex-view,代碼行數:12,代碼來源:ArrayToViewListener.php

示例4: onView

 /**
  * Processes a successful controller into an HTTP 200 response.
  *
  * Some controllers may not return a response object but simply the body of
  * one.  The VIEW event is called in that case, to allow us to mutate that
  * body into a Response object.  In particular we assume that the return
  * from an JSON-type response is a JSON string, so just wrap it into a
  * Response object.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
  *   The Event to process.
  */
 public function onView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
         $method = 'on' . $request->getRequestFormat();
         if (method_exists($this, $method)) {
             $event->setResponse($this->{$method}($event));
         } else {
             $event->setResponse(new Response('Not Acceptable', 406));
         }
     }
 }
開發者ID:dev981,項目名稱:gaptest,代碼行數:24,代碼來源:ViewSubscriber.php

示例5: onKernelView

 /**
  * This event is called when the controller action returns something else than a response object (e.g. an array).
  * This function handles the rendering of proper template according to the requested partial.
  * 
  * @param GetResponseForControllerResultEvent $event Event called.
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     // only work with master request
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     // only on NJAX requests
     $njax = $this->container->get('njax');
     if (!$njax->isNjax()) {
         return;
     }
     $request = $event->getRequest();
     $parameters = $event->getControllerResult();
     if (!($njaxConfiguration = $request->attributes->get('_njax'))) {
         return;
     }
     // this behavior is copied from Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView()
     if (null === $parameters) {
         if (!($vars = $request->attributes->get('_template_vars'))) {
             if (!($vars = $request->attributes->get('_template_default_vars'))) {
                 return;
             }
         }
         $parameters = array();
         foreach ($vars as $var) {
             $parameters[$var] = $request->attributes->get($var);
         }
     }
     if (!is_array($parameters)) {
         return $parameters;
     }
     // get the templating engine
     $templating = $this->container->get('templating');
     // now figure out which template to use
     $partial = $njax->getPartial();
     $template = $njaxConfiguration->getPartialTemplate($partial);
     $usedPartial = $partial;
     // if no specified template then try to guess the name of a partial template
     if (!$template) {
         $template = $njaxConfiguration->guessPartialTemplate($partial);
         // if couldn't guess the name then just use the default one
         if (!$template || !$templating->exists($template)) {
             $template = $njaxConfiguration->getDefaultTemplate();
             $usedPartial = null;
         }
     }
     $content = $templating->render($template, $parameters);
     $event->setResponse(new Response($content));
 }
開發者ID:neverbland,項目名稱:njax-bundle,代碼行數:55,代碼來源:NjaxListener.php


注:本文中的Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent::getRequestType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。