Core controller handler.

@param FilterControllerEvent $event

@throws \InvalidArgumentException
503135
public function onKernelController(FilterControllerEvent $event)
    {
        $request    = $event->getRequest();
        $controller = $event->getController();

        if (is_callable($controller) && method_exists($controller, '__invoke')) {
            $controller = [$controller, '__invoke'];
        }
        
        $this->scopeFetcher->setController($controller);

        $attributeName = $this->getAttributeName($controller);
        $request->attributes->set($attributeName, $this->scopeFetcher);
    }
741006
public function onKernelController(FilterControllerEvent $event): void
    {
        $controller = $event->getController();
        if (\is_array($controller)) {
            [$controller] = $controller; // Ignoring action
        }
        if (!$controller instanceof AdminInjectableInterface && !$controller instanceof ActionInjectableInterface) {
            return;
        }

        $request = $event->getRequest();
        if (!$request->attributes->has('_admin')) {
            $routeName = $request->attributes->get('_route');

            $m = "Missing request attribute '_admin' for route {$routeName}, this means you declared";
            $m .= ' this route outside the admin configuration, please use the admin configuration';
            throw new \LogicException($m);
        }
        $admin = $request->attributes->get('_admin');
        if (!$admin instanceof Admin) {
            throw new \UnexpectedValueException('_admin request attribute is not an Admin object');
        }
        if ($controller instanceof AdminInjectableInterface) {
            $controller->setAdmin($admin);
        }

        if (!$request->attributes->has('_action')) {
            $routeName = $request->attributes->get('_route');

            $m = "Missing request attribute '_action' for route {$routeName},";
            $m .= 'this means you declared this route outside the admin configuration, please include the _action';
            $m .= 'attribute in your route definition or use the admin configuration';
            throw new \LogicException($m);
        }
        $admin->setCurrentAction($request->attributes->get('_action'));
        if ($controller instanceof ActionInjectableInterface) {
            $controller->setAction($admin->getCurrentAction());
        }
    }
1357198
public function onResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();

        $this->setFrameOptions($request, $response);
    }
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]);
    }
473547
public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();
        if ($response) {
            $date = $response->getDate();
            if (empty($date)) {
                $response->setDate(new \DateTime());
            }
        }
    }
1107425
public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();
        $request = $event->getRequest();

        // Cors session do not allow in some browsers the *.
        $response->headers->set('Access-Control-Allow-Origin', $request->headers->get('Origin', '*'));
        $response->headers->set('Access-Control-Allow-Credentials', 'true');

        $corsMethods = $request->attributes->get('corsMethods', '');
        if (!empty($corsMethods)) {
            $response->headers->set('Access-Control-Allow-Methods', $corsMethods);
        }
        $response->headers->set('Access-Control-Expose-Headers', implode(', ', $this->headers));
        $response->headers->set('Access-Control-Allow-Headers', implode(', ', $this->allowHeaders));

        foreach ($this->staticHeaders as $headerName => $headerValue) {
            $response->headers->set($headerName, $headerValue);
        }
    }
1297325
public function onKernelResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $id = $request->get($this->ajaxId);

        if (!$request->isXmlHttpRequest() || null === $id) {
            return;
        }

        if (!isset($this->ajaxEvents[$id])) {
            $event->setResponse(new Response());

            return;
        }

        $ajaxEvent = $this->ajaxEvents[$id];

        $request->setRequestFormat($ajaxEvent->getFormat());
        $event->setResponse($ajaxEvent->generateResponse());
        $event->stopPropagation();
    }
1307104
public function onKernelResponse(FilterResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $layoutView = $event->getRequest()->attributes->get(
            $this->isExceptionResponse ?
                'ngbmExceptionLayoutView' :
                'ngbmLayoutView'
        );

        if (!$layoutView instanceof LayoutViewInterface) {
            return;
        }

        $this->tagger->tagLayout($event->getResponse(), $layoutView->getLayout());
    }
926272
public function onView(GetResponseForControllerResultEvent $event)
    {
        if (!$this->eventRequestMatches($event)) {
            return;
        }
        $event->setResponse($this->responseTransformer->createResponseFromContent($event->getControllerResult()));
    }
252208
public function onKernelController(FilterControllerEvent $event)
    {
        $controller = $event->getController();
        $request = $event->getRequest();
        $configurations = [];

        if ($configuration = $request->attributes->get('_converters')) {
            foreach (\is_array($configuration) ? $configuration : [$configuration] as $configuration) {
                $configurations[$configuration->getName()] = $configuration;
            }
        }

        if (\is_array($controller)) {
            $r = new \ReflectionMethod($controller[0], $controller[1]);
        } elseif (\is_object($controller) && \is_callable([$controller, '__invoke'])) {
            $r = new \ReflectionMethod($controller, '__invoke');
        } else {
            $r = new \ReflectionFunction($controller);
        }

        // automatically apply conversion for non-configured objects
        if ($this->autoConvert) {
            $configurations = $this->autoConfigure($r, $request, $configurations);
        }

        $this->manager->apply($request, $configurations);
    }
