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


PHP GetResponseForControllerResultEvent::getResponse方法代码示例

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


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

示例1: onKernelView

 /**
  * Dumps the statstable
  * @param  GetResponseForControllerResultEvent $event
  * @throws \RuntimeException
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $configuration = $event->getRequest()->attributes->get('_statstable');
     if (!$configuration instanceof Configuration\StatsTableResult) {
         return;
     }
     $types = $this->getTypes();
     $format = $configuration->getFormat();
     $formatConfiguration = array();
     foreach ($types as $type) {
         if (in_array($format, $type['formats'])) {
             $formatConfiguration = $type;
             break;
         }
     }
     if (0 === count($formatConfiguration)) {
         throw new \RuntimeException('Invalid format : "' . $format . '" given.');
     }
     $statsTable = $event->getControllerResult();
     if (!$statsTable instanceof \IgraalOSL\StatsTable\StatsTable) {
         throw new \RuntimeException('Controller result must be an instance of \\IgraalOSL\\StatsTable\\StatsTable');
     }
     $response = $event->getResponse();
     if (!$response) {
         $response = new Response();
     }
     $event->setResponse($response);
     /** @var \IgraalOSB\StatsTable\Dumper\DumperInterface $dumper */
     $dumper = new $formatConfiguration['class']();
     $stResponse = new StatsTableResponse($statsTable, $dumper);
     $response->headers->set('Content-type', $stResponse->headers->get('content-type'));
     $response->setContent($stResponse->getContent());
     unset($stResponse);
 }
开发者ID:igraal,项目名称:stats-table-bundle,代码行数:39,代码来源:StatsTableListener.php

示例2: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $response = $event->getResponse();
     if ($response && $response->headers->get('Content-type') == 'application/json') {
         return;
     }
     $controllerResult = $event->getControllerResult();
     $response = new Response();
     $response->setStatusCode(200);
     $response->headers->add(array('Content-type' => 'application/json'));
     list($controllerObject, $controllerMethod) = explode('::', $event->getRequest()->get('_controller'));
     $method = new \ReflectionMethod($controllerObject, $controllerMethod);
     $annotations = $this->reader->getMethodAnnotations($method);
     $full = false;
     foreach ($annotations as $annotation) {
         if ($annotation instanceof \Hyper\AdsBundle\Api\Json) {
             $full = $annotation->full;
         }
     }
     if (is_object($controllerResult)) {
         $content = json_encode($this->serializer->toJson($controllerResult, $full));
     } elseif (is_array($controllerResult) && !empty($controllerResult) && is_object(current($controllerResult))) {
         $content = json_encode($this->serializer->toJsonArray($controllerResult));
     } else {
         $content = json_encode($controllerResult);
     }
     $response->setContent($content);
     $event->setResponse($response);
 }
开发者ID:topstarsmith,项目名称:Adserver-Project,代码行数:29,代码来源:RestViewEventListener.php

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

示例4: onIframeUpload

 public function onIframeUpload(GetResponseForControllerResultEvent $event)
 {
     $response = $event->getResponse();
     // Browser IFRAMEs expect HTML. Browser extensions, such as Linkification
     // and Skype's Browser Highlighter, convert URLs, phone numbers, etc. into
     // links. This corrupts the JSON response. Protect the integrity of the
     // JSON data by making it the value of a textarea.
     // @see http://malsup.com/jquery/form/#file-upload
     // @see http://drupal.org/node/1009382
     $html = '<textarea>' . $response->getContent() . '</textarea>';
     return new Response($html);
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:12,代码来源:ViewSubscriber.php

示例5: onViewResponse

 /**
  * This event is being triggered after the controllers we called and before the response is checked.
  * Because our html controllers don't return anything we build the response here.
  *
  * @param GetResponseForControllerResultEvent $event The event.
  */
 public function onViewResponse(GetResponseForControllerResultEvent $event)
 {
     // get the event dispatcher
     $dispatcher = $this->framework->getEventDispatcher();
     // create an event
     $cevent = new ControllerEvent(null, $event->getRequest(), $event->getResponse(), $this);
     // dispatch the events
     $dispatcher->dispatch($this->event2Name1, $cevent);
     $dispatcher->dispatch($this->event2Name2, $cevent);
     $dispatcher->dispatch("App_Controllers_View_PostDispatch", $cevent);
     if ($this->module->isBasedOnTemplates() == false) {
         // simply return since here is nothing needed from the template
         return;
     }
     // final events if cache is due (before the css/js compilation)
     if ($this->isCacheDue()) {
         // run all theme custom commands
         $this->framework->getTheme()->beforeCompile();
     }
     // get the compressed urls
     $cssUrl = $this->getLessUrl();
     $jsUrl = $this->getJSUrl();
     // assign them to the template
     $this->assign("cssUrl", $cssUrl);
     $this->assign("jsUrl", $jsUrl);
     // final events if cache is due (after the css/js complication)
     if ($this->isCacheDue()) {
         $this->copyStaticContent();
         // run all theme custom commands
         $this->framework->getTheme()->afterCompile();
     }
     $this->framework->getTheme()->fixSmarty($this);
     // if still no template there is a problem
     if ($this->templateFile == "") {
         throw new \Symfony\Component\HttpKernel\Exception\BadRequestHttpException("Template does not exist: " . $this->technicalTemplateName);
     }
     // get our template
     $content = $this->fetch($this->templateFile);
     // parse language elements
     $content = $this->parseLanguage($content);
     // our response
     $newResponse = new Response();
     $newResponse->setContent($content);
     $newResponse->setStatusCode(200);
     $event->setResponse($newResponse);
 }
开发者ID:skelpo,项目名称:framework,代码行数:52,代码来源:View.php


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