upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -12,6 +12,8 @@
namespace Symfony\Component\Routing;
use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\Routing\Exception\InvalidArgumentException;
use Symfony\Component\Routing\Exception\RouteCircularReferenceException;
/**
* A RouteCollection represents a set of Route instances.
@@ -22,24 +24,40 @@ use Symfony\Component\Config\Resource\ResourceInterface;
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Tobias Schultze <http://tobion.de>
*
* @implements \IteratorAggregate<string, Route>
*/
class RouteCollection implements \IteratorAggregate, \Countable
{
/**
* @var Route[]
* @var array<string, Route>
*/
private $routes = [];
/**
* @var array
* @var array<string, Alias>
*/
private $aliases = [];
/**
* @var array<string, ResourceInterface>
*/
private $resources = [];
/**
* @var array<string, int>
*/
private $priorities = [];
public function __clone()
{
foreach ($this->routes as $name => $route) {
$this->routes[$name] = clone $route;
}
foreach ($this->aliases as $name => $alias) {
$this->aliases[$name] = clone $alias;
}
}
/**
@@ -49,18 +67,18 @@ class RouteCollection implements \IteratorAggregate, \Countable
*
* @see all()
*
* @return \ArrayIterator|Route[] An \ArrayIterator object for iterating over routes
* @return \ArrayIterator<string, Route>
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new \ArrayIterator($this->routes);
return new \ArrayIterator($this->all());
}
/**
* Gets the number of Routes in this collection.
*
* @return int The number of routes
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
@@ -69,36 +87,66 @@ class RouteCollection implements \IteratorAggregate, \Countable
}
/**
* Adds a route.
*
* @param string $name The route name
* @param int $priority
*/
public function add($name, Route $route)
public function add(string $name, Route $route/* , int $priority = 0 */)
{
unset($this->routes[$name]);
if (\func_num_args() < 3 && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
trigger_deprecation('symfony/routing', '5.1', 'The "%s()" method will have a new "int $priority = 0" argument in version 6.0, not defining it is deprecated.', __METHOD__);
}
unset($this->routes[$name], $this->priorities[$name], $this->aliases[$name]);
$this->routes[$name] = $route;
if ($priority = 3 <= \func_num_args() ? func_get_arg(2) : 0) {
$this->priorities[$name] = $priority;
}
}
/**
* Returns all routes in this collection.
*
* @return Route[] An array of routes
* @return array<string, Route>
*/
public function all()
{
if ($this->priorities) {
$priorities = $this->priorities;
$keysOrder = array_flip(array_keys($this->routes));
uksort($this->routes, static function ($n1, $n2) use ($priorities, $keysOrder) {
return (($priorities[$n2] ?? 0) <=> ($priorities[$n1] ?? 0)) ?: ($keysOrder[$n1] <=> $keysOrder[$n2]);
});
}
return $this->routes;
}
/**
* Gets a route by name.
*
* @param string $name The route name
*
* @return Route|null A Route instance or null when not found
* @return Route|null
*/
public function get($name)
public function get(string $name)
{
$visited = [];
while (null !== $alias = $this->aliases[$name] ?? null) {
if (false !== $searchKey = array_search($name, $visited)) {
$visited[] = $name;
throw new RouteCircularReferenceException($name, \array_slice($visited, $searchKey));
}
if ($alias->isDeprecated()) {
$deprecation = $alias->getDeprecation($name);
trigger_deprecation($deprecation['package'], $deprecation['version'], $deprecation['message']);
}
$visited[] = $name;
$name = $alias->getId();
}
return $this->routes[$name] ?? null;
}
@@ -110,7 +158,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
public function remove($name)
{
foreach ((array) $name as $n) {
unset($this->routes[$n]);
unset($this->routes[$n], $this->priorities[$n], $this->aliases[$n]);
}
}
@@ -123,8 +171,18 @@ class RouteCollection implements \IteratorAggregate, \Countable
// we need to remove all routes with the same names first because just replacing them
// would not place the new route at the end of the merged array
foreach ($collection->all() as $name => $route) {
unset($this->routes[$name]);
unset($this->routes[$name], $this->priorities[$name], $this->aliases[$name]);
$this->routes[$name] = $route;
if (isset($collection->priorities[$name])) {
$this->priorities[$name] = $collection->priorities[$name];
}
}
foreach ($collection->getAliases() as $name => $alias) {
unset($this->routes[$name], $this->priorities[$name], $this->aliases[$name]);
$this->aliases[$name] = $alias;
}
foreach ($collection->getResources() as $resource) {
@@ -134,17 +192,9 @@ class RouteCollection implements \IteratorAggregate, \Countable
/**
* Adds a prefix to the path of all child routes.
*
* @param string $prefix An optional prefix to add before each pattern of the route collection
* @param array $defaults An array of default values
* @param array $requirements An array of requirements
*/
public function addPrefix($prefix, array $defaults = [], array $requirements = [])
public function addPrefix(string $prefix, array $defaults = [], array $requirements = [])
{
if (null === $prefix) {
@trigger_error(sprintf('Passing null as $prefix to %s is deprecated in Symfony 4.4 and will trigger a TypeError in 5.0.', __METHOD__), \E_USER_DEPRECATED);
}
$prefix = trim(trim($prefix), '/');
if ('' === $prefix) {
@@ -164,25 +214,32 @@ class RouteCollection implements \IteratorAggregate, \Countable
public function addNamePrefix(string $prefix)
{
$prefixedRoutes = [];
$prefixedPriorities = [];
$prefixedAliases = [];
foreach ($this->routes as $name => $route) {
$prefixedRoutes[$prefix.$name] = $route;
if (null !== $name = $route->getDefault('_canonical_route')) {
$route->setDefault('_canonical_route', $prefix.$name);
if (null !== $canonicalName = $route->getDefault('_canonical_route')) {
$route->setDefault('_canonical_route', $prefix.$canonicalName);
}
if (isset($this->priorities[$name])) {
$prefixedPriorities[$prefix.$name] = $this->priorities[$name];
}
}
foreach ($this->aliases as $name => $alias) {
$prefixedAliases[$prefix.$name] = $alias->withId($prefix.$alias->getId());
}
$this->routes = $prefixedRoutes;
$this->priorities = $prefixedPriorities;
$this->aliases = $prefixedAliases;
}
/**
* Sets the host pattern on all routes.
*
* @param string $pattern The pattern
* @param array $defaults An array of default values
* @param array $requirements An array of requirements
*/
public function setHost($pattern, array $defaults = [], array $requirements = [])
public function setHost(?string $pattern, array $defaults = [], array $requirements = [])
{
foreach ($this->routes as $route) {
$route->setHost($pattern);
@@ -195,10 +252,8 @@ class RouteCollection implements \IteratorAggregate, \Countable
* Sets a condition on all routes.
*
* Existing conditions will be overridden.
*
* @param string $condition The condition
*/
public function setCondition($condition)
public function setCondition(?string $condition)
{
foreach ($this->routes as $route) {
$route->setCondition($condition);
@@ -209,8 +264,6 @@ class RouteCollection implements \IteratorAggregate, \Countable
* Adds defaults to all routes.
*
* An existing default value under the same name in a route will be overridden.
*
* @param array $defaults An array of default values
*/
public function addDefaults(array $defaults)
{
@@ -225,8 +278,6 @@ class RouteCollection implements \IteratorAggregate, \Countable
* Adds requirements to all routes.
*
* An existing requirement under the same name in a route will be overridden.
*
* @param array $requirements An array of requirements
*/
public function addRequirements(array $requirements)
{
@@ -278,7 +329,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
/**
* Returns an array of resources loaded to build this collection.
*
* @return ResourceInterface[] An array of resources
* @return ResourceInterface[]
*/
public function getResources()
{
@@ -297,4 +348,36 @@ class RouteCollection implements \IteratorAggregate, \Countable
$this->resources[$key] = $resource;
}
}
/**
* Sets an alias for an existing route.
*
* @param string $name The alias to create
* @param string $alias The route to alias
*
* @throws InvalidArgumentException if the alias is for itself
*/
public function addAlias(string $name, string $alias): Alias
{
if ($name === $alias) {
throw new InvalidArgumentException(sprintf('Route alias "%s" can not reference itself.', $name));
}
unset($this->routes[$name], $this->priorities[$name]);
return $this->aliases[$name] = new Alias($alias);
}
/**
* @return array<string, Alias>
*/
public function getAliases(): array
{
return $this->aliases;
}
public function getAlias(string $name): ?Alias
{
return $this->aliases[$name] ?? null;
}
}