vendor/pimcore/pimcore/bundles/CoreBundle/EventListener/Frontend/GoogleSearchConsoleVerificationListener.php line 42

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\CoreBundle\EventListener\Frontend;
  15. use Pimcore\Bundle\CoreBundle\EventListener\Traits\PimcoreContextAwareTrait;
  16. use Pimcore\Http\Request\Resolver\PimcoreContextResolver;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\HttpKernel\Event\RequestEvent;
  20. use Symfony\Component\HttpKernel\KernelEvents;
  21. /**
  22.  * @internal
  23.  */
  24. class GoogleSearchConsoleVerificationListener implements EventSubscriberInterface
  25. {
  26.     use PimcoreContextAwareTrait;
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             KernelEvents::REQUEST => ['onKernelRequest'64],
  31.         ];
  32.     }
  33.     /**
  34.      * @param RequestEvent $event
  35.      */
  36.     public function onKernelRequest(RequestEvent $event)
  37.     {
  38.         $request $event->getRequest();
  39.         if (!$event->isMainRequest()) {
  40.             return;
  41.         }
  42.         if (!$this->matchesPimcoreContext($requestPimcoreContextResolver::CONTEXT_DEFAULT)) {
  43.             return;
  44.         }
  45.         $conf \Pimcore\Config::getReportConfig();
  46.         if (!is_null($conf->get('webmastertools')) && isset($conf->get('webmastertools')->sites)) {
  47.             $sites $conf->get('webmastertools')->sites->toArray();
  48.             if (is_array($sites)) {
  49.                 foreach ($sites as $site) {
  50.                     if ($site['verification'] && $request->getPathInfo() === '/' $site['verification']) {
  51.                         $response = new Response('google-site-verification: ' $site['verification']);
  52.                         $event->setResponse($response);
  53.                         break;
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }