1212namespace  Symfony \Cmf \Component \Routing ;
1313
1414use  Symfony \Component \Routing \RouterInterface ;
15+ use  Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
1516use  Symfony \Component \Routing \Matcher \RequestMatcherInterface ;
1617use  Symfony \Component \Routing \RequestContext ;
1718use  Symfony \Component \Routing \RequestContextAwareInterface ;
2425use  Psr \Log \LoggerInterface ;
2526
2627/** 
27-  * ChainRouter 
28-  * 
29-  * Allows access to a lot of different routers. 
28+  * The ChainRouter allows to combine several routers to try in a defined order. 
3029 * 
3130 * @author Henrik Bjornskov <[email protected] > 3231 * @author Magnus Nordlander <[email protected] > 3332 */ 
3433class  ChainRouter implements  ChainRouterInterface, WarmableInterface
3534{
3635    /** 
37-      * @var \Symfony\Component\Routing\ RequestContext 
36+      * @var RequestContext 
3837     */ 
3938    private  $ context
4039
@@ -45,17 +44,17 @@ class ChainRouter implements ChainRouterInterface, WarmableInterface
4544    private  $ routersarray ();
4645
4746    /** 
48-      * @var \Symfony\Component\Routing\ RouterInterface[] Array of routers, sorted by priority 
47+      * @var RouterInterface[] Array of routers, sorted by priority 
4948     */ 
5049    private  $ sortedRouters
5150
5251    /** 
53-      * @var \Symfony\Component\Routing\ RouteCollection 
52+      * @var RouteCollection 
5453     */ 
5554    private  $ routeCollection
5655
5756    /** 
58-      * @var null|\Psr\Log\ LoggerInterface 
57+      * @var null|LoggerInterface 
5958     */ 
6059    protected  $ logger
6160
@@ -78,8 +77,13 @@ public function getContext()
7877    /** 
7978     * {@inheritdoc} 
8079     */ 
81-     public  function  add (RouterInterface   $ router$ priority0 )
80+     public  function  add ($ router$ priority0 )
8281    {
82+         if  (!$ routerinstanceof  RouterInterface
83+             && !($ routerinstanceof  RequestMatcherInterface && $ routerinstanceof  UrlGeneratorInterface)
84+         ) {
85+             throw  new  \InvalidArgumentException (sprintf ('%s is not a valid router. ' , get_class ($ router
86+         }
8387        if  (empty ($ this routers [$ priority
8488            $ this routers [$ priorityarray ();
8589        }
@@ -159,6 +163,10 @@ public function matchRequest(Request $request)
159163     * 
160164     * @param string  $url 
161165     * @param Request $request 
166+      * 
167+      * @return array An array of parameters 
168+      * 
169+      * @throws ResourceNotFoundException If no router matched. 
162170     */ 
163171    private  function  doMatch ($ urlRequest $ requestnull )
164172    {
@@ -208,15 +216,14 @@ public function generate($name, $parameters = array(), $absolute = false)
208216        $ debugarray ();
209217
210218        foreach  ($ this all () as  $ router
211-             // if $router does not implement ChainedRouterInterface and $name is not a string, continue 
212-             if  ($ name$ routerinstanceof  ChainedRouterInterface) {
213-                 if  (! is_string ($ name
214-                     continue ;
215-                 }
219+             // if $router does not announce it is capable of handling 
220+             // non-string routes and $name is not a string, continue 
221+             if  ($ nameis_string ($ name$ routerinstanceof  VersatileGeneratorInterface) {
222+                 continue ;
216223            }
217224
218-             // If $router implements ChainedRouterInterface but  doesn't support this route name, continue 
219-             if  ($ routerinstanceof  ChainedRouterInterface  && !$ routersupports ($ name
225+             // If $router is versatile and  doesn't support this route name, continue 
226+             if  ($ routerinstanceof  VersatileGeneratorInterface  && !$ routersupports ($ name
220227                continue ;
221228            }
222229
0 commit comments