594229
public function onKernelView(GetResponseForControllerResultEvent $event): void
    {
        $presentation = $event->getControllerResult();

        if (!$presentation instanceof PresentationInterface) {
            // Not the presentation instance
            return;
        }

        $data = null;
        $headers = [];

        if ($presentation->getResource()) {
            $acceptableMediaTypes = $event->getRequest()->getAcceptableContentTypes();
            $serializer = $this->serializerResolver->resolveByMediaTypes(
                get_class($presentation->getResource()),
                $acceptableMediaTypes,
                $acceptableMediaType
            );

            $serializationContext = $this->serializationContextCollector->collect();
            $data = $serializer->serialize($presentation->getResource(), $serializationContext);
            $headers = [
                'Content-Type' => $acceptableMediaType,
            ];
        }

        $response = new Response($data, $presentation->getStatusCode());
        $response->headers->add($headers);

        $event->setResponse($response);
    }
802500
public function setControllerDependencies(FilterControllerEvent $event)
    {
        $controller = $event->getController();
        if (!is_array($controller)) {
            return false;
        }

        $controller = $controller[0];

        if ($controller instanceof ConfigurationAwareInterface) {
            $controller->setKernel($this->container->get('kernel'));
            $controller->setCacheHandler($this->container->get('symfonyid.admin.cache.cache_handler'));
            $controller->setConfiguratorFactory($this->container->get('symfonyid.admin.configuration.configurator_factory'));
        }
    }
255612
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $event->getRequest();

        // Check if the event has a nodeTranslation, if not this method can be skipped
        if (!$request->attributes->has('_nodeTranslation')) {
            return;
        }

        $nodeTranslation = $request->attributes->get('_nodeTranslation');
        if (!($nodeTranslation instanceof NodeTranslation)) {
            throw new \Exception('Invalid _nodeTranslation value found in request attributes');
        }
        $entity = $nodeTranslation->getRef($this->em);

        // If the entity is an instance of the SlugActionInterface, change the controller
        if ($entity instanceof SlugActionInterface) {
            $request->attributes->set('_entity', $entity);

            // Do security check by firing an event that gets handled by the SlugSecurityListener
            $securityEvent = new SlugSecurityEvent();
            $securityEvent
                ->setNode($nodeTranslation->getNode())
                ->setEntity($entity)
                ->setRequest($request)
                ->setNodeTranslation($nodeTranslation);

            $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);

            // Set the right controller
            $request->attributes->set('_controller', $entity->getControllerAction());
            $event->setController($this->resolver->getController($request));
        }
    }
719279
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $this->request = $event->getRequest();
        if (false === $this->isEnabled()) {
            return;
        }

        $controller = $event->getController();

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

        foreach ($metadata->param_converter_bag as $param_converter) {
            $class = $param_converter->class;
            $bag = $param_converter->id_source;
            $unique_identifier = $request->$bag->get($param_converter->id_name, null);
            $entity = null;
            try {
                if (null === $unique_identifier) {
                    throw new \InvalidArgumentException(
                        'Unable to find identifier with provided attribute: '.$param_converter->id_name
                    );
                }
            } catch (\InvalidArgumentException $e) {
                if (true === $param_converter->required) {
                    throw $e;
                }
            }

            if (null !== $unique_identifier) {
                $entity = $event->getKernel()->getApplication()->getEntityManager()->find($class, $unique_identifier);
                if (null === $entity) {
                    throw new NotFoundHttpException("No `$class` exists with uid `$unique_identifier`.");
                }
            }

            $request->attributes->set($param_converter->name, $entity);
        }
    }
1230582
public function onKernelController(FilterControllerEvent $event) {
        $css = rtrim($this->cssBase, '/') . '/' . trim($this->lteAdmin, '/');
        $mng = $this->manager;

        $mng->registerStyle('jquery-ui', $css . '/jQueryUI/jquery-ui-1.10.3.custom.css');
        $mng->registerStyle('bootstrap', $css . '/bootstrap.css', ['jquery-ui']);
        $mng->registerStyle('bootstrap-slider', $css . '/bootstrap-slider/slider.css', ['bootstrap']);
        $mng->registerStyle('datatables', $css . '/datatables/dataTables.bootstrap.css', ['bootstrap']);
        $mng->registerStyle('fontawesome', $css . '/font-awesome.css');
        $mng->registerStyle('ionicons', $css . '/ionicons.css');
        $mng->registerStyle('admin-lte', $css . '/AdminLTE.css', ['bootstrap-slider', 'fontawesome', 'ionicons', 'datatables']);
        $mng->registerStyle('bs-colorpicker', $css . '/colorpicker/bootstrap-colorpicker.css', ['admin-lte']);
        $mng->registerStyle('daterangepicker', $css . '/daterangepicker/daterangepicker.css', ['admin-lte']);
        $mng->registerStyle('timepicker', $css . '/timepicker/bootstrap-timepicker.css', ['admin-lte']);
        $mng->registerStyle('wysiwyg', $css . '/bootstrap-wysihtml5/bootstrap3-wysihtml5.css', ['admin-lte']);
    }
747638
public function onResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $debug = $request->query->get('debug');
        $response = $event->getResponse();

        //this is for debug purpose
        if ($response instanceof JsonResponse && $debug) {
            $new = new Response();
            $new->setContent('<body>'.$response->getContent().'</body>');
            $event->setResponse($new);
        }
    }
1311225
public function onResponse(FilterResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $response = $event->getResponse();
        if (!$response->isRedirect() || !$response instanceof RedirectResponse) {
            return;
        }

        $this->handleNoBackendAccess($response);
        $this->handleLoginRetreat($request, $response);
    }