vendor/pimcore/pimcore/lib/Http/RequestMatcherFactory.php line 54

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Http;
  16. use Symfony\Component\HttpFoundation\RequestMatcher\AttributesRequestMatcher;
  17. use Symfony\Component\HttpFoundation\RequestMatcher\HostRequestMatcher;
  18. use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
  19. use Symfony\Component\HttpFoundation\RequestMatcher\PathRequestMatcher;
  20. /**
  21.  * @internal
  22.  */
  23. class RequestMatcherFactory
  24. {
  25.     /**
  26.      * Builds a set of request matchers from a config definition as configured in pimcore.admin.routes (see PimcoreCoreBundle
  27.      * configuration).
  28.      *
  29.      */
  30.     public function buildRequestMatchers(array $entries): array
  31.     {
  32.         $matchers = [];
  33.         foreach ($entries as $entry) {
  34.             $matchers[] = $this->buildRequestMatcher($entry);
  35.         }
  36.         return $matchers;
  37.     }
  38.     /**
  39.      * Builds a request matchers from a route configuration
  40.      *
  41.      */
  42.     public function buildRequestMatcher(array $entry): array
  43.     {
  44.         // TODO add support for IPs, attributes and schemes if necessary
  45.         $matchers = [];
  46.         if (isset($entry['path']) && $entry['path']) {
  47.             $matchers[] = new PathRequestMatcher($entry['path']);
  48.         }
  49.         if (isset($entry['host']) && $entry['host']) {
  50.             $matchers[] = new HostRequestMatcher($entry['host']);
  51.         }
  52.         if (isset($entry['methods']) && $entry['methods']) {
  53.             $matchers[] = new MethodRequestMatcher($entry['methods']);
  54.         }
  55.         if (isset($entry['route']) && $entry['route']) {
  56.             $matchers[] = new AttributesRequestMatcher(['_route' => $entry['route']]);
  57.         }
  58.         return $matchers;
  59.     }
  60. }