Merge branch '4.0'

* 4.0:
  Fix typos
  [Routing] remove useless failing mocks
  [appveyor] Workaround GitHub disabling of low versions of TLS
  Use long array syntax
  [Routing] Fix GC control of PHP-DSL
  [Routing] Don't throw 405 when scheme requirement doesn't match
  [Routing] Revert throwing 405 on missed slash/scheme redirections
  [WebProfilerBundle] fix test after ajax path updated
  Fix ArrayInput::toString() for InputArgument::IS_ARRAY args
  Update excluded_ajax_paths for sf4
  Add missing use for RoleInterface
  Add missing use of Role
  [Routing] fix CS
  add container.autowiring.strict_mode to 3.4 docs
  Set controller without __invoke method from invokable class
  [VarDumper] Fixed PHPDoc
This commit is contained in:
Nicolas Grekas 2018-02-26 18:04:28 +01:00
commit f06fa04ff1
23 changed files with 159 additions and 84 deletions

View File

@ -29,7 +29,11 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader
*/
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
{
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
if ('__invoke' === $method->getName()) {
$route->setDefault('_controller', $class->getName());
} else {
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
}
}
/**

View File

@ -38,7 +38,7 @@ class Configuration implements ConfigurationInterface
->children()
->booleanNode('toolbar')->defaultFalse()->end()
->booleanNode('intercept_redirects')->defaultFalse()->end()
->scalarNode('excluded_ajax_paths')->defaultValue('^/(app(_[\\w]+)?\\.php/)?_wdt')->end()
->scalarNode('excluded_ajax_paths')->defaultValue('^/((index|app(_[\w]+)?)\.php/)?_wdt')->end()
->end()
;

View File

@ -32,10 +32,10 @@ class ConfigurationTest extends TestCase
public function getDebugModes()
{
return array(
array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
array(array('excluded_ajax_paths' => 'test'), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => 'test')),
);
}

View File

@ -114,7 +114,7 @@ class ArrayInput extends Input
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
}
} else {
$params[] = is_array($val) ? array_map(array($this, 'escapeToken'), $val) : $this->escapeToken($val);
$params[] = is_array($val) ? implode(' ', array_map(array($this, 'escapeToken'), $val)) : $this->escapeToken($val);
}
}

View File

@ -170,5 +170,8 @@ class ArrayInputTest extends TestCase
$input = new ArrayInput(array('-b' => array('bval_1', 'bval_2'), '--f' => array('fval_1', 'fval_2')));
$this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input);
$input = new ArrayInput(array('array_arg' => array('val_1', 'val_2')));
$this->assertSame('val_1 val_2', (string) $input);
}
}

View File

@ -110,7 +110,7 @@ class MergeExtensionConfigurationPassTest extends TestCase
{
$container = new ContainerBuilder();
$container->registerExtension(new BarExtension());
$container->prependExtensionConfig('bar', []);
$container->prependExtensionConfig('bar', array());
(new MergeExtensionConfigurationPass())->process($container);
}

View File

@ -23,13 +23,15 @@ class CollectionConfigurator
use Traits\RouteTrait;
private $parent;
private $parentConfigurator;
public function __construct(RouteCollection $parent, string $name)
public function __construct(RouteCollection $parent, string $name, self $parentConfigurator = null)
{
$this->parent = $parent;
$this->name = $name;
$this->collection = new RouteCollection();
$this->route = new Route('');
$this->parentConfigurator = $parentConfigurator; // for GC control
}
public function __destruct()
@ -45,7 +47,7 @@ class CollectionConfigurator
{
$this->collection->add($this->name.$name, $route = clone $this->route);
return new RouteConfigurator($this->collection, $route->setPath($path), $this->name);
return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this);
}
/**
@ -55,7 +57,7 @@ class CollectionConfigurator
*/
final public function collection($name = '')
{
return new self($this->collection, $this->name.$name);
return new self($this->collection, $this->name.$name, $this);
}
/**

View File

@ -22,10 +22,11 @@ class RouteConfigurator
use Traits\AddTrait;
use Traits\RouteTrait;
public function __construct(RouteCollection $collection, Route $route, string $name = '')
public function __construct(RouteCollection $collection, Route $route, string $name = '', CollectionConfigurator $parentConfigurator = null)
{
$this->collection = $collection;
$this->route = $route;
$this->name = $name;
$this->parentConfigurator = $parentConfigurator; // for GC control
}
}

View File

@ -29,9 +29,10 @@ trait AddTrait
*/
final public function add(string $name, string $path): RouteConfigurator
{
$parentConfigurator = $this instanceof RouteConfigurator ? $this->parentConfigurator : null;
$this->collection->add($this->name.$name, $route = new Route($path));
return new RouteConfigurator($this->collection, $route);
return new RouteConfigurator($this->collection, $route, '', $parentConfigurator);
}
/**

View File

@ -538,18 +538,26 @@ EOF;
if ($this->supportsRedirections) {
$code .= <<<EOF
if (\$requiredSchemes && !isset(\$requiredSchemes[\$context->getScheme()])) {
\$hasRequiredScheme = !\$requiredSchemes || isset(\$requiredSchemes[\$context->getScheme()]);
if (\$requiredMethods && !isset(\$requiredMethods[\$canonicalMethod]) && !isset(\$requiredMethods[\$requestMethod])) {
if (\$hasRequiredScheme) {
\$allow += \$requiredMethods;
}
break;
}
if (!\$hasRequiredScheme) {
if ('GET' !== \$canonicalMethod) {
\$allow['GET'] = 'GET';
break;
}
return \$this->redirect(\$rawPathinfo, \$ret['_route'], key(\$requiredSchemes)) + \$ret;
}
return \$ret;
EOF;
}
$code .= <<<EOF
} else {
$code .= <<<EOF
if (\$requiredMethods && !isset(\$requiredMethods[\$canonicalMethod]) && !isset(\$requiredMethods[\$requestMethod])) {
\$allow += \$requiredMethods;
@ -559,6 +567,7 @@ EOF;
return \$ret;
EOF;
}
return $code;
}
@ -637,11 +646,20 @@ EOF;
throw new \LogicException('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.');
}
$schemes = self::export(array_flip($schemes));
$code .= <<<EOF
if ($methods) {
$methodVariable = isset($methods['GET']) ? '$canonicalMethod' : '$requestMethod';
$methods = self::export($methods);
$code .= <<<EOF
\$requiredSchemes = $schemes;
if (!isset(\$requiredSchemes[\$context->getScheme()])) {
\$hasRequiredScheme = isset(\$requiredSchemes[\$context->getScheme()]);
if (!isset((\$a = {$methods})[{$methodVariable}])) {
if (\$hasRequiredScheme) {
\$allow += \$a;
}
goto $gotoname;
}
if (!\$hasRequiredScheme) {
if ('GET' !== \$canonicalMethod) {
\$allow['GET'] = 'GET';
goto $gotoname;
}
@ -650,9 +668,21 @@ EOF;
EOF;
}
} else {
$code .= <<<EOF
\$requiredSchemes = $schemes;
if (!isset(\$requiredSchemes[\$context->getScheme()])) {
if ('GET' !== \$canonicalMethod) {
goto $gotoname;
}
if ($methods) {
return \$this->redirect(\$rawPathinfo, '$name', key(\$requiredSchemes)) + \$ret;
}
EOF;
}
} elseif ($methods) {
$methodVariable = isset($methods['GET']) ? '$canonicalMethod' : '$requestMethod';
$methods = self::export($methods);

View File

@ -135,6 +135,12 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
continue;
}
$status = $this->handleRouteRequirements($pathinfo, $name, $route);
if (self::REQUIREMENT_MISMATCH === $status[0]) {
continue;
}
// check HTTP method requirement
if ($requiredMethods = $route->getMethods()) {
// HEAD and GET are equivalent as per RFC
@ -143,18 +149,14 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
}
if (!in_array($method, $requiredMethods)) {
$this->allow = array_merge($this->allow, $requiredMethods);
if (self::REQUIREMENT_MATCH === $status[0]) {
$this->allow = array_merge($this->allow, $requiredMethods);
}
continue;
}
}
$status = $this->handleRouteRequirements($pathinfo, $name, $route);
if (self::REQUIREMENT_MISMATCH === $status[0]) {
continue;
}
return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : array()));
}
}

View File

@ -117,7 +117,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
* Adds a route collection at the end of the current set by appending all
* routes of the added collection.
*/
public function addCollection(RouteCollection $collection)
public function addCollection(self $collection)
{
// we need to remove all routes with the same names first because just replacing them
// would not place the new route at the end of the merged array

View File

@ -105,20 +105,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
}
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
if ('GET' !== $canonicalMethod) {
$allow['GET'] = 'GET';
break;
}
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
}
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
break;
}
return $ret;
}

