diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 9d1e97d5f7f2f..b0cc32bec41e5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -209,6 +209,7 @@ protected function getRouteData(Route $route): array 'hostRegex' => '' !== $route->getHost() ? $route->compile()->getHostRegex() : '', 'scheme' => $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', 'method' => $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', + 'priority' => $route->getPriority() ? $route->getPriority() : '', 'class' => \get_class($route), 'defaults' => $route->getDefaults(), 'requirements' => $route->getRequirements() ?: 'NO CUSTOM', diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index ab4f0567b76a7..9d798a83158ce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -56,6 +56,7 @@ protected function describeRoute(Route $route, array $options = []) ."\n".'- Host Regex: '.('' !== $route->getHost() ? $route->compile()->getHostRegex() : '') ."\n".'- Scheme: '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY') ."\n".'- Method: '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY') + ."\n".'- Priority: '.($route->getPriority() ? $route->getPriority() : '') ."\n".'- Class: '.\get_class($route) ."\n".'- Defaults: '.$this->formatRouterConfig($route->getDefaults()) ."\n".'- Requirements: '.($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM') diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 37e2117bc6cd6..111e5b7d046f0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -50,7 +50,7 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio { $showControllers = isset($options['show_controllers']) && $options['show_controllers']; - $tableHeaders = ['Name', 'Method', 'Scheme', 'Host', 'Path']; + $tableHeaders = ['Name', 'Method', 'Scheme', 'Host', 'Priority', 'Path']; if ($showControllers) { $tableHeaders[] = 'Controller'; } @@ -64,6 +64,7 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', '' !== $route->getHost() ? $route->getHost() : 'ANY', + 0 !== $route->getPriority() ? $route->getPriority() : '', $this->formatControllerLink($controller, $route->getPath()), ]; @@ -97,6 +98,7 @@ protected function describeRoute(Route $route, array $options = []) ['Host Regex', ('' !== $route->getHost() ? $route->compile()->getHostRegex() : '')], ['Scheme', ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY')], ['Method', ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')], + ['Priority', (0 !== $route->getPriority() ? $route->getPriority() : '')], ['Requirements', ($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')], ['Class', \get_class($route)], ['Defaults', $this->formatRouterConfig($route->getDefaults())], diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index 16e79f45f4cb8..0c974fd2f29c8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -195,6 +195,9 @@ private function getRouteDocument(Route $route, string $name = null): \DOMDocume $methodXML->appendChild(new \DOMText($method)); } + $routeXML->appendChild($priorityXML = $dom->createElement('priority')); + $priorityXML->appendChild(new \DOMText($route->getPriority())); + if ($route->getDefaults()) { $routeXML->appendChild($defaultsXML = $dom->createElement('defaults')); foreach ($route->getDefaults() as $attribute => $value) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 84f05c64874ea..62ba5a3dc0343 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -44,7 +44,9 @@ public static function getRoutes() ['opt1' => 'val1', 'opt2' => 'val2'], 'localhost', ['http', 'https'], - ['get', 'head'] + ['get', 'head'], + '', + 2 ), 'route_2' => new RouteStub( '/name/add', @@ -54,7 +56,8 @@ public static function getRoutes() 'localhost', ['http', 'https'], ['put', 'post'], - "context.getMethod() in ['GET', 'HEAD', 'POST']" + "context.getMethod() in ['GET', 'HEAD', 'POST']", + 1 ), ]; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.json index 1108109fb0b48..50f2d42cd75c0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.json @@ -5,6 +5,7 @@ "hostRegex": "#HOST_REGEX#", "scheme": "http|https", "method": "GET|HEAD", + "priority": 2, "class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\RouteStub", "defaults": { "name": "Joseph" diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.md index c36d35c83e8ac..c9952e5278edf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.md @@ -4,12 +4,13 @@ - Host Regex: #HOST_REGEX# - Scheme: http|https - Method: GET|HEAD +- Priority: 2 - Class: Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub -- Defaults: +- Defaults: - `name`: Joseph -- Requirements: +- Requirements: - `name`: [a-z]+ -- Options: +- Options: - `compiler_class`: Symfony\Component\Routing\RouteCompiler - `opt1`: val1 - `opt2`: val2 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt index 25074dfd18b2c..cc8485db4dfc3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt @@ -8,6 +8,7 @@ | Host Regex | #HOST_REGEX# | | Scheme | http|https | | Method | GET|HEAD | +| Priority | 2 | | Requirements | name: [a-z]+ | | Class | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub | | Defaults | name: Joseph | diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.xml index 9ff531c92821a..82ec068dbbff7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.xml @@ -6,6 +6,7 @@ https GET HEAD + 2 Joseph diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.json index 5b70dde63acef..7bb8885a4c8ac 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.json @@ -5,6 +5,7 @@ "hostRegex": "#HOST_REGEX#", "scheme": "http|https", "method": "PUT|POST", + "priority": 1, "class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\RouteStub", "defaults": [], "requirements": "NO CUSTOM", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.md index c60a6296b28db..d167e869c7694 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.md @@ -4,11 +4,12 @@ - Host Regex: #HOST_REGEX# - Scheme: http|https - Method: PUT|POST +- Priority: 1 - Class: Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub - Defaults: NONE - Requirements: NO CUSTOM -- Options: +- Options: - `compiler_class`: Symfony\Component\Routing\RouteCompiler - `opt1`: val1 - `opt2`: val2 -- Condition: context.getMethod() in ['GET', 'HEAD', 'POST'] \ No newline at end of file +- Condition: context.getMethod() in ['GET', 'HEAD', 'POST'] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt index 5853dd013d3a3..f4e8403d8dfce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt @@ -8,6 +8,7 @@ | Host Regex | #HOST_REGEX# | | Scheme | http|https | | Method | PUT|POST | +| Priority | 1 | | Requirements | NO CUSTOM | | Class | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub | | Defaults | NONE | diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.xml index f06a5f0cc30c2..781cfc42bcf0e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.xml @@ -6,6 +6,7 @@ https PUT POST + 1 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.json index 200108a166aac..2c7201c7a366b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.json @@ -6,6 +6,7 @@ "hostRegex": "#HOST_REGEX#", "scheme": "http|https", "method": "GET|HEAD", + "priority": 2, "class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\RouteStub", "defaults": { "name": "Joseph" @@ -26,6 +27,7 @@ "hostRegex": "#HOST_REGEX#", "scheme": "http|https", "method": "PUT|POST", + "priority": 1, "class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\RouteStub", "defaults": [], "requirements": "NO CUSTOM", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.md index 432001f0247fa..95b11c1707457 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.md @@ -7,12 +7,13 @@ route_1 - Host Regex: #HOST_REGEX# - Scheme: http|https - Method: GET|HEAD +- Priority: 2 - Class: Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub -- Defaults: +- Defaults: - `name`: Joseph -- Requirements: +- Requirements: - `name`: [a-z]+ -- Options: +- Options: - `compiler_class`: Symfony\Component\Routing\RouteCompiler - `opt1`: val1 - `opt2`: val2 @@ -27,10 +28,11 @@ route_2 - Host Regex: #HOST_REGEX# - Scheme: http|https - Method: PUT|POST +- Priority: 1 - Class: Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub - Defaults: NONE - Requirements: NO CUSTOM -- Options: +- Options: - `compiler_class`: Symfony\Component\Routing\RouteCompiler - `opt1`: val1 - `opt2`: val2 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.txt index 9d06562328908..8bea46d402237 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.txt @@ -1,7 +1,7 @@ - --------- ---------- ------------ ----------- --------------- -  Name   Method   Scheme   Host   Path  - --------- ---------- ------------ ----------- --------------- - route_1 GET|HEAD http|https localhost /hello/{name} - route_2 PUT|POST http|https localhost /name/add - --------- ---------- ------------ ----------- --------------- + --------- ---------- ------------ ----------- ---------- --------------- +  Name   Method   Scheme   Host   Priority   Path  + --------- ---------- ------------ ----------- ---------- --------------- + route_1 GET|HEAD http|https localhost 2 /hello/{name} + route_2 PUT|POST http|https localhost 1 /name/add + --------- ---------- ------------ ----------- ---------- --------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.xml index 6a07e059649c8..3fc7636024a22 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.xml @@ -7,6 +7,7 @@ https GET HEAD + 2 Joseph @@ -26,6 +27,7 @@ https PUT POST + 1 diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 8800e8985406d..73d11450bea31 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -201,7 +201,8 @@ protected function addRoute(RouteCollection $collection, $annot, array $globals, } foreach ($paths as $locale => $path) { - $route = $this->createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition); + $route = $this->createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, + $condition, $priority); $this->configureRoute($route, $class, $method, $annot); if (0 !== $locale) { $route->setDefault('_locale', $locale); @@ -325,9 +326,10 @@ private function resetGlobals(): array ]; } - protected function createRoute(string $path, array $defaults, array $requirements, array $options, ?string $host, array $schemes, array $methods, ?string $condition) + protected function createRoute(string $path, array $defaults, array $requirements, array $options, ?string $host, + array $schemes, array $methods, ?string $condition, ?int $priority) { - return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition); + return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition, $priority); } abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot); diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index 3b4d04c36db75..dbf48ca8db153 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -27,6 +27,7 @@ class Route implements \Serializable private $requirements = []; private $options = []; private $condition = ''; + private $priority = 0; /** * @var CompiledRoute|null @@ -49,8 +50,11 @@ class Route implements \Serializable * @param string|string[] $schemes A required URI scheme or an array of restricted schemes * @param string|string[] $methods A required HTTP method or an array of restricted methods * @param string|null $condition A condition that should evaluate to true for the route to match + * @param int|null $priority */ - public function __construct(string $path, array $defaults = [], array $requirements = [], array $options = [], ?string $host = '', $schemes = [], $methods = [], ?string $condition = '') + public function __construct(string $path, array $defaults = [], array $requirements = [], array $options = [], + ?string $host = '', $schemes = [], $methods = [], ?string $condition = '', ?int + $priority = 0) { $this->setPath($path); $this->addDefaults($defaults); @@ -60,6 +64,7 @@ public function __construct(string $path, array $defaults = [], array $requireme $this->setSchemes($schemes); $this->setMethods($methods); $this->setCondition($condition); + $this->setPriority($priority); } public function __serialize(): array @@ -74,6 +79,7 @@ public function __serialize(): array 'methods' => $this->methods, 'condition' => $this->condition, 'compiled' => $this->compiled, + 'priority' => $this->priority, ]; } @@ -101,6 +107,7 @@ public function __unserialize(array $data): void if (isset($data['compiled'])) { $this->compiled = $data['compiled']; } + $this->priority = $data['priority']; } /** @@ -507,6 +514,29 @@ public function setCondition(?string $condition) return $this; } + /** + * Returns the priority. + * + * @return integer The priority + */ + public function getPriority(): ?int + { + return $this->priority; + } + + /** + * Sets the priority. + * + * @return $this + */ + public function setPriority(?int $priority) + { + $this->priority = (int) $priority; + $this->compiled = null; + + return $this; + } + /** * Compiles the route. * pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy