本文整理汇总了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);
}
示例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);
}
示例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));
}
}
示例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);
}
示例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);
}