[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 CHANGELOG
========= =========
4.1.0
-----
* allowed to pass an optional `LoggerInterface $logger` instance to the `Router`
4.0.0 4.0.0
----- -----

View File

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

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Routing; namespace Symfony\Bundle\FrameworkBundle\Routing;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
@ -37,13 +38,15 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
* @param mixed $resource The main resource to load * @param mixed $resource The main resource to load
* @param array $options An array of options * @param array $options An array of options
* @param RequestContext $context The context * @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->container = $container;
$this->resource = $resource; $this->resource = $resource;
$this->context = $context ?: new RequestContext(); $this->context = $context ?: new RequestContext();
$this->logger = $logger;
$this->setOptions($options); $this->setOptions($options);
} }