@param GetResponseForControllerResultEvent $event

@throws MalformedContentException
@throws UnsupportedContentTypeException
427603
public function onKernelView(GetResponseForControllerResultEvent $event)
    {
        $request = $event->getRequest();
        if (!$request->attributes->has(RequestMeta::ATTRIBUTE_URI)) {
            return;
        }
        $event->setResponse(
            $this->responseFactory->createResponse(
                $request,
                $event->getControllerResult()
            )
        );
    }
1077651
public function onException(GetResponseForExceptionEvent $event)
    {
        if ($event->isMasterRequest()) {
            return;
        }

        $exception = $event->getException();

        $level = LogLevel::CRITICAL;
        if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
            $level = LogLevel::WARNING;
        }

        $this->logger->log($level, $exception->getMessage(), ['event' => 'exception', 'exception' => $exception]);
    }
764345
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        if (($exception = $event->getException()) instanceof SerializationException) {
            $response = $exception->getResponse()
                ->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);

            $event->setResponse($response);
        }
    }
1304844
public function onKernelException(GetResponseForExceptionEvent $event) {

        $ex = $event->getException();

        // Handle the exception.
        if (true === ($ex instanceof BadUserRoleException)) {
            $this->handleBadUserRoleException($event, $ex);
        }
        if (true === ($ex instanceof RedirectResponseException)) {
            $this->handleRedirectResponseException($event, $ex);
        }

        return $event;
    }
1168017
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $request   = $event->getRequest();
        $exception = $event->getException();

        if (!$this->supports($request)) {
            return;
        }

        $statusCode = $exception instanceof HttpException ? $exception->getStatusCode() : 500;
        $errors     = array();

        switch(true) {

            // validation exception
            case $exception instanceof ValidationException :
                $errors = $this->parseValidationException($exception);
                $statusCode = 400;
            break;

            // other http exceptions
            default:
                $errors = array($exception->getMessage());
        }

        $data = array(
            'code'    => $statusCode,
            'message' => $exception->getMessage(),
            'errors'  => $errors
        );
        if ($this->debug) {
            $data['trace'] = explode("\n", $exception->getTraceAsString());
        }

        $event->setResponse(new JsonResponse($data, $statusCode));
    }
398740
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        if ($this->isProfilerRequest($event->getRequest())) {
            return;
        }

        $exception = $event->getException();

        if ($exception instanceof DatabaseExceptionInterface) {
            $html = $this->renderDatabaseException($exception);
        } elseif ($exception instanceof AbstractSystemValidationException) {
            $html = $this->renderSystemValidationException($exception);
        } else {
            $html = $this->renderException($exception);
        }

        $statusCode = $exception instanceof HttpExceptionInterface ?
            $exception->getStatusCode() :
            Response::HTTP_INTERNAL_SERVER_ERROR;
        $response = new Response($html, $statusCode, ['X-Debug-Exception-Handled' => time()]);

        $event->setResponse($response);
    }
1143911
public function onKernelView(GetResponseForControllerResultEvent $event): void
    {
        $request = $event->getRequest();
        if (!RequestAttributesExtractor::extractAttributes($request)) {
            return;
        }

        $user = $event->getControllerResult();
        if (!$user instanceof UserInterface || $request->isMethodSafe(false)) {
            return;
        }

        if ('DELETE' === $request->getMethod()) {
            $this->userManager->deleteUser($user);
            $event->setControllerResult(null);
        } else {
            $this->userManager->updateUser($user);
        }
    }
897664
public function onException(GetResponseForExceptionEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $attributes = $event->getRequest()->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        $exception = $event->getException();
        if ($exception instanceof HttpExceptionInterface) {
            return;
        }

        $exceptionClass = null;
        foreach ($this->exceptionMap as $sourceException => $targetException) {
            if (is_a($exception, $sourceException, true)) {
                $exceptionClass = $targetException;

                break;
            }
        }

        if ($exceptionClass !== null) {
            $convertedException = new $exceptionClass(
                $exception->getMessage(),
                $exception,
                $exception->getCode()
            );

            $event->setException($convertedException);
        }
    }
337106
public function collectControllerData(FilterControllerEvent $event)
    {
        if (HttpKernelInterface::SUB_REQUEST === $event->getRequestType()) {
            return;
        }

        $controller = $this->getClassName($event->getController()[0]);
        $action     = $event->getController()[1];

        $this->setController($controller);
        $this->setAction($action);
    }
