-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,20 @@ | |
* @contact [email protected] | ||
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Swoft\Http\Server\Router; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use LogicException; | ||
use Traversable; | ||
use function array_merge; | ||
use function array_shift; | ||
use ArrayIterator; | ||
use function count; | ||
use function get_class; | ||
use function is_array; | ||
use function is_object; | ||
use function is_string; | ||
use IteratorAggregate; | ||
use LogicException; | ||
use function preg_match; | ||
use function preg_match_all; | ||
use function property_exists; | ||
|
@@ -31,7 +33,6 @@ | |
use function strtr; | ||
use function substr; | ||
use function substr_count; | ||
use Traversable; | ||
use function trim; | ||
|
||
/** | ||
|
@@ -64,13 +65,15 @@ final class Route implements IteratorAggregate | |
/** | ||
* map where parameter binds. | ||
* [param name => regular expression path (or symbol name)] | ||
* | ||
* @var string[] | ||
*/ | ||
private $bindVars; | ||
|
||
/** | ||
* dynamic route param values, only use for route cache | ||
* [param name => value] | ||
* | ||
* @var string[] | ||
*/ | ||
private $params = []; | ||
|
@@ -79,6 +82,7 @@ final class Route implements IteratorAggregate | |
|
||
/** | ||
* path var names. | ||
* | ||
* @var array '/users/{id}' => ['id'] | ||
*/ | ||
private $pathVars = []; | ||
|
@@ -91,6 +95,7 @@ final class Route implements IteratorAggregate | |
/** | ||
* '/users/{id}' -> '/users/' | ||
* '/blog/post-{id}' -> '/blog/post-' | ||
* | ||
* @var string | ||
*/ | ||
private $pathStart = ''; | ||
|
@@ -99,12 +104,14 @@ final class Route implements IteratorAggregate | |
|
||
/** | ||
* middleware handler chains | ||
* | ||
* @var callable[] | ||
*/ | ||
private $chains = []; | ||
|
||
/** | ||
* some custom route options data. | ||
* | ||
* @var array | ||
*/ | ||
private $options; | ||
|
@@ -342,7 +349,8 @@ public function match(string $path): array | |
*/ | ||
public function copyWithParams(array $params): self | ||
{ | ||
$route = clone $this; | ||
$route = clone $this; | ||
// set params | ||
$route->params = $params; | ||
|
||
return $route; | ||
|
@@ -366,11 +374,12 @@ public function middleware(...$middleware): self | |
|
||
/** | ||
* alias of the method: middleware() | ||
* @see middleware() | ||
* | ||
* @param mixed ...$middleware | ||
* | ||
* @return Route | ||
* @see middleware() | ||
* | ||
*/ | ||
public function push(...$middleware): self | ||
{ | ||
|
@@ -405,6 +414,7 @@ public function toUri(array $pathVars = []): string | |
|
||
/** | ||
* get basic info data | ||
* | ||
* @return array | ||
*/ | ||
public function info(): array | ||
|
@@ -418,6 +428,7 @@ public function info(): array | |
|
||
/** | ||
* get all info data | ||
* | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
|
@@ -452,13 +463,8 @@ public function __toString(): string | |
*/ | ||
public function toString(): string | ||
{ | ||
return sprintf( | ||
'%-7s %-25s --> %s (%d middleware)', | ||
$this->method, | ||
$this->path, | ||
$this->getHandlerName(), | ||
count($this->chains) | ||
); | ||
return sprintf('%-7s %-25s --> %s (%d middleware)', $this->method, $this->path, $this->getHandlerName(), | ||
count($this->chains)); | ||
} | ||
|
||
/** | ||
|
@@ -512,6 +518,7 @@ public function setOptions(array $options): self | |
|
||
/** | ||
* Retrieve an external iterator | ||
* | ||
* @link https://php.net/manual/en/iteratoraggregate.getiterator.php | ||
* @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b> | ||
* @since 5.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters