@@ -60,7 +60,7 @@ public function setPrefix($prefix)
60
60
*/
61
61
public function getRouteCollectionForRequest (Request $ request )
62
62
{
63
- $ url = $ request ->getPathInfo ();
63
+ $ url = $ request ->getPathInfo ();
64
64
$ candidates = $ this ->getCandidates ($ url );
65
65
66
66
$ collection = new RouteCollection ();
@@ -77,7 +77,8 @@ public function getRouteCollectionForRequest(Request $request)
77
77
$ collection ->add ($ key , $ route );
78
78
}
79
79
}
80
- } catch (RepositoryException $ e ) {
80
+ }
81
+ catch (RepositoryException $ e ) {
81
82
// TODO: how to determine whether this is a relevant exception or not?
82
83
// https://github.com/symfony-cmf/RoutingBundle/issues/143
83
84
// for example, getting /my//test (note the double /) is just an invalid path
@@ -95,17 +96,17 @@ public function getRouteCollectionForRequest(Request $request)
95
96
*/
96
97
protected function getCandidates ($ url )
97
98
{
98
- $ candidates = array ();
99
+ $ candidates = array ();
99
100
if ('/ ' !== $ url ) {
100
101
if (preg_match ('/(.+)\.[a-z]+$/i ' , $ url , $ matches )) {
101
102
$ candidates [] = $ this ->idPrefix . $ url ;
102
- $ url = $ matches [1 ];
103
+ $ url = $ matches [1 ];
103
104
}
104
105
105
106
$ part = $ url ;
106
107
while (false !== ($ pos = strrpos ($ part , '/ ' ))) {
107
108
$ candidates [] = $ this ->idPrefix . $ part ;
108
- $ part = substr ($ url , 0 , $ pos );
109
+ $ part = substr ($ url , 0 , $ pos );
109
110
}
110
111
}
111
112
@@ -117,15 +118,15 @@ protected function getCandidates($url)
117
118
/**
118
119
* {@inheritDoc}
119
120
*/
120
- public function getRouteByName ($ name , $ parameters = array ())
121
+ public function getRouteByName ($ name , $ parameters = array ())
121
122
{
122
123
123
124
// $name is the route document path
124
- if ( '' === $ this ->idPrefix || 0 === strpos ($ name , $ this ->idPrefix ) ) {
125
+ if ('' === $ this ->idPrefix || 0 === strpos ($ name , $ this ->idPrefix )) {
125
126
$ route = $ this ->getObjectManager ()->find ($ this ->className , $ name );
126
127
}
127
128
128
- if (! $ route ) {
129
+ if (empty ( $ route) ) {
129
130
throw new RouteNotFoundException (sprintf ('No route found for path "%s" ' , $ name ));
130
131
}
131
132
@@ -139,15 +140,20 @@ public function getRouteByName($name, $parameters = array())
139
140
/**
140
141
* {@inheritDoc}
141
142
*/
142
- public function getRoutesByNames ($ names , $ parameters = array ())
143
+ public function getRoutesByNames ($ names , $ parameters = array ())
143
144
{
144
- $ routes = array ();
145
- foreach ($ names as $ name ) {
146
- if ('' === $ this ->idPrefix || 0 === strpos ($ name , $ this ->idPrefix )) {
147
- $ routes [] = $ name ;
145
+ $ routes = array ();
146
+ if ('' === $ this ->idPrefix ) {
147
+ foreach ($ names as $ name ) {
148
+ if (0 === strpos ($ name , $ this ->idPrefix )) {
149
+ $ routes [] = $ name ;
150
+ }
148
151
}
152
+ } else {
153
+ $ routes = $ names ;
149
154
}
150
155
156
+
151
157
$ collection = $ this ->getObjectManager ()->findMany ($ this ->className , $ routes );
152
158
foreach ($ collection as $ key => $ document ) {
153
159
if (!$ document instanceof SymfonyRoute) {
@@ -158,5 +164,4 @@ public function getRoutesByNames($names, $parameters = array())
158
164
159
165
return $ collection ;
160
166
}
161
-
162
167
}
0 commit comments