Handles Notifications sent from AWS SNS

@param GetResponseEvent $event The Kernel Request's GetResponseEvent
@return string
498627
private function handleSnsNotifications(GetResponseEvent $event) {
		$notification = json_decode((string) $event->getRequest()->getContent(), true);

		$type = $event->getRequest()->headers->get('x-amz-sns-message-type');

		$metadata = [
			'Type'      => $notification['Type'],
			'TopicArn'  => $notification['TopicArn'],
			'Timestamp' => $notification['Timestamp'],
		];

		if ($type === 'Notification') {

			// We put the queue name in the Subject field
			$queue               = $notification['Subject'];
			$metadata['Subject'] = $queue;

			$notification = new Notification(
				$notification['MessageId'],
				$notification['Message'],
				$metadata
			);

			$this->dispatcher->dispatch(
				Events::Notification($queue),
				new NotificationEvent($queue, NotificationEvent::TYPE_MESSAGE, $notification)
			);

			return "SNS Message Notification Received.";
		}

		// For subscription notifications, we need to parse the Queue from
		// the Topic ARN
		$arnParts = explode(':', $notification['TopicArn']);
		$last     = end($arnParts);
		$queue    = str_replace('qpush_', '', $last);

		// Get the token for the Subscription Confirmation
		$metadata['Token'] = $notification['Token'];

		$notification = new Notification(
			$notification['MessageId'],
			$notification['Message'],
			$metadata
		);

		$this->dispatcher->dispatch(
			Events::Notification($queue),
			new NotificationEvent($queue, NotificationEvent::TYPE_SUBSCRIPTION, $notification)
		);

		return "SNS Subscription Confirmation Received.";
	}
38274
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            // don't do anything if it's not the master request
            return;
        }

        $request = $event->getRequest();

        $requestUri = $request->getRequestUri();

        $requestUriNew = preg_replace('/-{2,}/', '-', $requestUri);

        if ($requestUri !== $requestUriNew) {
            $event->setResponse(new RedirectResponse($requestUriNew, 301));
            $event->stopPropagation();
        }
    }
721284
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->isMasterRequest() && $this->getParameter('nyroDev_utility.setLocale')) {
            $locale = $event->getRequest()->getLocale();

            if (0 === strpos($locale, 'change_')) {
                $tmp = explode('change_', $locale);
                $locale = $tmp[1];
                // Update already instanciated objects
                $event->getRequest()->setLocale($locale);
                $this->get('translator')->setLocale($locale);
            }

            if (!defined('NYRO_LOCALE')) {
                define('NYRO_LOCALE', $locale);
            }

            $locales = [
                $locale,
                $locale.'@euro',
                $locale.'.utf8',
            ];
            if (2 == strlen($locale)) {
                $locUp = strtoupper($locale);
                $locale .= '_'.('ZH' == $locUp ? 'CN' : $locUp);
                $locales[] = $locale;
                $locales[] = $locale.'@euro';
                $locales[] = $locale.'.utf8';
            }
            foreach (array_reverse($locales) as $loc) {
                $tmp = setlocale(LC_ALL, $loc);
                if (mb_strtolower($tmp) == mb_strtolower($loc)) {
                    break;
                }
            }
        }
    }
810688
public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $application = $event->getKernel()->getApplication();

        if (null !== $application && false === $request->hasSession()) {
            $container = $application->getContainer();
            $event->getRequest()->setSession($container->get('bb_session'));
        }

        parent::handle($event);
    }
161034
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        foreach ($this->requestMatchers as $requestMatcher) {
            if ($requestMatcher->matches($request)) {
                $request->attributes->set(FOSRestBundle::ZONE_ATTRIBUTE, true);

                return;
            }
        }

        $request->attributes->set(FOSRestBundle::ZONE_ATTRIBUTE, false);
    }
242439
public function handleRequest(GetResponseEvent $event)
    {
        if (!($tagcacheConfig = $this->getTagcacheConfig($event->getRequest()))) {
            return;
        }

        if (is_array($cacheContent = $this->tagcache->get($tagcacheConfig->getKey()))) {
            if ($cacheContent['Expires'] - (time() - $cacheContent['CreatedAt']) < 0) {
                return;
            }
            $response = new TagcacheResponse($this->renderCacheContent($cacheContent));
            $response->headers->add($cacheContent['Headers']);
            $event->setResponse($response);
        }
    }
