Merge branch '4.1'

* 4.1:
  fix deps
  fixed CS
  [FrameworkBundle] fix for allowing single colon controller notation
This commit is contained in:
Nicolas Grekas 2018-06-11 15:22:42 +02:00
commit 90afbf73ac
3 changed files with 65 additions and 13 deletions

View File

@ -87,15 +87,15 @@ class DelegatingLoader extends BaseDelegatingLoader
try {
$controller = $this->parser->parse($controller, false);
@trigger_error(sprintf('Referencing controllers with %s is deprecated since Symfony 4.1. Use %s instead.', $deprecatedNotation, $controller), E_USER_DEPRECATED);
@trigger_error(sprintf('Referencing controllers with %s is deprecated since Symfony 4.1, use "%s" instead.', $deprecatedNotation, $controller), E_USER_DEPRECATED);
} catch (\InvalidArgumentException $e) {
// unable to optimize unknown notation
}
}
if (1 === substr_count($controller, ':')) {
$controller = str_replace(':', '::', $controller);
@trigger_error(sprintf('Referencing controllers with a single colon is deprecated since Symfony 4.1. Use %s instead.', $controller), E_USER_DEPRECATED);
$nonDeprecatedNotation = str_replace(':', '::', $controller);
@trigger_error(sprintf('Referencing controllers with a single colon is deprecated since Symfony 4.1, use "%s" instead.', $nonDeprecatedNotation), E_USER_DEPRECATED);
}
$route->setDefault('_controller', $controller);

View File

@ -5,7 +5,11 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Routing;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class DelegatingLoaderTest extends TestCase
{
@ -17,4 +21,48 @@ class DelegatingLoaderTest extends TestCase
new DelegatingLoader($controllerNameParser, new LoaderResolver());
$this->assertTrue(true, '__construct() takes a ControllerNameParser and LoaderResolverInterface respectively as its first and second argument.');
}
/**
* @group legacy
* @expectedDeprecation Referencing controllers with foo:bar:baz is deprecated since Symfony 4.1. Use some_parsed::controller instead.
* @expectedDeprecation Referencing controllers with a single colon is deprecated since Symfony 4.1. Use foo::baz instead.
*/
public function testLoad()
{
$controllerNameParser = $this->getMockBuilder(ControllerNameParser::class)
->disableOriginalConstructor()
->getMock();
$controllerNameParser->expects($this->once())
->method('parse')
->with('foo:bar:baz')
->willReturn('some_parsed::controller');
$loaderResolver = $this->getMockBuilder(LoaderResolverInterface::class)
->disableOriginalConstructor()
->getMock();
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loaderResolver->expects($this->once())
->method('resolve')
->willReturn($loader);
$routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('/', array('_controller' => 'foo:bar:baz')));
$routeCollection->add('bar', new Route('/', array('_controller' => 'foo::baz')));
$routeCollection->add('baz', new Route('/', array('_controller' => 'foo:baz')));
$loader->expects($this->once())
->method('load')
->willReturn($routeCollection);
$delegatingLoader = new DelegatingLoader($controllerNameParser, $loaderResolver);
$loadedRouteCollection = $delegatingLoader->load('foo');
$this->assertCount(3, $loadedRouteCollection);
$this->assertSame('some_parsed::controller', $routeCollection->get('foo')->getDefault('_controller'));
$this->assertSame('foo::baz', $routeCollection->get('bar')->getDefault('_controller'));
$this->assertSame('foo:baz', $routeCollection->get('baz')->getDefault('_controller'));
}
}

View File

@ -19,9 +19,14 @@ class ProjectServiceContainer extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = array();
$this->services = $this->privates = array();
$this->methodMap = array(
'bar' => 'getBarService',
'foo' => 'getFooService',
@ -30,12 +35,10 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
public function reset()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
$this->privates = array();
parent::reset();
}
public function compile()
@ -48,11 +51,12 @@ class ProjectServiceContainer extends Container
return true;
}
public function isFrozen()
public function getRemovedIds()
{
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED);
return true;
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
protected function createProxy($class, \Closure $factory)