[FrameworkBundle] Allow to pass a logger instance to the Router

This commit is contained in:
Maxime Steinhausser 2017-11-05 17:04:27 +01:00
parent 12f6db8a9a
commit 78f4f88cdd
3 changed files with 15 additions and 5 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
4.1.0
-----
* allowed to pass an optional `LoggerInterface $logger` instance to the `Router`
4.0.0
-----

View File

@ -51,6 +51,7 @@
</service>
<service id="router.default" class="Symfony\Bundle\FrameworkBundle\Routing\Router">
<tag name="monolog.logger" channel="router" />
<argument type="service" id="service_container" />
<argument>%router.resource%</argument>
<argument type="collection">
@ -66,6 +67,7 @@
<argument key="matcher_cache_class">%router.cache_class_prefix%UrlMatcher</argument>
</argument>
<argument type="service" id="router.request_context" on-invalid="ignore" />
<argument type="service" id="logger" on-invalid="ignore" />
<call method="setConfigCacheFactory">
<argument type="service" id="config_cache_factory" />
</call>

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Routing;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
@ -33,17 +34,19 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
private $collectedParameters = array();
/**
* @param ContainerInterface $container A ContainerInterface instance
* @param mixed $resource The main resource to load
* @param array $options An array of options
* @param RequestContext $context The context
* @param ContainerInterface $container A ContainerInterface instance
* @param mixed $resource The main resource to load
* @param array $options An array of options
* @param RequestContext $context The context
* @param LoggerInterface|null $logger
*/
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null)
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null)
{
$this->container = $container;
$this->resource = $resource;
$this->context = $context ?: new RequestContext();
$this->logger = $logger;
$this->setOptions($options);
}