768940
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (
            'html' !== $request->getRequestFormat('') ||
            !($request->attributes->has('_api_resource_class') || $request->attributes->getBoolean('_api_respond', false))
        ) {
            return;
        }

        $request->attributes->set('_controller', 'api_platform.swagger.action.ui');
    }
1322387
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }
        $request = $event->getRequest();

        if ($request::getTrustedProxies()) {
            $request->getClientIps();
        }

        $request->getHost();
    }
652940
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        $this->client->setFallbackType('HTTP');

        $this->resolver->set($event->getRequest());
    }
872038
public function getNotificationsSms($event)
    {
        $notificationEmailRepository = $this->getContainer()->get('doctrine')->getRepository(
            'CompoNotificationBundle:NotificationSms'
        );

        return $notificationEmailRepository->findBy(['event' => $event]);
    }
984399
public function send(SendResponseEvent $event)
    {


        // Console //

        if ($this->response instanceof ConsoleResponse) {
            $templateContent = $this->getTemplateContent('console');
            // inject details
            $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
            $this->response->setContent($templateContent);
            $this->response->setErrorLevel(1);

            return $this->sendResponse($this->response);
        }


        // HTTP //

        $this->response->setStatusCode(500);

        $requestHeaders = $this->request->getHeaders();
        if ($requestHeaders->has('accept')) {

            $accept = $requestHeaders->get('Accept');
            $responseHeaders = $this->response->getHeaders();
            $responseHeaders->clearHeaders();

            if ($accept->match('text/html') !== false) { // html

                // get template content
                $templateContent = $this->getTemplateContent($event->getParam('type'));
                // inject details
                $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
                $contentType = 'text/html; charset=utf-8';
                $responseHeaders->addHeaderLine('content-type', $contentType);
                $this->response->setContent($templateContent);

            } else if ($accept->match('application/json') !== false
                || $accept->match('application/hal+json') !== false) { // json

                // return api problem structured json
                $contentType = 'application/problem+json; charset=utf-8';
                $responseHeaders->addHeaderLine('content-type', $contentType);
                // get template
                $templateContent = $this->getTemplateContent('json');
                // inject details
                $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
                $this->response->setContent($templateContent);

            }
        }

        $this->sendResponse($this->response);

    }
45777
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

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

        if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
            foreach ($this->mimeTypes as $format => $mimeTypes) {
                if (method_exists(Request::class, 'getMimeTypes')) {
                    $mimeTypes = array_merge($mimeTypes, Request::getMimeTypes($format));
                } elseif (null !== $request->getMimeType($format)) {
                    $class = new \ReflectionClass(Request::class);
                    $properties = $class->getStaticProperties();
                    if (isset($properties['formats'][$format])) {
                        $mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
                    }
                }

                $request->setFormat($format, $mimeTypes);
            }
        }
    }
347803
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->getRequest()->attributes->get('is_rest_request')) {
            return;
        }

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

        // skip CSRF validation if no session is running
        if (!$event->getRequest()->getSession()->isStarted()) {
            return;
        }

        if ($this->isMethodSafe($event->getRequest()->getMethod())) {
            return;
        }

        if ($this->isSessionRoute($event->getRequest()->get('_route'))) {
            return;
        }

        if (!$this->checkCsrfToken($event->getRequest())) {
            throw new UnauthorizedException(
                'Missing or invalid CSRF token',
                $event->getRequest()->getMethod() . ' ' . $event->getRequest()->getPathInfo()
            );
        }

        // Dispatching event so that CSRF token intention can be injected into Legacy Stack
        $this->eventDispatcher->dispatch(RestEvents::REST_CSRF_TOKEN_VALIDATED);
    }