494652
public function buildResponse(GetResponseForControllerResultEvent $event)
    {
        $request = $event->getRequest();

        if (
            !$request->attributes->has(RouteKeys::ACTION) ||
            $request->attributes->get(RouteKeys::ACTION) !== 'capabilities'
        ) {
            return;
        }

        $routes = $event->getControllerResult();
        $response = new Response;
        $links = $response->headers->get('Link', null, false);

        foreach ($routes as $name => $route) {
            $definition = $route->getDefault(RouteKeys::DEFINITION);
            list($collection, $resource) = explode('::', $definition);
            $definition = $this
                ->registry
                ->getCollection($collection)
                ->getResource($resource);

            $links[] = sprintf(
                '<%s>; rel="endpoint"; name="%s_%s"',
                $this->urlGenerator->generate($name),
                $definition->getCollection(),
                $definition
            );
        }

        $response->headers->add(['Link' => $links]);
        $event->setResponse($response);
    }
1138897
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $attributes = $request->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        if (!$attributes->has('itemType')) {
            return;
        }

        $config = $this->loadConfig($attributes->get('itemType'));

        $customParams = $request->query->get('customParams', []);
        if (!is_array($customParams)) {
            throw new RuntimeException(
                sprintf(
                    'Invalid custom parameters specification for "%s" item type.',
                    $attributes->get('itemType')
                )
            );
        }

        $config->addParameters($customParams);

        $configLoadEvent = new ConfigLoadEvent($config);

        Kernel::VERSION_ID >= 40300 ?
            $this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) :
            $this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent);

        $this->container->set('netgen_content_browser.current_config', $config);
    }
1247226
public function onKernelView(GetResponseForControllerResultEvent $event): void
    {
        $request = $event->getRequest();
        if (
            $request->isMethodSafe(false)
            || $request->isMethod('DELETE')
            || !($attributes = RequestAttributesExtractor::extractAttributes($request))
            || !$attributes['receive']
        ) {
            return;
        }

        $resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);
        $inputMetadata = $resourceMetadata->getOperationAttribute($attributes, 'input', [], true);
        if (\array_key_exists('class', $inputMetadata) && null === $inputMetadata['class']) {
            return;
        }

        $validationGroups = $resourceMetadata->getOperationAttribute($attributes, 'validation_groups', null, true);
        $this->validator->validate($event->getControllerResult(), ['groups' => $validationGroups]);
    }
1154953
public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($event->isMasterRequest()
            || $event->getRequest()->attributes->get('_controller') !== $this->exceptionController) {
            return;
        }

        // Status code is not set by the exception controller but only by the
        // kernel at the very end.
        // So lets use the status code from the flatten exception instead.
        $statusCode = $event->getRequest()->attributes->get('exception')->getStatusCode();

        $dir = $this->getGifDir($statusCode);
        $gif = $this->getRandomGif($dir);
        $url = $this->getGifUrl($dir, $gif);

        $content = $event->getResponse()->getContent();

        if (version_compare(Kernel::VERSION, '3.2', '<')) {
            $content = preg_replace(
                '/<img alt="Exception detected!" src=".*" \/>/',
                sprintf('<img alt="Exception detected!" src="%s" data-gif style="width:145px" />', $url),
                $content
            );
        } elseif (version_compare(Kernel::VERSION, '3.3', '<')) {
            $content = preg_replace(
                '@<svg xmlns="http://www.w3.org/2000/svg" width="112"(.*?)</svg>@ims',
                sprintf('<img alt="Exception detected!" src="%s" data-gif style="width:145px" />', $url),
                $content
            );
        } else {
            $content = preg_replace(
                '@<div class="exception-illustration hidden-xs-down">(.*?)</div>@ims',
                sprintf('<div class="exception-illustration hidden-xs-down" style="opacity:1"><img alt="Exception detected!" src="%s" data-gif style="height:66px" /></div>', $url),
                $content
            );
        }

        $event->getResponse()->setContent($content);
    }
