Core controller handler.

@param FilterControllerEvent $event

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

        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
            return;
        }

        $controller = $event->getController();

        if (is_callable($controller) && method_exists($controller, '__invoke')) {
            $controller = [$controller, '__invoke'];
        }

        $this->paramFetcher->setController($controller);
        $attributeName = $this->getAttributeName($controller);
        $request->attributes->set($attributeName, $this->paramFetcher);

        if ($this->setParamsAsAttributes) {
            $params = $this->paramFetcher->all();
            foreach ($params as $name => $param) {
                if ($request->attributes->has($name) && null !== $request->attributes->get($name)) {
                    $msg = sprintf("ParamFetcher parameter conflicts with a path parameter '$name' for route '%s'", $request->attributes->get('_route'));

                    throw new \InvalidArgumentException($msg);
                }

                $request->attributes->set($name, $param);
            }
        }
    }
594529
public function onKernelResponse(FilterResponseEvent $event)
    {
        $event->getResponse()->headers->set(self::HEADER_NAME, $this->requestId->get());
    }
646193
public function isValidListener(FilterControllerEvent $event)
    {
        $controller = $event->getController();
        if (!is_array($controller)) {
            return false;
        }

        $controller = $controller[0];
        if (!$controller instanceof ConfigurationAwareInterface) {
            return false;
        }

        $this->controller = $controller;

        return true;
    }
405779
public function onKernelController(FilterControllerEvent $event)
    {
        /**
         * Data load.
         */
        $controller = $event->getController();

        /**
         * If is not a valid controller structure, return.
         */
        if (!is_array($controller)) {
            return;
        }

        $request = $event->getRequest();
        $method = new ReflectionMethod($controller[0], $controller[1]);

        /**
         * Given specific configuration, analyze full request.
         */
        $this->analyzeRequest($request, $this->reader, $method);
    }
473547
public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();
        if ($response) {
            $date = $response->getDate();
            if (empty($date)) {
                $response->setDate(new \DateTime());
            }
        }
    }
1159115
public function onKernelResponse(FilterResponseEvent $event)
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
            return;
        }

        $this->turbolinks->decorateResponse($event->getRequest(), $event->getResponse());
    }
1369596
public function onView(GetResponseForControllerResultEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $value = $event->getControllerResult();
        if (!$value instanceof AbstractValue) {
            return;
        }

        $context = [];
        if ($request->query->get('html') === 'false') {
            $context['disable_html'] = true;
        }

        $response = new JsonResponse(null, $value->getStatusCode());
        $response->setContent(
            $this->serializer->serialize($value, 'json', $context)
        );

        $event->setResponse($response);
    }
393619
public function onKernelResponse(FilterResponseEvent $event)
    {
        /**
         * Only flushes if exists AnnotationFlush as a controller annotations.
         */
        if ($this->mustFlush) {

            /**
             * Flushing manager.
             */
            $this
                ->manager
                ->flush($this->entities);
        }
    }
731000
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $event->getRequest();
        $route   = $this->routes->get($request->attributes->get('_route'));

        if ($route && $route->hasContent()) {
            $this->populateContent($route, $request);
        }
    }
841942
public function onCoreController(FilterControllerEvent $event)
    {
        if (!is_array($controller = $event->getController())) {
            return;
        }

        $class  = new \ReflectionClass($controller[0]);
        $method = $class->getMethod($controller[1]);

        if ($classAnnotations = $this->reader->getClassAnnotations($class)) {
            foreach ($classAnnotations as $classAnnotation) {
                if ($classAnnotation instanceof Firewall) {
                    if (is_array($classAnnotation->actions) && in_array($method->name, $classAnnotation->actions)) {
                        $this->loadFirewall($classAnnotation);
                    } elseif ($classAnnotation->actions === null) {
                        $this->loadFirewall($classAnnotation);
                    }
                }
            }
        }

        if ($methodAnnotation = $this->reader->getMethodAnnotation($method, 'M6Web\Bundle\FirewallBundle\Annotation\Firewall')) {
            $this->loadFirewall($methodAnnotation);
        }
    }
898829
public function beforeFilter(Event $event)
    {
        $this->_controller->set('__commentComponentLoaded__', true);
        $this->_controller->set('_commentFormContext', $this->config('arrayContext'));
    }
212986
public function onKernelController(FilterControllerEvent $event)
    {
        $controller = $event->getController();

        /*
         * $controller passed can be either a class or a Closure.
         * This is not usual in Symfony but it may happen.
         * If it is a class, it comes in array format
         */
        if (!is_array($controller)) {
            return;
        }
        $fqcn = get_class($controller[0]);
        $isMediaManagerBundleController = $this->startsWith($fqcn, 'Phlexible\Bundle\MediaManagerBundle\Controller');
        if ($isMediaManagerBundleController && !$this->checkDefaultVolumeExists()) {
            throw new \Exception('No default volume found. Maybe you haven\'t initialized the MediaManager yet?');
        }
    }
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');
    }
639645
public function getFilter(GetFilterEvent $event): void
    {
        $filter = $this->buildSharingFilter($event);
        $filter = $this->buildOwnerFilter($event, $filter);

        $event->setFilterConstraint($filter);
    }
1055786
private function registerControllerFilters($controller, $controllerService, $filters)
    {
        foreach ($filters as $filter) {
            if ($filter instanceof Before) {
                foreach ($filter->methods as $method) {
                    $this->registerFilter($method, 'before', $controller, $controllerService);
                }
            }

            if ($filter instanceof After) {
                foreach ($filter->methods as $method) {
                    $this->registerFilter($method, 'after', $controller, $controllerService);
                }
            }
        }
    }
96808
public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();

        if ($response instanceof SerializedResponse) {
            $acceptableContentTypes = $event->getRequest()->getAcceptableContentTypes();

            $format = 'json';

            foreach ($acceptableContentTypes as $item) {
                if (strpos($item, 'xml') !== false) {
                    $format = 'xml';
                    break;
                }
            }

            $serializedData = $this->serializer->serialize($response->getData(), $format, null);

            $response->setContent($serializedData);
        }
    }
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));
        }
    }