Skip to content

[FrameworkBundle] [Routing] DelegatingLoader: deprecate logger argument #16135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
13 changes: 10 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add another legacy test for the other possibility of the old constructor:

new DelegatingLoader($this->controllerNameParser, null, new LoaderResolver());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
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.');
}
}