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

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 Enterprise License (PEL)
  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 PEL
  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\GetResponseEvent;
  20. use Symfony\Component\HttpKernel\KernelEvents;
  21. class GoogleSearchConsoleVerificationListener implements EventSubscriberInterface
  22. {
  23.     use PimcoreContextAwareTrait;
  24.     public static function getSubscribedEvents()
  25.     {
  26.         return [
  27.             KernelEvents::REQUEST => ['onKernelRequest'64]
  28.         ];
  29.     }
  30.     /**
  31.      * @param GetResponseEvent $event
  32.      */
  33.     public function onKernelRequest(GetResponseEvent $event)
  34.     {
  35.         $request $event->getRequest();
  36.         if (!$event->isMasterRequest()) {
  37.             return;
  38.         }
  39.         if (!$this->matchesPimcoreContext($requestPimcoreContextResolver::CONTEXT_DEFAULT)) {
  40.             return;
  41.         }
  42.         $conf = \Pimcore\Config::getReportConfig();
  43.         if (!is_null($conf->get('webmastertools')) && isset($conf->get('webmastertools')->sites)) {
  44.             $sites $conf->get('webmastertools')->sites->toArray();
  45.             if (is_array($sites)) {
  46.                 foreach ($sites as $site) {
  47.                     if ($site['verification'] && $request->getPathInfo() === '/' $site['verification']) {
  48.                         $response = new Response('google-site-verification: ' $site['verification']);
  49.                         $event->setResponse($response);
  50.                         break;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }