[FrameworkBundle] [Routing] DelegatingLoader: deprecate logger argument

This commit is contained in:
ogizanagi 2015-10-05 23:40:44 +02:00
parent 9c5565f30c
commit af0eba7d26
3 changed files with 55 additions and 5 deletions

View File

@ -56,9 +56,7 @@
</service>
<service id="routing.loader" class="%routing.loader.class%">
<tag name="monolog.logger" channel="router" />
<argument type="service" id="controller_name_converter" />
<argument type="service" id="logger" on-invalid="null" />
<argument type="service" id="routing.resolver" />
</service>

View File

@ -34,14 +34,21 @@ class DelegatingLoader extends BaseDelegatingLoader
/**
* Constructor.
*
* Ability to pass a LoggerInterface instance as second argument will be removed in 3.0.
*
* @param ControllerNameParser $parser A ControllerNameParser instance
* @param LoggerInterface $logger A LoggerInterface instance
* @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
*/
public function __construct(ControllerNameParser $parser, LoggerInterface $logger = null, LoaderResolverInterface $resolver)
public function __construct(ControllerNameParser $parser, $resolver, $r = null)
{
$this->parser = $parser;
$this->logger = $logger;
if (!$resolver instanceof LoaderResolverInterface) {
$this->logger = $resolver;
$resolver = $r;
@trigger_error('Passing a LoggerInterface instance a second argument of the '.__METHOD__.' method is deprecated since version 2.8 and will not be supported anymore in 3.0.', E_USER_DEPRECATED);
}
parent::__construct($resolver);
}

View File

@ -0,0 +1,45 @@
<?php
namespace Symfony\Bundle\FrameworkBundle\Tests\Routing;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
class DelegatingLoaderTest extends \PHPUnit_Framework_TestCase
{
/** @var ControllerNameParser */
private $controllerNameParser;
public function setUp()
{
$this->controllerNameParser = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser')
->disableOriginalConstructor()
->getMock();
}
/**
* @group legacy
*/
public function testLegacyConstructorApi()
{
new DelegatingLoader($this->controllerNameParser, new NullLogger(), new LoaderResolver());
$this->assertTrue(true, '__construct() accepts a LoggerInterface instance as its second argument');
}
/**
* @group legacy
*/
public function testLegacyConstructorApiAcceptsNullAsSecondArgument()
{
new DelegatingLoader($this->controllerNameParser, null, new LoaderResolver());
$this->assertTrue(true, '__construct() accepts null as its second argument');
}
public function testConstructorApi()
{
new DelegatingLoader($this->controllerNameParser, new LoaderResolver());
$this->assertTrue(true, '__construct() takes a ControllerNameParser and LoaderResolverInterface respectively as its first and second argument.');
}
}