Initial Drupal 11 with DDEV setup
This commit is contained in:
		
							
								
								
									
										57
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/AddTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/AddTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,57 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the Symfony package.
 | 
			
		||||
 *
 | 
			
		||||
 * (c) Fabien Potencier <fabien@symfony.com>
 | 
			
		||||
 *
 | 
			
		||||
 * For the full copyright and license information, please view the LICENSE
 | 
			
		||||
 * file that was distributed with this source code.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Symfony\Component\Routing\Loader\Configurator\Traits;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Routing\Loader\Configurator\AliasConfigurator;
 | 
			
		||||
use Symfony\Component\Routing\Loader\Configurator\CollectionConfigurator;
 | 
			
		||||
use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator;
 | 
			
		||||
use Symfony\Component\Routing\RouteCollection;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Nicolas Grekas <p@tchwork.com>
 | 
			
		||||
 */
 | 
			
		||||
trait AddTrait
 | 
			
		||||
{
 | 
			
		||||
    use LocalizedRouteTrait;
 | 
			
		||||
 | 
			
		||||
    protected RouteCollection $collection;
 | 
			
		||||
    protected string $name = '';
 | 
			
		||||
    protected ?array $prefixes = null;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds a route.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string|array $path the path, or the localized paths of the route
 | 
			
		||||
     */
 | 
			
		||||
    public function add(string $name, string|array $path): RouteConfigurator
 | 
			
		||||
    {
 | 
			
		||||
        $parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null);
 | 
			
		||||
        $route = $this->createLocalizedRoute($this->collection, $name, $path, $this->name, $this->prefixes);
 | 
			
		||||
 | 
			
		||||
        return new RouteConfigurator($this->collection, $route, $this->name, $parentConfigurator, $this->prefixes);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function alias(string $name, string $alias): AliasConfigurator
 | 
			
		||||
    {
 | 
			
		||||
        return new AliasConfigurator($this->collection->addAlias($name, $alias));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds a route.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string|array $path the path, or the localized paths of the route
 | 
			
		||||
     */
 | 
			
		||||
    public function __invoke(string $name, string|array $path): RouteConfigurator
 | 
			
		||||
    {
 | 
			
		||||
        return $this->add($name, $path);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										50
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/HostTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/HostTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the Symfony package.
 | 
			
		||||
 *
 | 
			
		||||
 * (c) Fabien Potencier <fabien@symfony.com>
 | 
			
		||||
 *
 | 
			
		||||
 * For the full copyright and license information, please view the LICENSE
 | 
			
		||||
 * file that was distributed with this source code.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Symfony\Component\Routing\Loader\Configurator\Traits;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Routing\RouteCollection;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @internal
 | 
			
		||||
 */
 | 
			
		||||
trait HostTrait
 | 
			
		||||
{
 | 
			
		||||
    final protected function addHost(RouteCollection $routes, string|array $hosts): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!$hosts || !\is_array($hosts)) {
 | 
			
		||||
            $routes->setHost($hosts ?: '');
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        foreach ($routes->all() as $name => $route) {
 | 
			
		||||
            if (null === $locale = $route->getDefault('_locale')) {
 | 
			
		||||
                $priority = $routes->getPriority($name) ?? 0;
 | 
			
		||||
                $routes->remove($name);
 | 
			
		||||
                foreach ($hosts as $locale => $host) {
 | 
			
		||||
                    $localizedRoute = clone $route;
 | 
			
		||||
                    $localizedRoute->setDefault('_locale', $locale);
 | 
			
		||||
                    $localizedRoute->setRequirement('_locale', preg_quote($locale));
 | 
			
		||||
                    $localizedRoute->setDefault('_canonical_route', $name);
 | 
			
		||||
                    $localizedRoute->setHost($host);
 | 
			
		||||
                    $routes->add($name.'.'.$locale, $localizedRoute, $priority);
 | 
			
		||||
                }
 | 
			
		||||
            } elseif (!isset($hosts[$locale])) {
 | 
			
		||||
                throw new \InvalidArgumentException(\sprintf('Route "%s" with locale "%s" is missing a corresponding host in its parent collection.', $name, $locale));
 | 
			
		||||
            } else {
 | 
			
		||||
                $route->setHost($hosts[$locale]);
 | 
			
		||||
                $route->setRequirement('_locale', preg_quote($locale));
 | 
			
		||||
                $routes->add($name, $route, $routes->getPriority($name) ?? 0);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										76
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/LocalizedRouteTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/LocalizedRouteTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,76 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the Symfony package.
 | 
			
		||||
 *
 | 
			
		||||
 * (c) Fabien Potencier <fabien@symfony.com>
 | 
			
		||||
 *
 | 
			
		||||
 * For the full copyright and license information, please view the LICENSE
 | 
			
		||||
 * file that was distributed with this source code.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Symfony\Component\Routing\Loader\Configurator\Traits;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Routing\Route;
 | 
			
		||||
use Symfony\Component\Routing\RouteCollection;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @internal
 | 
			
		||||
 *
 | 
			
		||||
 * @author Nicolas Grekas <p@tchwork.com>
 | 
			
		||||
 * @author Jules Pietri <jules@heahprod.com>
 | 
			
		||||
 */
 | 
			
		||||
trait LocalizedRouteTrait
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates one or many routes.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string|array $path the path, or the localized paths of the route
 | 
			
		||||
     */
 | 
			
		||||
    final protected function createLocalizedRoute(RouteCollection $collection, string $name, string|array $path, string $namePrefix = '', ?array $prefixes = null): RouteCollection
 | 
			
		||||
    {
 | 
			
		||||
        $paths = [];
 | 
			
		||||
 | 
			
		||||
        $routes = new RouteCollection();
 | 
			
		||||
 | 
			
		||||
        if (\is_array($path)) {
 | 
			
		||||
            if (null === $prefixes) {
 | 
			
		||||
                $paths = $path;
 | 
			
		||||
            } elseif ($missing = array_diff_key($prefixes, $path)) {
 | 
			
		||||
                throw new \LogicException(\sprintf('Route "%s" is missing routes for locale(s) "%s".', $name, implode('", "', array_keys($missing))));
 | 
			
		||||
            } else {
 | 
			
		||||
                foreach ($path as $locale => $localePath) {
 | 
			
		||||
                    if (!isset($prefixes[$locale])) {
 | 
			
		||||
                        throw new \LogicException(\sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    $paths[$locale] = $prefixes[$locale].$localePath;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } elseif (null !== $prefixes) {
 | 
			
		||||
            foreach ($prefixes as $locale => $prefix) {
 | 
			
		||||
                $paths[$locale] = $prefix.$path;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $routes->add($namePrefix.$name, $route = $this->createRoute($path));
 | 
			
		||||
            $collection->add($namePrefix.$name, $route);
 | 
			
		||||
 | 
			
		||||
            return $routes;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        foreach ($paths as $locale => $path) {
 | 
			
		||||
            $routes->add($name.'.'.$locale, $route = $this->createRoute($path));
 | 
			
		||||
            $collection->add($namePrefix.$name.'.'.$locale, $route);
 | 
			
		||||
            $route->setDefault('_locale', $locale);
 | 
			
		||||
            $route->setRequirement('_locale', preg_quote($locale));
 | 
			
		||||
            $route->setDefault('_canonical_route', $namePrefix.$name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $routes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function createRoute(string $path): Route
 | 
			
		||||
    {
 | 
			
		||||
        return new Route($path);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										63
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/PrefixTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/PrefixTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,63 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the Symfony package.
 | 
			
		||||
 *
 | 
			
		||||
 * (c) Fabien Potencier <fabien@symfony.com>
 | 
			
		||||
 *
 | 
			
		||||
 * For the full copyright and license information, please view the LICENSE
 | 
			
		||||
 * file that was distributed with this source code.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Symfony\Component\Routing\Loader\Configurator\Traits;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Routing\Route;
 | 
			
		||||
use Symfony\Component\Routing\RouteCollection;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @internal
 | 
			
		||||
 *
 | 
			
		||||
 * @author Nicolas Grekas <p@tchwork.com>
 | 
			
		||||
 */
 | 
			
		||||
trait PrefixTrait
 | 
			
		||||
{
 | 
			
		||||
    final protected function addPrefix(RouteCollection $routes, string|array $prefix, bool $trailingSlashOnRoot): void
 | 
			
		||||
    {
 | 
			
		||||
        if (\is_array($prefix)) {
 | 
			
		||||
            foreach ($prefix as $locale => $localePrefix) {
 | 
			
		||||
                $prefix[$locale] = trim(trim($localePrefix), '/');
 | 
			
		||||
            }
 | 
			
		||||
            foreach ($routes->all() as $name => $route) {
 | 
			
		||||
                if (null === $locale = $route->getDefault('_locale')) {
 | 
			
		||||
                    $priority = $routes->getPriority($name) ?? 0;
 | 
			
		||||
                    $routes->remove($name);
 | 
			
		||||
                    foreach ($prefix as $locale => $localePrefix) {
 | 
			
		||||
                        $localizedRoute = clone $route;
 | 
			
		||||
                        $localizedRoute->setDefault('_locale', $locale);
 | 
			
		||||
                        $localizedRoute->setRequirement('_locale', preg_quote($locale));
 | 
			
		||||
                        $localizedRoute->setDefault('_canonical_route', $name);
 | 
			
		||||
                        $localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
 | 
			
		||||
                        $routes->add($name.'.'.$locale, $localizedRoute, $priority);
 | 
			
		||||
                    }
 | 
			
		||||
                } elseif (!isset($prefix[$locale])) {
 | 
			
		||||
                    throw new \InvalidArgumentException(\sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale));
 | 
			
		||||
                } else {
 | 
			
		||||
                    $route->setPath($prefix[$locale].(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
 | 
			
		||||
                    $routes->add($name, $route, $routes->getPriority($name) ?? 0);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $routes->addPrefix($prefix);
 | 
			
		||||
        if (!$trailingSlashOnRoot) {
 | 
			
		||||
            $rootPath = (new Route(trim(trim($prefix), '/').'/'))->getPath();
 | 
			
		||||
            foreach ($routes->all() as $route) {
 | 
			
		||||
                if ($route->getPath() === $rootPath) {
 | 
			
		||||
                    $route->setPath(rtrim($rootPath, '/'));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										172
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/RouteTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										172
									
								
								vendor/symfony/routing/Loader/Configurator/Traits/RouteTrait.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,172 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the Symfony package.
 | 
			
		||||
 *
 | 
			
		||||
 * (c) Fabien Potencier <fabien@symfony.com>
 | 
			
		||||
 *
 | 
			
		||||
 * For the full copyright and license information, please view the LICENSE
 | 
			
		||||
 * file that was distributed with this source code.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Symfony\Component\Routing\Loader\Configurator\Traits;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Routing\Route;
 | 
			
		||||
use Symfony\Component\Routing\RouteCollection;
 | 
			
		||||
 | 
			
		||||
trait RouteTrait
 | 
			
		||||
{
 | 
			
		||||
    protected RouteCollection|Route $route;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds defaults.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function defaults(array $defaults): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addDefaults($defaults);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds requirements.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function requirements(array $requirements): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addRequirements($requirements);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds options.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function options(array $options): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addOptions($options);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Whether paths should accept utf8 encoding.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function utf8(bool $utf8 = true): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addOptions(['utf8' => $utf8]);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the condition.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function condition(string $condition): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->setCondition($condition);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the pattern for the host.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function host(string $pattern): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->setHost($pattern);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the schemes (e.g. 'https') this route is restricted to.
 | 
			
		||||
     * So an empty array means that any scheme is allowed.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $schemes
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function schemes(array $schemes): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->setSchemes($schemes);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the HTTP methods (e.g. 'POST') this route is restricted to.
 | 
			
		||||
     * So an empty array means that any method is allowed.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $methods
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function methods(array $methods): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->setMethods($methods);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds the "_controller" entry to defaults.
 | 
			
		||||
     *
 | 
			
		||||
     * @param callable|string|array $controller a callable or parseable pseudo-callable
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function controller(callable|string|array $controller): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addDefaults(['_controller' => $controller]);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds the "_locale" entry to defaults.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function locale(string $locale): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addDefaults(['_locale' => $locale]);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds the "_format" entry to defaults.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function format(string $format): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addDefaults(['_format' => $format]);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds the "_stateless" entry to defaults.
 | 
			
		||||
     *
 | 
			
		||||
     * @return $this
 | 
			
		||||
     */
 | 
			
		||||
    final public function stateless(bool $stateless = true): static
 | 
			
		||||
    {
 | 
			
		||||
        $this->route->addDefaults(['_stateless' => $stateless]);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user