/**
  * 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);
 }
 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);
 }
Exemplo n.º 3
0
 /**
  * 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));
     }
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 /**
  * 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);
 }