[Routing] Fix host vars extraction

This commit is contained in:
Nicolas Grekas 2018-02-22 09:38:25 +01:00
parent 8e207cda80
commit 70c122b29d
3 changed files with 75 additions and 2 deletions

View File

@ -626,10 +626,10 @@ EOF;
// optimize parameters array
if ($matches || $hostMatches) {
$vars = array();
if ($hostMatches) {
if ($hostMatches && $checkHost) {
$vars[] = '$hostMatches';
}
if ($matches) {
if ($matches || ($hostMatches && !$checkHost)) {
$vars[] = '$matches';
}
$vars[] = "array('_route' => '$name')";

View File

@ -0,0 +1,67 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();
$host = strtolower($context->getHost());
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
$matchedPathinfo = $host.$pathinfo;
$regexList = array(
0 => '{^(?'
.'|(?i:([^\\.]++)\\.exampple\\.com)(?'
.'|/abc([^/]++)(?'
.'|(*:54)'
.')'
.')'
.')$}sD',
);
foreach ($regexList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
switch ($m = (int) $matches['MARK']) {
case 54:
$matches = array('foo' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
// r1
return $this->mergeDefaults(array_replace($matches, array('_route' => 'r1')), array());
// r2
return $this->mergeDefaults(array_replace($matches, array('_route' => 'r2')), array());
break;
}
if (54 === $m) {
break;
}
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
$offset += strlen($m);
}
}
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
}
}

View File

@ -467,6 +467,11 @@ class PhpMatcherDumperTest extends TestCase
$suffixCollection->add('r100', new Route('abc{foo}/100'));
$suffixCollection->add('r200', new Route('abc{foo}/200'));
/* test case 13 */
$hostCollection = new RouteCollection();
$hostCollection->add('r1', (new Route('abc{foo}'))->setHost('{foo}.exampple.com'));
$hostCollection->add('r2', (new Route('abc{foo}'))->setHost('{foo}.exampple.com'));
return array(
array(new RouteCollection(), 'url_matcher0.php', array()),
array($collection, 'url_matcher1.php', array()),
@ -481,6 +486,7 @@ class PhpMatcherDumperTest extends TestCase
array($chunkedCollection, 'url_matcher10.php', array()),
array($demoCollection, 'url_matcher11.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
array($suffixCollection, 'url_matcher12.php', array()),
array($hostCollection, 'url_matcher13.php', array()),
);
}