-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from symfony-cmf/deprecate-dynamicrouter-match
deprecate DynamicRouter::match and cleanup interface usage
- Loading branch information
Showing
7 changed files
with
49 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Cmf\Component\Routing; | ||
|
||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Routing\Matcher\RequestMatcherInterface; | ||
use Symfony\Component\Routing\RequestContext; | ||
use Symfony\Component\Routing\RequestContextAwareInterface; | ||
|
@@ -24,17 +25,15 @@ | |
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* ChainRouter | ||
* | ||
* Allows access to a lot of different routers. | ||
* The ChainRouter allows to combine several routers to try in a defined order. | ||
* | ||
* @author Henrik Bjornskov <[email protected]> | ||
* @author Magnus Nordlander <[email protected]> | ||
*/ | ||
class ChainRouter implements ChainRouterInterface, WarmableInterface | ||
{ | ||
/** | ||
* @var \Symfony\Component\Routing\RequestContext | ||
* @var RequestContext | ||
*/ | ||
private $context; | ||
|
||
|
@@ -45,17 +44,17 @@ class ChainRouter implements ChainRouterInterface, WarmableInterface | |
private $routers = array(); | ||
|
||
/** | ||
* @var \Symfony\Component\Routing\RouterInterface[] Array of routers, sorted by priority | ||
* @var RouterInterface[] Array of routers, sorted by priority | ||
*/ | ||
private $sortedRouters; | ||
|
||
/** | ||
* @var \Symfony\Component\Routing\RouteCollection | ||
* @var RouteCollection | ||
*/ | ||
private $routeCollection; | ||
|
||
/** | ||
* @var null|\Psr\Log\LoggerInterface | ||
* @var null|LoggerInterface | ||
*/ | ||
protected $logger; | ||
|
||
|
@@ -78,8 +77,13 @@ public function getContext() | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function add(RouterInterface $router, $priority = 0) | ||
public function add($router, $priority = 0) | ||
{ | ||
if (!$router instanceof RouterInterface | ||
&& !($router instanceof RequestMatcherInterface && $router instanceof UrlGeneratorInterface) | ||
) { | ||
throw new \InvalidArgumentException(sprintf('%s is not a valid router.', get_class($router))); | ||
} | ||
if (empty($this->routers[$priority])) { | ||
$this->routers[$priority] = array(); | ||
} | ||
|
@@ -159,6 +163,10 @@ public function matchRequest(Request $request) | |
* | ||
* @param string $url | ||
* @param Request $request | ||
* | ||
* @return array An array of parameters | ||
* | ||
* @throws ResourceNotFoundException If no router matched. | ||
*/ | ||
private function doMatch($url, Request $request = null) | ||
{ | ||
|
@@ -208,15 +216,14 @@ public function generate($name, $parameters = array(), $absolute = false) | |
$debug = array(); | ||
|
||
foreach ($this->all() as $router) { | ||
// if $router does not implement ChainedRouterInterface and $name is not a string, continue | ||
if ($name && !$router instanceof ChainedRouterInterface) { | ||
if (! is_string($name)) { | ||
continue; | ||
} | ||
// if $router does not announce it is capable of handling | ||
// non-string routes and $name is not a string, continue | ||
if ($name && !is_string($name) && !$router instanceof VersatileGeneratorInterface) { | ||
continue; | ||
} | ||
|
||
// If $router implements ChainedRouterInterface but doesn't support this route name, continue | ||
if ($router instanceof ChainedRouterInterface && !$router->supports($name)) { | ||
// If $router is versatile and doesn't support this route name, continue | ||
if ($router instanceof VersatileGeneratorInterface && !$router->supports($name)) { | ||
continue; | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -15,27 +15,25 @@ | |
use Symfony\Component\Routing\Matcher\RequestMatcherInterface; | ||
|
||
/** | ||
* ChainRouterInterface | ||
* Interface for a router that proxies routing to other routers. | ||
* | ||
* Allows access to a lot of different routers. | ||
* | ||
* @author Henrik Bjornskov <[email protected]> | ||
* @author Magnus Nordlander <[email protected]> | ||
* @author Daniel Wehner <[email protected]> | ||
*/ | ||
interface ChainRouterInterface extends RouterInterface, RequestMatcherInterface | ||
{ | ||
/** | ||
* Add a Router to the index | ||
* Add a Router to the index. | ||
* | ||
* @param RouterInterface $router The router instance | ||
* @param RouterInterface $router The router instance. Instead of RouterInterface, may also | ||
* be RequestMatcherInterface and UrlGeneratorInterface. | ||
* @param integer $priority The priority | ||
*/ | ||
public function add(RouterInterface $router, $priority = 0); | ||
public function add($router, $priority = 0); | ||
|
||
/** | ||
* Sorts the routers and flattens them. | ||
* | ||
* @return RouterInterface[] | ||
* @return RouterInterface[] or RequestMatcherInterface and UrlGeneratorInterface. | ||
*/ | ||
public function all(); | ||
} |
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
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