491220
public function redirectMyContentTypeNode(GetResponseEvent $event) {
    $request = $event->getRequest();
    $language = $this->languageManager->getCurrentLanguage()->getId();

    if ($request->attributes->get('_route') !== 'entity.node.canonical') {
      return;
    }

    if ($request->attributes->get('node')->getType() !== 'challenge') {
      return;
    }

    // $redirect_url = Url::fromUri('entity:node/123');.
    $node = $request->attributes->get('node');
    if ($language == 'fr') {
      $redirect_url = '/fr/defis/' . $node->getTranslation('fr')->get('field_friendly_url')->getValue()[0]['value'];
    }
    else {
      $redirect_url = '/en/challenges/' . $node->get('field_friendly_url')->getValue()[0]['value'];
    }

    $response = new RedirectResponse($redirect_url, 301);
    $event->setResponse($response);
  }
611503
public function onError(GetResponseForExceptionEvent $event)
    {
        if ($event->getRequest()->isXmlHttpRequest()) {
            $exception = $event->getException();
            if ($exception instanceof InvalidDataException) {
                // return correct status code for invalid data sent by the user
                $response = new JsonResponse($exception->getErrors(), 422);
            } else {
                $response = new JsonResponse([
                    'message' => $exception->getMessage(),
                    'trace' => $exception->getTrace(),
                    //if <200, not http error code
                ], $exception->getCode() < 200 ? 500 : $exception->getCode());
            }

            $event->setResponse($response);
        }
    }
441149
public function onCoreException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        $request = $event->getRequest();

        if ($request->isXmlHttpRequest()
            && get_class($exception) == 'Symfony\Component\Security\Core\Exception\AccessDeniedException') {
            $form = $this->templating->render(
                'ClarolineCoreBundle:Authentication:loginAjaxForm.html.twig'
            );

            //@see https://github.com/gillest/HackSessionBundle
            if (!$request->hasPreviousSession()) {
                $request->cookies->set(session_name(), 'tmp');
                $request->setSession($this->session);
            }

            $event->setResponse(new Response($form, 403));
        }
    }
1191606
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $this->request = $event->getRequest();

        if ($request->attributes->has('start') && $request->attributes->has('count')) {
            return;
        }

        if (false === $this->isEnabled()) {
            return;
        }

        $controller = $event->getController();

        if (false === in_array($request->getMethod(), array('GET', 'HEAD', 'DELETE'))) {
            // pagination only makes sense with GET or DELETE methods
            return;
        }

        $metadata = $this->getControllerActionMetadata($controller);

        if (null === $metadata || null === $metadata->default_start) {
            // no annotations defined for this controller
            return;
        }

        $start = $metadata->default_start;
        $count = $metadata->default_count;

        $range = explode(',', $request->headers->get('Range'));
        if (true === isset($range[0])) {
            $start = intval($range[0]);
        }

        if (true === isset($range[1])) {
            $count = intval($range[1]);
        }

        $violations = new ConstraintViolationList();

        $start_violations = $this->validator->validateValue($start, array(
            // NB: Type assert must come first as otherwise it won't be called
            new \Symfony\Component\Validator\Constraints\Type(array(
                'type'    => 'numeric',
                'message' => 'Headers "Range" attribute first operand (=start) must be a positive integer',
            )),
            new \Symfony\Component\Validator\Constraints\Range(array(
                'min'        => 0,
                'minMessage' => 'Headers "Range" attribute first operand (=start) must be a positive integer',
            )),

        ));

        $count_label = 'Headers "Range" attribute second operand (=count)';
        $count_violations = $this->validator->validateValue($count, array(
            // NB: Type assert must come first as otherwise it won't be called
            new \Symfony\Component\Validator\Constraints\Type(array(
                'type' => 'numeric',
                'message' => "$count_label must be a positive integer",
            )),
            new \Symfony\Component\Validator\Constraints\Range(array(
                'min'        => $metadata->min_count,
                'minMessage' => "$count_label must be greater than or equal to ".$metadata->min_count,
                'max'        => $metadata->max_count,
                'maxMessage' => "$count_label must be less than or equal to ".$metadata->max_count,
            )),
        ));

        $violations->addAll($start_violations);
        $violations->addAll($count_violations);

        $violation_param = $this->getViolationsParameterName($metadata);

        if (null !== $violation_param) {
            // if action has an argument for violations, pass it
            $request->attributes->set($violation_param, $violations);
        } elseif (0 < count($violations)) {
            // if action has no arg for violations and there is at least one, throw an exception
            throw new ValidationException($violations);
        }

        // add pagination properties to attributes
        $request->attributes->set('start', $start);
        $request->attributes->set('count', $count);

        // remove pagination properties from headers
        $request->headers->remove('Range');
    }