merged 2.0
This commit is contained in:
commit
7b0d100e02
@ -34,6 +34,7 @@ class ApacheUrlMatcher extends UrlMatcher
|
|||||||
public function match($pathinfo)
|
public function match($pathinfo)
|
||||||
{
|
{
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
|
$defaults = array();
|
||||||
$allow = array();
|
$allow = array();
|
||||||
$match = false;
|
$match = false;
|
||||||
|
|
||||||
@ -44,12 +45,11 @@ class ApacheUrlMatcher extends UrlMatcher
|
|||||||
$name = substr($name, 9);
|
$name = substr($name, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === strpos($name, '_ROUTING_')) {
|
if (0 === strpos($name, '_ROUTING_DEFAULTS_')) {
|
||||||
|
$name = substr($name, 18);
|
||||||
|
$defaults[$name] = $value;
|
||||||
|
} elseif (0 === strpos($name, '_ROUTING_')) {
|
||||||
$name = substr($name, 9);
|
$name = substr($name, 9);
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('_route' == $name) {
|
if ('_route' == $name) {
|
||||||
$match = true;
|
$match = true;
|
||||||
$parameters[$name] = $value;
|
$parameters[$name] = $value;
|
||||||
@ -58,12 +58,15 @@ class ApacheUrlMatcher extends UrlMatcher
|
|||||||
} else {
|
} else {
|
||||||
$parameters[$name] = $value;
|
$parameters[$name] = $value;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
unset($_SERVER[$key]);
|
unset($_SERVER[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($match) {
|
if ($match) {
|
||||||
return $parameters;
|
return $this->mergeDefaults($parameters, $defaults);
|
||||||
} elseif (0 < count($allow)) {
|
} elseif (0 < count($allow)) {
|
||||||
throw new MethodNotAllowedException($allow);
|
throw new MethodNotAllowedException($allow);
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,7 +74,7 @@ class ApacheMatcherDumper extends MatcherDumper
|
|||||||
$variables[] = 'E=_ROUTING_'.$variable.':%'.($i + 1);
|
$variables[] = 'E=_ROUTING_'.$variable.':%'.($i + 1);
|
||||||
}
|
}
|
||||||
foreach ($route->getDefaults() as $key => $value) {
|
foreach ($route->getDefaults() as $key => $value) {
|
||||||
$variables[] = 'E=_ROUTING_'.$key.':'.strtr($value, array(
|
$variables[] = 'E=_ROUTING_DEFAULTS_'.$key.':'.strtr($value, array(
|
||||||
':' => '\\:',
|
':' => '\\:',
|
||||||
'=' => '\\=',
|
'=' => '\\=',
|
||||||
'\\' => '\\\\',
|
'\\' => '\\\\',
|
||||||
|
@ -4,7 +4,11 @@ RewriteRule .* - [QSA,L]
|
|||||||
|
|
||||||
# foo
|
# foo
|
||||||
RewriteCond %{REQUEST_URI} ^/foo/(baz|symfony)$
|
RewriteCond %{REQUEST_URI} ^/foo/(baz|symfony)$
|
||||||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foo,E=_ROUTING_bar:%1,E=_ROUTING_def:test]
|
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foo,E=_ROUTING_bar:%1,E=_ROUTING_DEFAULTS_def:test]
|
||||||
|
|
||||||
|
# foobar
|
||||||
|
RewriteCond %{REQUEST_URI} ^/foo(?:/([^/]+))?$
|
||||||
|
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foobar,E=_ROUTING_bar:%1,E=_ROUTING_DEFAULTS_bar:toto]
|
||||||
|
|
||||||
# bar
|
# bar
|
||||||
RewriteCond %{REQUEST_URI} ^/bar/([^/]+)$
|
RewriteCond %{REQUEST_URI} ^/bar/([^/]+)$
|
||||||
@ -58,7 +62,7 @@ RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz5unsafe,E=_ROUTING_foo:%1]
|
|||||||
|
|
||||||
# baz6
|
# baz6
|
||||||
RewriteCond %{REQUEST_URI} ^/test/baz$
|
RewriteCond %{REQUEST_URI} ^/test/baz$
|
||||||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz6,E=_ROUTING_foo:bar\ baz]
|
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz6,E=_ROUTING_DEFAULTS_foo:bar\ baz]
|
||||||
|
|
||||||
# baz7
|
# baz7
|
||||||
RewriteCond %{REQUEST_URI} ^/te\ st/baz$
|
RewriteCond %{REQUEST_URI} ^/te\ st/baz$
|
||||||
|
@ -49,6 +49,35 @@ class ApacheUrlMatcherTest extends \PHPUnit_Framework_TestCase
|
|||||||
'name' => 'world',
|
'name' => 'world',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'Route with params and defaults',
|
||||||
|
'/hello/hugo',
|
||||||
|
array(
|
||||||
|
'_ROUTING__route' => 'hello',
|
||||||
|
'_ROUTING__controller' => 'AcmeBundle:Default:index',
|
||||||
|
'_ROUTING_name' => 'hugo',
|
||||||
|
'_ROUTING_DEFAULTS_name' => 'world',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'hugo',
|
||||||
|
'_route' => 'hello',
|
||||||
|
'_controller' => 'AcmeBundle:Default:index',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'Route with defaults only',
|
||||||
|
'/hello',
|
||||||
|
array(
|
||||||
|
'_ROUTING__route' => 'hello',
|
||||||
|
'_ROUTING__controller' => 'AcmeBundle:Default:index',
|
||||||
|
'_ROUTING_DEFAULTS_name' => 'world',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'world',
|
||||||
|
'_route' => 'hello',
|
||||||
|
'_controller' => 'AcmeBundle:Default:index',
|
||||||
|
),
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'REDIRECT_ envs',
|
'REDIRECT_ envs',
|
||||||
'/hello/world',
|
'/hello/world',
|
||||||
|
@ -70,6 +70,11 @@ class ApacheMatcherDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('def' => 'test'),
|
array('def' => 'test'),
|
||||||
array('bar' => 'baz|symfony')
|
array('bar' => 'baz|symfony')
|
||||||
));
|
));
|
||||||
|
// defaults parameters in pattern
|
||||||
|
$collection->add('foobar', new Route(
|
||||||
|
'/foo/{bar}',
|
||||||
|
array('bar' => 'toto')
|
||||||
|
));
|
||||||
// method requirement
|
// method requirement
|
||||||
$collection->add('bar', new Route(
|
$collection->add('bar', new Route(
|
||||||
'/bar/{foo}',
|
'/bar/{foo}',
|
||||||
|
Reference in New Issue
Block a user