8000 merged 2.0 · sigues/symfony@7b0d100 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b0d100

Browse files
committed
merged 2.0
2 parents d67d66a + 50eb170 commit 7b0d100

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

src/Symfony/Component/Routing/Matcher/ApacheUrlMatcher.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ApacheUrlMatcher extends UrlMatcher
3434
public function match($pathinfo)
3535
{
3636
$parameters = array();
37+
$defaults = array();
3738
$allow = array();
3839
$match = false;
3940

@@ -44,26 +45,28 @@ public function match($pathinfo)
4445
$name = substr($name, 9);
4546
}
4647

47-
if (0 === strpos($name, '_ROUTING_')) {
48+
if (0 === strpos($name, '_ROUTING_DEFAULTS_')) {
49+
$name = substr($name, 18);
50+
$defaults[$name] = $value;
51+
} elseif (0 === strpos($name, '_ROUTING_')) {
4852
$name = substr($name, 9);
53+
if ('_route' == $name) {
54+
$match = true;
55+
$parameters[$name] = $value;
56+
} elseif (0 === strpos($name, '_allow_')) {
57+
$allow[] = substr($name, 7);
58+
} else {
59+
$parameters[$name] = $value;
60+
}
4961
} else {
5062
continue;
5163
}
5264

53-
if ('_route' == $name) {
54-
$match = true;
55-
$parameters[$name] = $value;
56-
} elseif (0 === strpos($name, '_allow_')) {
57-
$allow[] = substr($name, 7);
58-
} else {
59-
$parameters[$name] = $value;
60-
}
61-
6265
unset($_SERVER[$key]);
6366
}
6467

6568
if ($match) {
66-
return $parameters;
69+
return $this->mergeDefaults($parameters, $defaults);
6770
} elseif (0 < count($allow)) {
6871
throw new MethodNotAllowedException($allow);
6972
} else {

src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function dump(array $options = array())
7474
$variables[] = 'E=_ROUTING_'.$variable.':%'.($i + 1);
7575
}
7676
foreach ($route->getDefaults() as $key => $value) {
77-
$variables[] = 'E=_ROUTING_'.$key.':'.strtr($value, array(
77+
$variables[] = 'E=_ROUTING_DEFAULTS_'.$key.':'.strtr($value, array(
7878
':' => '\\:',
7979
'=' => '\\=',
8080
'\\' => '\\\\',

src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ RewriteRule .* - [QSA,L]
44

55
# foo
66
RewriteCond %{REQUEST_URI} ^/foo/(baz|symfony)$
7-
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foo,E=_ROUTING_bar:%1,E=_ROUTING_def:test]
7+
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foo,E=_ROUTING_bar:%1,E=_ROUTING_DEFAULTS_def:test]
8+
9+
# foobar
10+
RewriteCond %{REQUEST_URI} ^/foo(?:/([^/]+))?$
11+
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foobar,E=_ROUTING_bar:%1,E=_ROUTING_DEFAULTS_bar:toto]
812

913
# bar
1014
RewriteCond %{REQUEST_URI} ^/bar/([^/]+)$
@@ -58,7 +62,7 @@ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz5unsafe,E=_ROUTING_foo:%1]
5862

5963
# baz6
6064
RewriteCond %{REQUEST_URI} ^/test/baz$
61-
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz6,E=_ROUTING_foo:bar\ baz]
65+
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz6,E=_ROUTING_DEFAULTS_foo:bar\ baz]
6266

6367
# baz7
6468
RewriteCond %{REQUEST_URI} ^/te\ st/baz$

src/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,35 @@ public function getMatchData()
4949
'name' => 'world',
5050
),
5151
),
52+
array(
53+
'Route with params and defaults',
54+
'/hello/hugo',
55+
array(
56+
'_ROUTING__route' => 'hello',
57+
'_ROUTING__controller' => 'AcmeBundle:Default:index',
58+
'_ROUTING_name' => 'hugo',
59+
'_ROUTING_DEFAULTS_name' => 'world',
60+
),
61+
array(
62+
'name' => 'hugo',
63+
'_route' => 'hello',
64+
'_controller' => 'AcmeBundle:Default:index',
65+
),
66+
),
67+
array(
68+
'Route with defaults only',
69+
'/hello',
70+
array(
71+
'_ROUTING__route' => 'hello',
72+
'_ROUTING__controller' => 'AcmeBundle:Default:index',
73+
'_ROUTING_DEFAULTS_name' => 'world',
74+
),
75+
array(
76+
'name' => 'world',
77+
'_route' => 'hello',
78+
'_controller' => 'AcmeBundle:Default:index',
79+
),
80+
),
5281
array(
5382
'REDIRECT_ envs',
5483
'/hello/world',

src/Symfony/Component/Routing/Tests/Matcher/Dumper/ApacheMatcherDumperTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ private function getRouteCollection()
7070
array('def' => 'test'),
7171
array('bar' => 'baz|symfony')
7272
));
73+
// defaults parameters in pattern
74+
$collection->add('foobar', new Route(
75+
'/foo/{bar}',
76+
array('bar' => 'toto')
77+
));
7378
// method requirement
7479
$collection->add('bar', new Route(
7580
'/bar/{foo}',

0 commit comments

Comments
 (0)
0