本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent::hasResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseForControllerResultEvent::hasResponse方法的具体用法?PHP GetResponseForControllerResultEvent::hasResponse怎么用?PHP GetResponseForControllerResultEvent::hasResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent
的用法示例。
在下文中一共展示了GetResponseForControllerResultEvent::hasResponse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelResponse
/**
* @param GetResponseForControllerResultEvent $event
*
* @return GetResponseForControllerResultEvent
*/
public function onKernelResponse(GetResponseForControllerResultEvent $event)
{
if ($event->hasResponse()) {
return $event;
}
$accept = $event->getRequest()->get('_accept');
$responseFactory = new Factory($accept);
$response = $responseFactory->create($event->getControllerResult());
$event->setResponse($response);
return $event;
}
示例2: onKernelView
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$this->logger->debug('Response builder listener: catch kernel.request event');
// If this is not a master request, skip handling
if (!$event->isMasterRequest()) {
$this->logger->debug('Response builder listener: this is not master request, skip');
return;
}
// If content already prepared
if ($event->hasResponse()) {
$this->logger->debug('Response builder listener: event already has response, skip');
return;
}
// Getting controller result
$result = $event->getControllerResult();
// If result is Response instance
if ($result instanceof Response) {
$this->logger->debug('Response builder listener: controller result is already an instance of Response, skip');
return;
}
// Getting action
$apiServerAction = $event->getRequest()->attributes->get('apiAction');
/* @var $apiServerAction ApiServerAction */
// Something wrong
if (!$apiServerAction) {
$this->logger->error('Response parser listener: request has no apiAction attribute, throwing access denied exception');
throw new AccessDeniedHttpException();
}
// Getting api server interface
$apiServerInterface = $apiServerAction->getApiServerInterface();
// Getting connection
$apiServerConnection = $event->getRequest()->attributes->get('apiConnection');
/* @var $apiServerConnection ApiServerConnection */
// Something wrong
if (!$apiServerConnection) {
$this->logger->error('Response parser listener: request has no apiConnection attribute, throwing access denied exception');
throw new AccessDeniedHttpException();
}
// Creating api response
try {
$apiResponse = $apiServerInterface->getApiResponse($result);
$newApiUserToken = $apiServerConnection->getNewApiUserToken();
if ($newApiUserToken) {
$this->logger->debug('Response builder listener: applying new api user token to response');
$apiResponse->setUserToken($newApiUserToken);
}
} catch (\Exception $e) {
$this->logger->error(sprintf('Response parser listener: problem with building response ("%s"), sending exception response', $e->getMessage()));
$apiResponse = $apiServerInterface->getExceptionResponse($e->getMessage());
}
// Setting response
$event->setResponse(new JsonResponse($apiResponse->export()));
$this->logger->debug('Response builder listener: response built');
}
示例3: postController
/**
* @param GetResponseForControllerResultEvent $event
*/
public function postController(GetResponseForControllerResultEvent $event)
{
if ($this->viewModelService->getViewModel()->getTemplate() === null) {
return;
}
if (is_array($event->getControllerResult())) {
$this->viewModelService->set($event->getControllerResult());
}
if (!$event->hasResponse()) {
$event->setResponse($this->viewModelService->render());
}
}
示例4: filterResponse
public function filterResponse(GetResponseForControllerResultEvent $event)
{
/* @var $request \Symfony\Component\HttpFoundation\Request */
$request = $event->getRequest();
if ($request->attributes->has('zend_compat_controller') && !$event->hasResponse()) {
/* @var $zendController ZendController */
$zendController = $request->attributes->get('zend_compat_controller');
$zendController->postDispatch();
/* @var $zendRequest ZendRequest */
$zendRequest = $zendController->getRequest();
/* @var $response Symfony\Component\HttpFoundation\Response */
$response = new Response();
/* @var $zendResponse ZendResponse */
$zendResponse = $zendController->getResponse();
$response->headers->add($zendResponse->getHeaders());
$response->setStatusCode($zendResponse->getHttpResponseCode());
if ($zendController->getHelper('viewrenderer')->getNoRender() === false) {
// TODO: "html" => ContextSwitch
$viewName = sprintf("%sBundle:%s:%s.%s.%s", $zendRequest->getModuleName(), $zendRequest->getControllerName(), $zendRequest->getActionName(), "html", "phtml");
$vars = $zendController->view->allVars();
foreach ($vars as $k => $v) {
if ($v instanceof \Zend_Form) {
$v->setView($this->zendView);
foreach ($v->getElements() as $element) {
$element->setView($this->zendView);
}
}
}
$content = $this->templating->render($viewName, $vars);
if ($zendController->getHelper('layout')->isEnabled()) {
$content = $this->templating->render($zendController->getHelper('layout')->getLayout(), array('content' => $content));
}
$response->setContent($content);
}
$event->setResponse($response);
}
}
示例5: wrapPromise
public static function wrapPromise(GetResponseForControllerResultEvent $event)
{
if (!$event->hasResponse() && $event->getControllerResult() instanceof PromiseInterface) {
$event->setResponse(new self($event->getControllerResult()));
}
}