827225
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (
            !($attributes = RequestAttributesExtractor::extractAttributes($request))
            || !$attributes['receive']
        ) {
            return;
        }

        if (null === $filters = $request->attributes->get('_api_filters')) {
            $queryString = RequestParser::getQueryString($request);
            $filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
        }

        $context = null === $filters ? [] : ['filters' => $filters];
        if ($this->serializerContextBuilder) {
            // Builtin data providers are able to use the serialization context to automatically add join clauses
            $context += $normalizationContext = $this->serializerContextBuilder->createFromRequest($request, true, $attributes);
            $request->attributes->set('_api_normalization_context', $normalizationContext);
        }

        if (isset($attributes['collection_operation_name'])) {
            $request->attributes->set('data', $request->isMethod('POST') ? null : $this->getCollectionData($attributes, $context));

            return;
        }

        $data = [];

        if ($this->identifierConverter) {
            $context[IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER] = true;
        }

        try {
            $identifiers = $this->extractIdentifiers($request->attributes->all(), $attributes);

            if (isset($attributes['item_operation_name'])) {
                $data = $this->getItemData($identifiers, $attributes, $context);
            } elseif (isset($attributes['subresource_operation_name'])) {
                // Legacy
                if (null === $this->subresourceDataProvider) {
                    throw new RuntimeException('No subresource data provider.');
                }

                $data = $this->getSubresourceData($identifiers, $attributes, $context);
            }
        } catch (InvalidIdentifierException $e) {
            throw new NotFoundHttpException('Not found, because of an invalid identifier configuration', $e);
        }

        if (null === $data) {
            throw new NotFoundHttpException('Not Found');
        }

        $request->attributes->set('data', $data);
    }
372494
public function handle(GetResponseEvent $event)
    {
        if (null !== $this->logger) {
            $this->logger->info('Checking for guard authentication credentials.', array('firewall_key' => $this->providerKey, 'authenticators' => count($this->guardAuthenticators)));
        }

        foreach ($this->guardAuthenticators as $key => $guardAuthenticator) {
            // get a key that's unique to *this* guard authenticator
            // this MUST be the same as GuardAuthenticationProvider
            $uniqueGuardKey = $this->providerKey.'_'.$key;

            $this->executeGuardAuthenticator($uniqueGuardKey, $guardAuthenticator, $event);
        }
    }
1371114
private function handleIronMqNotifications(GetResponseEvent $event) {
		$headers   = $event->getRequest()->headers;
		$messageId = $headers->get('iron-message-id');

		if (null === ($message = json_decode($event->getRequest()->getContent(), true))) {
			throw new \InvalidArgumentException('Unable to decode JSON');
		}

		$queue    = $this->getIronMqQueueName($event, $message);
		$metadata = [
			'iron-subscriber-message-id'  => $headers->get('iron-subscriber-message-id'),
			'iron-subscriber-message-url' => $headers->get('iron-subscriber-message-url')
		];

		unset($message['_qpush_queue']);

		$notification = new Notification(
			$messageId,
			$message,
			$metadata
		);

		$this->dispatcher->dispatch(
			Events::Notification($queue),
			new NotificationEvent($queue, NotificationEvent::TYPE_MESSAGE, $notification)
		);

		return "IronMQ Notification Received.";
	}
693559
public function onKernelRequest(GetResponseEvent $event)
    {
        // Nothing to do here, if it's not the Master request.
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $route = $request->get('_route');

        // Only do these 'expensive' checks on a select few backend pages.
        if (!in_array($route, ['dashboard', 'login', 'userfirst'])) {
            return;
        }

        $this->logThreshold = $this->app['config']->get('general/configuration_notices/log_threshold', 10000);

        $this->app['stopwatch']->start('bolt.configuration_notices');

        $this->singleHostnameCheck($request);
        $this->ipAddressCheck($request);
        $this->topLevelCheck($request);
        $this->writableFolderCheck();

        // Do these only when logged in, on the dashboard
        if ($route === 'dashboard') {
            $this->mailConfigCheck();
            $this->developmentCheck();
            $this->liveCheck($request);
            $this->gdCheck();
            $this->thumbsFolderCheck();
            $this->canonicalCheck($request);
            $this->imageFunctionsCheck();
            $this->maintenanceCheck();
            $this->thumbnailConfigCheck();
            $this->changelogCheck();
            $this->systemlogCheck();
        }

        $this->app['stopwatch']->stop('bolt.configuration_notices');
    }