View File

@ -82,20 +82,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
}
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
if ('GET' !== $canonicalMethod) {
$allow['GET'] = 'GET';
break;
}
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
}
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
break;
}
return $ret;
}
@ -236,20 +237,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
}
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
if ('GET' !== $canonicalMethod) {
$allow['GET'] = 'GET';
break;
}
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
}
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
break;
}
return $ret;
}

View File

@ -64,20 +64,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
if ('GET' !== $canonicalMethod) {
$allow['GET'] = 'GET';
break;
}
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
}
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
break;
}
return $ret;
}
@ -106,20 +107,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
}
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
if ('GET' !== $canonicalMethod) {
$allow['GET'] = 'GET';
break;
}
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
}
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
break;
}
return $ret;
}

View File

@ -60,20 +60,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
if ('GET' !== $canonicalMethod) {
$allow['GET'] = 'GET';
break;
}
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
}
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
break;
}
return $ret;
}
@ -118,20 +119,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
}
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
break;
}
if (!$hasRequiredScheme) {
if ('GET' !== $canonicalMethod) {
$allow['GET'] = 'GET';
break;
}
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
}
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
break;
}
return $ret;
}

View File

@ -4,6 +4,7 @@ namespace Symfony\Component\Routing\Loader\Configurator;
return function (RoutingConfigurator $routes) {
$routes
->collection()
->add('foo', '/foo')
->condition('abc')
->options(array('utf8' => true))

View File

@ -26,6 +26,15 @@ class DumpedUrlMatcherTest extends UrlMatcherTest
parent::testSchemeRequirement();
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.
*/
public function testSchemeAndMethodMismatch()
{
parent::testSchemeRequirement();
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
static $i = 0;

View File

@ -475,6 +475,18 @@ class UrlMatcherTest extends TestCase
$this->assertEquals(array('_route' => 'buz'), $matcher->match('/prefix/buz'));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testSchemeAndMethodMismatch()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array(), array(), null, array('https'), array('POST')));
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/');
}
public function testSiblingRoutes()
{
$coll = new RouteCollection();

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Router;
use Symfony\Component\HttpFoundation\Request;
@ -83,7 +84,7 @@ class RouterTest extends TestCase
{
$this->router->setOption('resource_type', 'ResourceType');
$routeCollection = $this->getMockBuilder('Symfony\Component\Routing\RouteCollection')->getMock();
$routeCollection = new RouteCollection();
$this->loader->expects($this->once())
->method('load')->with('routing.yml', 'ResourceType')
@ -101,7 +102,7 @@ class RouterTest extends TestCase
$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->will($this->returnValue($this->getMockBuilder('Symfony\Component\Routing\RouteCollection')->getMock()));
->will($this->returnValue(new RouteCollection()));
$this->assertInstanceOf('Symfony\\Component\\Routing\\Matcher\\UrlMatcher', $this->router->getMatcher());
}
@ -123,7 +124,7 @@ class RouterTest extends TestCase
$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->will($this->returnValue($this->getMockBuilder('Symfony\Component\Routing\RouteCollection')->getMock()));
->will($this->returnValue(new RouteCollection()));
$this->assertInstanceOf('Symfony\\Component\\Routing\\Generator\\UrlGenerator', $this->router->getGenerator());
}

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Security\Core\Authentication\Token;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Symfony\Component\Security\Core\Role\Role;
/**
* PreAuthenticatedToken implements a pre-authenticated token.

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Security\Core\Authentication\Token;
use Symfony\Component\Security\Core\Role\Role;
/**
* UsernamePasswordToken implements a username and password token.
*

View File

@ -215,7 +215,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
*
* @param string|int $key The key to seek to
*
* @return self|null A clone of $this of null if the key is not set
* @return self|null A clone of $this or null if the key is not set
*/
public function seek($key)
{