Skip to content

Commit ee90e05

Browse files
committed
feature symfony#24826 [FrameworkBundle] Allow to pass a logger instance to the Router (ogizanagi)
This PR was merged into the 4.1-dev branch. Discussion ---------- [FrameworkBundle] Allow to pass a logger instance to the Router | Q | A | ------------- | --- | Branch? | 4.1 <!-- see comment below --> | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | symfony#24739 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A As explained in symfony#24739, this will allow the `UrlGenerator` to log invalid calls when `router.strict_requirements` is `false` (so instead of throwing): <img width="1064" alt="screenshot 2017-10-29 a 09 57 31" src="https://user-images.githubusercontent.com/2211145/32142080-482bc64e-bc90-11e7-8382-b78b507bae48.PNG"> ~~This PR must re-introduce the `logger` argument in the definition along with the `monolog.logger` tag removed for cleaning in symfony#24739, once it's merged up into master.~~ Done Commits ------- 78f4f88 [FrameworkBundle] Allow to pass a logger instance to the Router
2 parents 3da36e3 + 78f4f88 commit ee90e05

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.1.0
5+
-----
6+
7+
* allowed to pass an optional `LoggerInterface $logger` instance to the `Router`
8+
49
4.0.0
510
-----
611

src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
</service>
5252

5353
<service id="router.default" class="Symfony\Bundle\FrameworkBundle\Routing\Router">
54+
<tag name="monolog.logger" channel="router" />
5455
<argument type="service" id="service_container" />
5556
<argument>%router.resource%</argument>
5657
<argument type="collection">
@@ -66,6 +67,7 @@
6667
<argument key="matcher_cache_class">%router.cache_class_prefix%UrlMatcher</argument>
6768
</argument>
6869
<argument type="service" id="router.request_context" on-invalid="ignore" />
70+
<argument type="service" id="logger" on-invalid="ignore" />
6971
<call method="setConfigCacheFactory">
7072
<argument type="service" id="config_cache_factory" />
7173
</call>

src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Routing;
1313

14+
use Psr\Log\LoggerInterface;
1415
use Symfony\Component\Config\Loader\LoaderInterface;
1516
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
1617
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
@@ -33,17 +34,19 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
3334
private $collectedParameters = array();
3435

3536
/**
36-
* @param ContainerInterface $container A ContainerInterface instance
37-
* @param mixed $resource The main resource to load
38-
* @param array $options An array of options
39-
* @param RequestContext $context The context
37+
* @param ContainerInterface $container A ContainerInterface instance
38+
* @param mixed $resource The main resource to load
39+
* @param array $options An array of options
40+
* @param RequestContext $context The context
41+
* @param LoggerInterface|null $logger
4042
*/
41-
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null)
43+
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null)
4244
{
4345
$this->container = $container;
4446

4547
$this->resource = $resource;
4648
$this->context = $context ?: new RequestContext();
49+
$this->logger = $logger;
4750
$this->setOptions($options);
4851
}
4952

0 commit comments

Comments
 (0)