upgrade to laravel 7 and set branch to v2
This commit is contained in:
76
vendor/symfony/routing/RouteCollection.php
vendored
76
vendor/symfony/routing/RouteCollection.php
vendored
@@ -35,6 +35,11 @@ class RouteCollection implements \IteratorAggregate, \Countable
|
||||
*/
|
||||
private $resources = [];
|
||||
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
private $priorities = [];
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->routes as $name => $route) {
|
||||
@@ -53,7 +58,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->routes);
|
||||
return new \ArrayIterator($this->all());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,15 +72,21 @@ 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->routes[$name] = $route;
|
||||
|
||||
if ($priority = 3 <= \func_num_args() ? func_get_arg(2) : 0) {
|
||||
$this->priorities[$name] = $priority;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,17 +96,23 @@ class RouteCollection implements \IteratorAggregate, \Countable
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function get($name)
|
||||
public function get(string $name)
|
||||
{
|
||||
return isset($this->routes[$name]) ? $this->routes[$name] : null;
|
||||
}
|
||||
@@ -108,7 +125,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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +138,12 @@ 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->routes[$name] = $route;
|
||||
|
||||
if (isset($collection->priorities[$name])) {
|
||||
$this->priorities[$name] = $collection->priorities[$name];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($collection->getResources() as $resource) {
|
||||
@@ -132,17 +153,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) {
|
||||
@@ -162,25 +175,26 @@ class RouteCollection implements \IteratorAggregate, \Countable
|
||||
public function addNamePrefix(string $prefix)
|
||||
{
|
||||
$prefixedRoutes = [];
|
||||
$prefixedPriorities = [];
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
$this->routes = $prefixedRoutes;
|
||||
$this->priorities = $prefixedPriorities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
@@ -193,10 +207,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);
|
||||
@@ -207,8 +219,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)
|
||||
{
|
||||
@@ -223,8 +233,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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user