-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed minor issues in the router class
- Added missing UrlGeneratorInterface to the router class. - Updated the getCollection method to no longer throw an exception - Improved performance of the addRoute method in the router's class
- Loading branch information
1 parent
7c5b4e1
commit 95d8177
Showing
2 changed files
with
12 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
* | ||
* @author Divine Niiquaye Ibok <[email protected]> | ||
*/ | ||
class Router implements RouteMatcherInterface, RequestMethodInterface, MiddlewareInterface | ||
class Router implements RouteMatcherInterface, RequestMethodInterface, MiddlewareInterface, UrlGeneratorInterface | ||
{ | ||
/** | ||
* Standard HTTP methods for browser requests. | ||
|
@@ -90,9 +90,7 @@ public static function withCollection(RouteCollection $collection = null, RouteC | |
*/ | ||
public function addRoute(Route ...$routes): void | ||
{ | ||
if ($this->collection instanceof RouteCollection) { | ||
$this->collection->routes($routes); | ||
} | ||
$this->getCollection()->routes($routes, false); | ||
} | ||
|
||
/** | ||
|
@@ -118,11 +116,9 @@ public function generateUri(string $routeName, array $parameters = [], int $refe | |
{ | ||
$matcher = $this->getMatcher(); | ||
|
||
//@codeCoverageIgnoreStart | ||
if (!$matcher instanceof UrlGeneratorInterface) { | ||
throw new UrlGenerationException(\sprintf('The route matcher does not support using the %s implementation', UrlGeneratorInterface::class)); | ||
} | ||
//@codeCoverageIgnoreEnd | ||
|
||
return $matcher->generateUri($routeName, $parameters, $referenceType); | ||
} | ||
|
@@ -166,11 +162,11 @@ public function getCollection(): RouteCollection | |
{ | ||
if (\is_callable($collection = $this->collection)) { | ||
$collection($collection = new RouteCollection()); | ||
} elseif (null === $collection) { | ||
throw new \RuntimeException(\sprintf('Did you forget to set add the route collection with the "%s".', __CLASS__ . '::setCollection')); | ||
} elseif (null !== $collection) { | ||
return $this->collection; | ||
} | ||
|
||
return $this->collection = $collection; | ||
return $this->collection = $collection ?? new RouteCollection(); | ||
} | ||
|
||
/** | ||
|
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