vendor/contao/core-bundle/src/EventListener/InsecureInstallationListener.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\EventListener;
  11. use Contao\CoreBundle\Exception\InsecureInstallationException;
  12. use Symfony\Component\HttpKernel\Event\RequestEvent;
  13. /**
  14.  * @internal
  15.  */
  16. class InsecureInstallationListener
  17. {
  18.     /**
  19.      * Throws an exception if the document root is insecure.
  20.      *
  21.      * @throws InsecureInstallationException
  22.      */
  23.     public function __invoke(RequestEvent $event): void
  24.     {
  25.         $request $event->getRequest();
  26.         // Skip the check on localhost
  27.         if (\in_array($request->getClientIp(), ['127.0.0.1''fe80::1''::1'], true)) {
  28.             return;
  29.         }
  30.         // The document root is not in a subdirectory
  31.         if ('' === $request->getBasePath()) {
  32.             return;
  33.         }
  34.         throw new InsecureInstallationException('Your installation is not secure. Please set the document root to the /public subfolder.');
  35.     }
  36. }