mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -94,7 +94,7 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
} elseif ($env instanceof \Stringable || \is_scalar($env)) {
|
||||
$this->env = (string) $env;
|
||||
} else {
|
||||
throw new \TypeError(__METHOD__.sprintf(': Parameter $env was expected to be a string or null, "%s" given.', get_debug_type($env)));
|
||||
throw new \TypeError(__METHOD__.\sprintf(': Parameter $env was expected to be a string or null, "%s" given.', get_debug_type($env)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,15 +111,15 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
/**
|
||||
* @throws \InvalidArgumentException When route can't be parsed
|
||||
*/
|
||||
public function load(mixed $class, string $type = null): RouteCollection
|
||||
public function load(mixed $class, ?string $type = null): RouteCollection
|
||||
{
|
||||
if (!class_exists($class)) {
|
||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||
throw new \InvalidArgumentException(\sprintf('Class "%s" does not exist.', $class));
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($class);
|
||||
if ($class->isAbstract()) {
|
||||
throw new \InvalidArgumentException(sprintf('Attributes from class "%s" cannot be read as it is abstract.', $class->getName()));
|
||||
throw new \InvalidArgumentException(\sprintf('Attributes from class "%s" cannot be read as it is abstract.', $class->getName()));
|
||||
}
|
||||
|
||||
$this->hasDeprecatedAnnotations = false;
|
||||
@@ -144,7 +144,7 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
|
||||
if (1 === $collection->count() - \count($routeNamesBefore)) {
|
||||
$newRouteName = current(array_diff(array_keys($collection->all()), $routeNamesBefore));
|
||||
if ($newRouteName !== $aliasName = sprintf('%s::%s', $class->name, $method->name)) {
|
||||
if ($newRouteName !== $aliasName = \sprintf('%s::%s', $class->name, $method->name)) {
|
||||
$collection->addAlias($aliasName, $newRouteName);
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
$collection->addAlias($class->name, $invokeRouteName);
|
||||
}
|
||||
|
||||
if ($invokeRouteName !== $aliasName = sprintf('%s::__invoke', $class->name)) {
|
||||
if ($invokeRouteName !== $aliasName = \sprintf('%s::__invoke', $class->name)) {
|
||||
$collection->addAlias($aliasName, $invokeRouteName);
|
||||
}
|
||||
}
|
||||
@@ -195,7 +195,7 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
|
||||
foreach ($requirements as $placeholder => $requirement) {
|
||||
if (\is_int($placeholder)) {
|
||||
throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder, $requirement, $name, $class->getName(), $method->getName()));
|
||||
throw new \InvalidArgumentException(\sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder, $requirement, $name, $class->getName(), $method->getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,11 +219,11 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
$paths[$locale] = $prefix.$localePath;
|
||||
}
|
||||
} elseif ($missing = array_diff_key($prefix, $path)) {
|
||||
throw new \LogicException(sprintf('Route to "%s" is missing paths for locale(s) "%s".', $class->name.'::'.$method->name, implode('", "', array_keys($missing))));
|
||||
throw new \LogicException(\sprintf('Route to "%s" is missing paths for locale(s) "%s".', $class->name.'::'.$method->name, implode('", "', array_keys($missing))));
|
||||
} else {
|
||||
foreach ($path as $locale => $localePath) {
|
||||
if (!isset($prefix[$locale])) {
|
||||
throw new \LogicException(sprintf('Route to "%s" with locale "%s" is missing a corresponding prefix in class "%s".', $method->name, $locale, $class->name));
|
||||
throw new \LogicException(\sprintf('Route to "%s" with locale "%s" is missing a corresponding prefix in class "%s".', $method->name, $locale, $class->name));
|
||||
}
|
||||
|
||||
$paths[$locale] = $prefix[$locale].$localePath;
|
||||
@@ -242,7 +242,7 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
continue;
|
||||
}
|
||||
foreach ($paths as $locale => $path) {
|
||||
if (preg_match(sprintf('/\{%s(?:<.*?>)?\}/', preg_quote($param->name)), $path)) {
|
||||
if (preg_match(\sprintf('/\{%s(?:<.*?>)?\}/', preg_quote($param->name)), $path)) {
|
||||
if (\is_scalar($defaultValue = $param->getDefaultValue()) || null === $defaultValue) {
|
||||
$defaults[$param->name] = $defaultValue;
|
||||
} elseif ($defaultValue instanceof \BackedEnum) {
|
||||
@@ -267,7 +267,7 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
if ('annotation' === $type) {
|
||||
trigger_deprecation('symfony/routing', '6.4', 'The "annotation" route type is deprecated, use the "attribute" route type instead.');
|
||||
@@ -360,7 +360,7 @@ abstract class AttributeClassLoader implements LoaderInterface
|
||||
|
||||
foreach ($globals['requirements'] as $placeholder => $requirement) {
|
||||
if (\is_int($placeholder)) {
|
||||
throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" in "%s"?', $placeholder, $requirement, $class->getName()));
|
||||
throw new \InvalidArgumentException(\sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" in "%s"?', $placeholder, $requirement, $class->getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class AttributeDirectoryLoader extends AttributeFileLoader
|
||||
/**
|
||||
* @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed
|
||||
*/
|
||||
public function load(mixed $path, string $type = null): ?RouteCollection
|
||||
public function load(mixed $path, ?string $type = null): ?RouteCollection
|
||||
{
|
||||
if (!is_dir($dir = $this->locator->locate($path))) {
|
||||
return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection();
|
||||
@@ -61,7 +61,7 @@ class AttributeDirectoryLoader extends AttributeFileLoader
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
if (!\is_string($resource)) {
|
||||
return false;
|
||||
|
||||
@@ -43,7 +43,7 @@ class AttributeFileLoader extends FileLoader
|
||||
*
|
||||
* @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
|
||||
*/
|
||||
public function load(mixed $file, string $type = null): ?RouteCollection
|
||||
public function load(mixed $file, ?string $type = null): ?RouteCollection
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
@@ -63,7 +63,7 @@ class AttributeFileLoader extends FileLoader
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
if ('annotation' === $type) {
|
||||
trigger_deprecation('symfony/routing', '6.4', 'The "annotation" route type is deprecated, use the "attribute" route type instead.');
|
||||
@@ -82,7 +82,7 @@ class AttributeFileLoader extends FileLoader
|
||||
$tokens = token_get_all(file_get_contents($file));
|
||||
|
||||
if (1 === \count($tokens) && \T_INLINE_HTML === $tokens[0][0]) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forgot to add the "<?php" start tag at the beginning of the file?', $file));
|
||||
throw new \InvalidArgumentException(\sprintf('The file "%s" does not contain PHP code. Did you forget to add the "<?php" start tag at the beginning of the file?', $file));
|
||||
}
|
||||
|
||||
$nsTokens = [\T_NS_SEPARATOR => true, \T_STRING => true];
|
||||
|
||||
@@ -26,12 +26,12 @@ class ClosureLoader extends Loader
|
||||
/**
|
||||
* Loads a Closure.
|
||||
*/
|
||||
public function load(mixed $closure, string $type = null): RouteCollection
|
||||
public function load(mixed $closure, ?string $type = null): RouteCollection
|
||||
{
|
||||
return $closure($this->env);
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
return $resource instanceof \Closure && (!$type || 'closure' === $type);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class CollectionConfigurator
|
||||
private ?array $parentPrefixes;
|
||||
private string|array|null $host = null;
|
||||
|
||||
public function __construct(RouteCollection $parent, string $name, self $parentConfigurator = null, array $parentPrefixes = null)
|
||||
public function __construct(RouteCollection $parent, string $name, ?self $parentConfigurator = null, ?array $parentPrefixes = null)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
$this->name = $name;
|
||||
@@ -38,15 +38,12 @@ class CollectionConfigurator
|
||||
$this->parentPrefixes = $parentPrefixes;
|
||||
}
|
||||
|
||||
public function __sleep(): array
|
||||
public function __serialize(): array
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
@@ -84,11 +81,11 @@ class CollectionConfigurator
|
||||
if (null === $this->parentPrefixes) {
|
||||
// no-op
|
||||
} elseif ($missing = array_diff_key($this->parentPrefixes, $prefix)) {
|
||||
throw new \LogicException(sprintf('Collection "%s" is missing prefixes for locale(s) "%s".', $this->name, implode('", "', array_keys($missing))));
|
||||
throw new \LogicException(\sprintf('Collection "%s" is missing prefixes for locale(s) "%s".', $this->name, implode('", "', array_keys($missing))));
|
||||
} else {
|
||||
foreach ($prefix as $locale => $localePrefix) {
|
||||
if (!isset($this->parentPrefixes[$locale])) {
|
||||
throw new \LogicException(sprintf('Collection "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $this->name, $locale));
|
||||
throw new \LogicException(\sprintf('Collection "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $this->name, $locale));
|
||||
}
|
||||
|
||||
$prefix[$locale] = $this->parentPrefixes[$locale].$localePrefix;
|
||||
|
||||
@@ -30,15 +30,12 @@ class ImportConfigurator
|
||||
$this->route = $route;
|
||||
}
|
||||
|
||||
public function __sleep(): array
|
||||
public function __serialize(): array
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class RouteConfigurator
|
||||
|
||||
protected $parentConfigurator;
|
||||
|
||||
public function __construct(RouteCollection $collection, RouteCollection $route, string $name = '', CollectionConfigurator $parentConfigurator = null, array $prefixes = null)
|
||||
public function __construct(RouteCollection $collection, RouteCollection $route, string $name = '', ?CollectionConfigurator $parentConfigurator = null, ?array $prefixes = null)
|
||||
{
|
||||
$this->collection = $collection;
|
||||
$this->route = $route;
|
||||
@@ -42,7 +42,14 @@ class RouteConfigurator
|
||||
*/
|
||||
final public function host(string|array $host): static
|
||||
{
|
||||
$previousRoutes = clone $this->route;
|
||||
$this->addHost($this->route, $host);
|
||||
foreach ($previousRoutes as $name => $route) {
|
||||
if (!$this->route->get($name)) {
|
||||
$this->collection->remove($name);
|
||||
}
|
||||
}
|
||||
$this->collection->addCollection($this->route);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class RoutingConfigurator
|
||||
private string $file;
|
||||
private ?string $env;
|
||||
|
||||
public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file, string $env = null)
|
||||
public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file, ?string $env = null)
|
||||
{
|
||||
$this->collection = $collection;
|
||||
$this->loader = $loader;
|
||||
@@ -38,7 +38,7 @@ class RoutingConfigurator
|
||||
/**
|
||||
* @param string|string[]|null $exclude Glob patterns to exclude from the import
|
||||
*/
|
||||
final public function import(string|array $resource, string $type = null, bool $ignoreErrors = false, string|array $exclude = null): ImportConfigurator
|
||||
final public function import(string|array $resource, ?string $type = null, bool $ignoreErrors = false, string|array|null $exclude = null): ImportConfigurator
|
||||
{
|
||||
$this->loader->setCurrentDir(\dirname($this->path));
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ trait HostTrait
|
||||
|
||||
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;
|
||||
@@ -35,14 +36,14 @@ trait HostTrait
|
||||
$localizedRoute->setRequirement('_locale', preg_quote($locale));
|
||||
$localizedRoute->setDefault('_canonical_route', $name);
|
||||
$localizedRoute->setHost($host);
|
||||
$routes->add($name.'.'.$locale, $localizedRoute);
|
||||
$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));
|
||||
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->add($name, $route, $routes->getPriority($name) ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ trait LocalizedRouteTrait
|
||||
*
|
||||
* @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
|
||||
final protected function createLocalizedRoute(RouteCollection $collection, string $name, string|array $path, string $namePrefix = '', ?array $prefixes = null): RouteCollection
|
||||
{
|
||||
$paths = [];
|
||||
|
||||
@@ -37,11 +37,11 @@ trait LocalizedRouteTrait
|
||||
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))));
|
||||
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));
|
||||
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;
|
||||
|
||||
@@ -27,22 +27,33 @@ trait PrefixTrait
|
||||
foreach ($prefix as $locale => $localePrefix) {
|
||||
$prefix[$locale] = trim(trim($localePrefix), '/');
|
||||
}
|
||||
$aliases = [];
|
||||
foreach ($routes->getAliases() as $name => $alias) {
|
||||
$aliases[$alias->getId()][] = $name;
|
||||
}
|
||||
foreach ($routes->all() as $name => $route) {
|
||||
if (null === $locale = $route->getDefault('_locale')) {
|
||||
$priority = $routes->getPriority($name) ?? 0;
|
||||
$routes->remove($name);
|
||||
foreach ($aliases[$name] ?? [] as $aliasName) {
|
||||
$routes->remove($aliasName);
|
||||
}
|
||||
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);
|
||||
$routes->add($name.'.'.$locale, $localizedRoute, $priority);
|
||||
foreach ($aliases[$name] ?? [] as $aliasName) {
|
||||
$routes->addAlias($aliasName.'.'.$locale, $name.'.'.$locale);
|
||||
}
|
||||
}
|
||||
} elseif (!isset($prefix[$locale])) {
|
||||
throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $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->add($name, $route, $routes->getPriority($name) ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@ class ContainerLoader extends ObjectLoader
|
||||
{
|
||||
private ContainerInterface $container;
|
||||
|
||||
public function __construct(ContainerInterface $container, string $env = null)
|
||||
public function __construct(ContainerInterface $container, ?string $env = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
parent::__construct($env);
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
return 'service' === $type && \is_string($resource);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class DirectoryLoader extends FileLoader
|
||||
{
|
||||
public function load(mixed $file, string $type = null): mixed
|
||||
public function load(mixed $file, ?string $type = null): mixed
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
@@ -43,7 +43,7 @@ class DirectoryLoader extends FileLoader
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
// only when type is forced to directory, not to conflict with AttributeLoader
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
*/
|
||||
class GlobFileLoader extends FileLoader
|
||||
{
|
||||
public function load(mixed $resource, string $type = null): mixed
|
||||
public function load(mixed $resource, ?string $type = null): mixed
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
|
||||
@@ -34,7 +34,7 @@ class GlobFileLoader extends FileLoader
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
return 'glob' === $type;
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ abstract class ObjectLoader extends Loader
|
||||
/**
|
||||
* Calls the object method that will load the routes.
|
||||
*/
|
||||
public function load(mixed $resource, string $type = null): RouteCollection
|
||||
public function load(mixed $resource, ?string $type = null): RouteCollection
|
||||
{
|
||||
if (!preg_match('/^[^\:]+(?:::(?:[^\:]+))?$/', $resource)) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object'));
|
||||
throw new \InvalidArgumentException(\sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object'));
|
||||
}
|
||||
|
||||
$parts = explode('::', $resource);
|
||||
@@ -45,11 +45,11 @@ abstract class ObjectLoader extends Loader
|
||||
$loaderObject = $this->getObject($parts[0]);
|
||||
|
||||
if (!\is_object($loaderObject)) {
|
||||
throw new \TypeError(sprintf('"%s:getObject()" must return an object: "%s" returned.', static::class, get_debug_type($loaderObject)));
|
||||
throw new \TypeError(\sprintf('"%s:getObject()" must return an object: "%s" returned.', static::class, get_debug_type($loaderObject)));
|
||||
}
|
||||
|
||||
if (!\is_callable([$loaderObject, $method])) {
|
||||
throw new \BadMethodCallException(sprintf('Method "%s" not found on "%s" when importing routing resource "%s".', $method, get_debug_type($loaderObject), $resource));
|
||||
throw new \BadMethodCallException(\sprintf('Method "%s" not found on "%s" when importing routing resource "%s".', $method, get_debug_type($loaderObject), $resource));
|
||||
}
|
||||
|
||||
$routeCollection = $loaderObject->$method($this, $this->env);
|
||||
@@ -57,7 +57,7 @@ abstract class ObjectLoader extends Loader
|
||||
if (!$routeCollection instanceof RouteCollection) {
|
||||
$type = get_debug_type($routeCollection);
|
||||
|
||||
throw new \LogicException(sprintf('The "%s::%s()" method must return a RouteCollection: "%s" returned.', get_debug_type($loaderObject), $method, $type));
|
||||
throw new \LogicException(\sprintf('The "%s::%s()" method must return a RouteCollection: "%s" returned.', get_debug_type($loaderObject), $method, $type));
|
||||
}
|
||||
|
||||
// make the object file tracked so that if it changes, the cache rebuilds
|
||||
|
||||
@@ -30,7 +30,7 @@ class PhpFileLoader extends FileLoader
|
||||
/**
|
||||
* Loads a PHP file.
|
||||
*/
|
||||
public function load(mixed $file, string $type = null): RouteCollection
|
||||
public function load(mixed $file, ?string $type = null): RouteCollection
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
$this->setCurrentDir(\dirname($path));
|
||||
@@ -54,7 +54,7 @@ class PhpFileLoader extends FileLoader
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'php' === $type);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ final class Psr4DirectoryLoader extends Loader implements DirectoryAwareLoaderIn
|
||||
/**
|
||||
* @param array{path: string, namespace: string} $resource
|
||||
*/
|
||||
public function load(mixed $resource, string $type = null): ?RouteCollection
|
||||
public function load(mixed $resource, ?string $type = null): ?RouteCollection
|
||||
{
|
||||
$path = $this->locator->locate($resource['path'], $this->currentDirectory);
|
||||
if (!is_dir($path)) {
|
||||
@@ -46,7 +46,7 @@ final class Psr4DirectoryLoader extends Loader implements DirectoryAwareLoaderIn
|
||||
return $this->loadFromDirectory($path, trim($resource['namespace'], '\\'));
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
return ('attribute' === $type || 'annotation' === $type) && \is_array($resource) && isset($resource['path'], $resource['namespace']);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class XmlFileLoader extends FileLoader
|
||||
* @throws \InvalidArgumentException when the file cannot be loaded or when the XML cannot be
|
||||
* parsed because it does not validate against the scheme
|
||||
*/
|
||||
public function load(mixed $file, string $type = null): RouteCollection
|
||||
public function load(mixed $file, ?string $type = null): RouteCollection
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
@@ -90,11 +90,11 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->localName, $path));
|
||||
throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->localName, $path));
|
||||
}
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
return \is_string($resource) && 'xml' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'xml' === $type);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class XmlFileLoader extends FileLoader
|
||||
protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $path)
|
||||
{
|
||||
if ('' === $id = $node->getAttribute('id')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" attribute.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must have an "id" attribute.', $path));
|
||||
}
|
||||
|
||||
if ('' !== $alias = $node->getAttribute('alias')) {
|
||||
@@ -128,14 +128,14 @@ class XmlFileLoader extends FileLoader
|
||||
[$defaults, $requirements, $options, $condition, $paths, /* $prefixes */, $hosts] = $this->parseConfigs($node, $path);
|
||||
|
||||
if (!$paths && '' === $node->getAttribute('path')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have a "path" attribute or <path> child nodes.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must have a "path" attribute or <path> child nodes.', $path));
|
||||
}
|
||||
|
||||
if ($paths && '' !== $node->getAttribute('path')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must not have both a "path" attribute and <path> child nodes.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must not have both a "path" attribute and <path> child nodes.', $path));
|
||||
}
|
||||
|
||||
$routes = $this->createLocalizedRoute($collection, $id, $paths ?: $node->getAttribute('path'));
|
||||
$routes = $this->createLocalizedRoute(new RouteCollection(), $id, $paths ?: $node->getAttribute('path'));
|
||||
$routes->addDefaults($defaults);
|
||||
$routes->addRequirements($requirements);
|
||||
$routes->addOptions($options);
|
||||
@@ -146,6 +146,8 @@ class XmlFileLoader extends FileLoader
|
||||
if (null !== $hosts) {
|
||||
$this->addHost($routes, $hosts);
|
||||
}
|
||||
|
||||
$collection->addCollection($routes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +169,7 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
if (!$resource) {
|
||||
throw new \InvalidArgumentException(sprintf('The <import> element in file "%s" must have a "resource" attribute or element.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The <import> element in file "%s" must have a "resource" attribute or element.', $path));
|
||||
}
|
||||
|
||||
$type = $node->getAttribute('type');
|
||||
@@ -180,7 +182,7 @@ class XmlFileLoader extends FileLoader
|
||||
[$defaults, $requirements, $options, $condition, /* $paths */, $prefixes, $hosts] = $this->parseConfigs($node, $path);
|
||||
|
||||
if ('' !== $prefix && $prefixes) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must not have both a "prefix" attribute and <prefix> child nodes.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must not have both a "prefix" attribute and <prefix> child nodes.', $path));
|
||||
}
|
||||
|
||||
$exclude = [];
|
||||
@@ -294,15 +296,15 @@ class XmlFileLoader extends FileLoader
|
||||
case 'resource':
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "condition".', $n->localName, $path));
|
||||
throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "condition".', $n->localName, $path));
|
||||
}
|
||||
}
|
||||
|
||||
if ($controller = $node->getAttribute('controller')) {
|
||||
if (isset($defaults['_controller'])) {
|
||||
$name = $node->hasAttribute('id') ? sprintf('"%s".', $node->getAttribute('id')) : sprintf('the "%s" tag.', $node->tagName);
|
||||
$name = $node->hasAttribute('id') ? \sprintf('"%s".', $node->getAttribute('id')) : \sprintf('the "%s" tag.', $node->tagName);
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" attribute and the defaults key "_controller" for ', $path).$name);
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" attribute and the defaults key "_controller" for ', $path).$name);
|
||||
}
|
||||
|
||||
$defaults['_controller'] = $controller;
|
||||
@@ -318,9 +320,9 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
if ($stateless = $node->getAttribute('stateless')) {
|
||||
if (isset($defaults['_stateless'])) {
|
||||
$name = $node->hasAttribute('id') ? sprintf('"%s".', $node->getAttribute('id')) : sprintf('the "%s" tag.', $node->tagName);
|
||||
$name = $node->hasAttribute('id') ? \sprintf('"%s".', $node->getAttribute('id')) : \sprintf('the "%s" tag.', $node->tagName);
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "stateless" attribute and the defaults key "_stateless" for ', $path).$name);
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" attribute and the defaults key "_stateless" for ', $path).$name);
|
||||
}
|
||||
|
||||
$defaults['_stateless'] = XmlUtils::phpize($stateless);
|
||||
@@ -416,7 +418,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
return $map;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "bool", "int", "float", "string", "list", or "map".', $node->localName, $path));
|
||||
throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "bool", "int", "float", "string", "list", or "map".', $node->localName, $path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +446,7 @@ class XmlFileLoader extends FileLoader
|
||||
continue;
|
||||
}
|
||||
if ('deprecated' !== $child->localName) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $node->getAttribute('id'), $path));
|
||||
throw new \InvalidArgumentException(\sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $node->getAttribute('id'), $path));
|
||||
}
|
||||
|
||||
$deprecatedNode = $child;
|
||||
@@ -455,10 +457,10 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
if (!$deprecatedNode->hasAttribute('package')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <deprecated> element in file "%s" must have a "package" attribute.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The <deprecated> element in file "%s" must have a "package" attribute.', $path));
|
||||
}
|
||||
if (!$deprecatedNode->hasAttribute('version')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <deprecated> element in file "%s" must have a "version" attribute.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The <deprecated> element in file "%s" must have a "version" attribute.', $path));
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
@@ -41,16 +41,16 @@ class YamlFileLoader extends FileLoader
|
||||
/**
|
||||
* @throws \InvalidArgumentException When a route can't be parsed because YAML is invalid
|
||||
*/
|
||||
public function load(mixed $file, string $type = null): RouteCollection
|
||||
public function load(mixed $file, ?string $type = null): RouteCollection
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
if (!stream_is_local($path)) {
|
||||
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('This is not a local file "%s".', $path));
|
||||
}
|
||||
|
||||
if (!file_exists($path)) {
|
||||
throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('File "%s" not found.', $path));
|
||||
}
|
||||
|
||||
$this->yamlParser ??= new YamlParser();
|
||||
@@ -58,7 +58,7 @@ class YamlFileLoader extends FileLoader
|
||||
try {
|
||||
$parsedConfig = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
|
||||
} catch (ParseException $e) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);
|
||||
throw new \InvalidArgumentException(\sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
$collection = new RouteCollection();
|
||||
@@ -71,7 +71,7 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
// not an array
|
||||
if (!\is_array($parsedConfig)) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The file "%s" must contain a YAML array.', $path));
|
||||
}
|
||||
|
||||
foreach ($parsedConfig as $name => $config) {
|
||||
@@ -105,7 +105,7 @@ class YamlFileLoader extends FileLoader
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
return \is_string($resource) && \in_array(pathinfo($resource, \PATHINFO_EXTENSION), ['yml', 'yaml'], true) && (!$type || 'yaml' === $type);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
foreach ($requirements as $placeholder => $requirement) {
|
||||
if (\is_int($placeholder)) {
|
||||
throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s"?', $placeholder, $requirement, $name, $path));
|
||||
throw new \InvalidArgumentException(\sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s"?', $placeholder, $requirement, $name, $path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ class YamlFileLoader extends FileLoader
|
||||
$defaults['_stateless'] = $config['stateless'];
|
||||
}
|
||||
|
||||
$routes = $this->createLocalizedRoute($collection, $name, $config['path']);
|
||||
$routes = $this->createLocalizedRoute(new RouteCollection(), $name, $config['path']);
|
||||
$routes->addDefaults($defaults);
|
||||
$routes->addRequirements($requirements);
|
||||
$routes->addOptions($options);
|
||||
@@ -168,6 +168,8 @@ class YamlFileLoader extends FileLoader
|
||||
if (isset($config['host'])) {
|
||||
$this->addHost($routes, $config['host']);
|
||||
}
|
||||
|
||||
$collection->addCollection($routes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,7 +252,7 @@ class YamlFileLoader extends FileLoader
|
||||
protected function validate(mixed $config, string $name, string $path)
|
||||
{
|
||||
if (!\is_array($config)) {
|
||||
throw new \InvalidArgumentException(sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path));
|
||||
}
|
||||
if (isset($config['alias'])) {
|
||||
$this->validateAlias($config, $name, $path);
|
||||
@@ -258,22 +260,22 @@ class YamlFileLoader extends FileLoader
|
||||
return;
|
||||
}
|
||||
if ($extraKeys = array_diff(array_keys($config), self::AVAILABLE_KEYS)) {
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::AVAILABLE_KEYS)));
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::AVAILABLE_KEYS)));
|
||||
}
|
||||
if (isset($config['resource']) && isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name));
|
||||
}
|
||||
if (!isset($config['resource']) && isset($config['type'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path));
|
||||
throw new \InvalidArgumentException(\sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path));
|
||||
}
|
||||
if (!isset($config['resource']) && !isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path));
|
||||
throw new \InvalidArgumentException(\sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path));
|
||||
}
|
||||
if (isset($config['controller']) && isset($config['defaults']['_controller'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name));
|
||||
}
|
||||
if (isset($config['stateless']) && isset($config['defaults']['_stateless'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "stateless" key and the defaults key "_stateless" for "%s".', $path, $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" key and the defaults key "_stateless" for "%s".', $path, $name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,16 +287,16 @@ class YamlFileLoader extends FileLoader
|
||||
{
|
||||
foreach ($config as $key => $value) {
|
||||
if (!\in_array($key, ['alias', 'deprecated'], true)) {
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify other keys than "alias" and "deprecated" for "%s".', $path, $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify other keys than "alias" and "deprecated" for "%s".', $path, $name));
|
||||
}
|
||||
|
||||
if ('deprecated' === $key) {
|
||||
if (!isset($value['package'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must specify the attribute "package" of the "deprecated" option for "%s".', $path, $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must specify the attribute "package" of the "deprecated" option for "%s".', $path, $name));
|
||||
}
|
||||
|
||||
if (!isset($value['version'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The routing file "%s" must specify the attribute "version" of the "deprecated" option for "%s".', $path, $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must specify the attribute "version" of the "deprecated" option for "%s".', $path, $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user