-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add priority to debug router #36110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add priority to debug router #36110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--------- ---------- ------------ ----------- --------------- | ||
[32m Name [39m [32m Method [39m [32m Scheme [39m [32m Host [39m [32m Path [39m | ||
--------- ---------- ------------ ----------- --------------- | ||
route_1 GET|HEAD http|https localhost /hello/{name} | ||
route_2 PUT|POST http|https localhost /name/add | ||
--------- ---------- ------------ ----------- --------------- | ||
--------- ---------- ------------ ----------- ---------- --------------- | ||
[32m Name [39m [32m Method [39m [32m Scheme [39m [32m Host [39m [32m Priority [39m [32m Path [39m | ||
--------- ---------- ------------ ----------- ---------- --------------- | ||
route_1 GET|HEAD http|https localhost 2 /hello/{name} | ||
route_2 PUT|POST http|https localhost 1 /name/add | ||
--------- ---------- ------------ ----------- ---------- --------------- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you can see in the implementation, routes don't have priorities on their own right now. |
||
{ | ||
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. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why sometimes you compare
0 !== $route->getPriority()
and sometimes only$route->getPriority()
?maybe using the same pattern is better