Skip to content

Commit a4442ac

Browse files
committed
Merge branch 'master' into start-1.1
Conflicts: ChainRouter.php
2 parents 0b37f82 + a98a795 commit a4442ac

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

ChainRouter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class ChainRouter implements RouterInterface, RequestMatcherInterface, WarmableI
3030
private $context;
3131

3232
/**
33-
* @var \Symfony\Component\Routing\RouterInterface[]
33+
* Array of arrays of routers grouped by priority
34+
* @var array
3435
*/
3536
private $routers = array();
3637

ContentAwareGenerator.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function generate($name, $parameters = array(), $absolute = false)
6161
throw new RouteNotFoundException('Route of this document is not an instance of Symfony\Component\Routing\Route but: '.$hint);
6262
}
6363

64+
$this->unsetLocaleIfNotNeeded($route, $parameters);
65+
6466
return parent::generate($route, $parameters, $absolute);
6567
}
6668

@@ -249,4 +251,23 @@ public function getRouteDebugMessage($name, array $parameters = array())
249251

250252
return parent::getRouteDebugMessage($name, $parameters);
251253
}
254+
255+
/**
256+
* Unset the _locale parameter if it is there and not needed
257+
*
258+
* @param SymfonyRoute $route
259+
* @param array $parameters
260+
*/
261+
protected function unsetLocaleIfNotNeeded(SymfonyRoute $route, array &$parameters)
262+
{
263+
$locale = $this->getLocale($parameters);
264+
if (null !== $locale) {
265+
if (preg_match('/'.$route->getRequirement('_locale').'/', $locale) && $locale == $route->getDefault('_locale')) {
266+
$compiledRoute = $route->compile();
267+
if (!in_array('_locale', $compiledRoute->getVariables())) {
268+
unset($parameters['_locale']);
269+
}
270+
}
271+
}
272+
}
252273
}

DynamicRouter.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ public function getRouteCollection()
9191
*/
9292
public function getMatcher()
9393
{
94-
// we may not set the context in DynamicRouter::setContext as this would lead to symfony cache warmup problems
95-
// a request matcher does not need the request context separately as it can get it from the request.
94+
/* we may not set the context in DynamicRouter::setContext as this
95+
* would lead to symfony cache warmup problems.
96+
* a request matcher does not need the request context separately as it
97+
* can get it from the request.
98+
*/
9699
if ($this->matcher instanceof RequestContextAwareInterface) {
97100
$this->matcher->setContext($this->getContext());
98101
}
@@ -113,8 +116,8 @@ public function getGenerator()
113116
/**
114117
* Generates a URL from the given parameters.
115118
*
116-
* If the generator is not able to generate the url, it must throw the RouteNotFoundException
117-
* as documented below.
119+
* If the generator is not able to generate the url, it must throw the
120+
* RouteNotFoundException as documented below.
118121
*
119122
* @param string $name The name of the route
120123
* @param mixed $parameters An array of parameters
@@ -151,12 +154,14 @@ public function supports($name)
151154
* If the matcher can not find information, it must throw one of the
152155
* exceptions documented below.
153156
*
154-
* @param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded)
157+
* @param string $pathinfo The path info to be parsed (raw format, i.e. not
158+
* urldecoded)
155159
*
156160
* @return array An array of parameters
157161
*
158162
* @throws ResourceNotFoundException If the resource could not be found
159-
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
163+
* @throws MethodNotAllowedException If the resource was found but the
164+
* request method is not allowed
160165
*
161166
* @api
162167
*/
@@ -188,16 +193,20 @@ public function match($pathinfo)
188193
* @return array An array of parameters
189194
*
190195
* @throws ResourceNotFoundException If no matching resource could be found
191-
* @throws MethodNotAllowedException If a matching resource was found but the request method is not allowed
196+
* @throws MethodNotAllowedException If a matching resource was found but
197+
* the request method is not allowed
192198
*/
193199
public function matchRequest(Request $request)
194200
{
195-
if (! empty($this->uriFilterRegexp) && ! preg_match($this->uriFilterRegexp, $request->getPathInfo())) {
201+
if (! empty($this->uriFilterRegexp)
202+
&& ! preg_match($this->uriFilterRegexp, $request->getPathInfo())
203+
) {
196204
throw new ResourceNotFoundException("{$request->getPathInfo()} does not match the '{$this->uriFilterRegexp}' pattern");
197205
}
198206

199207
$matcher = $this->getMatcher();
200208
if ($matcher instanceof UrlMatcherInterface) {
209+
// the match method will enhance the route $defaults
201210
return $this->match($request->getPathInfo());
202211
}
203212

RouteProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface RouteProviderInterface
3131
*
3232
* @param Request $request A request against which to match.
3333
*
34-
* @return \Symfony\Component\Routing\RouteCollection with all urls that
34+
* @return \Symfony\Component\Routing\RouteCollection with all Routes that
3535
* could potentially match $request. Empty collection if nothing can
3636
* match.
3737
*/

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"symfony/routing": ">=2.2,<2.3-dev",
1818
"symfony/http-kernel": ">=2.2,<2.3-dev"
1919
},
20+
"suggest": {
21+
"symfony/http-foundation": "ChainRouter/DynamicRouter have optional support for Request instances, several enhancers require a Request instances, >=2.1,<2.3-dev"
22+
},
2023
"autoload": {
2124
"psr-0": { "Symfony\\Cmf\\Component\\Routing": "" }
2225
},

0 commit comments

Comments
 (0)