Skip to content

Commit

Permalink
Use NullLogger if no logger available
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Feb 9, 2017
1 parent 3c67713 commit 148de05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
7 changes: 3 additions & 4 deletions EventListener/RouterListener.php
Expand Up @@ -5,6 +5,7 @@
use eZ\Bundle\EzPublishLegacyBundle\Routing\FallbackRouter;
use Netgen\TagsBundle\Routing\Generator\TagUrlGenerator;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
Expand All @@ -28,7 +29,7 @@ class RouterListener implements EventSubscriberInterface
*/
public function __construct(LoggerInterface $logger = null)
{
$this->logger = $logger;
$this->logger = $logger ?: new NullLogger();
}

/**
Expand Down Expand Up @@ -71,9 +72,7 @@ public function onKernelRequest(GetResponseEvent $event)
return;
}

if ($this->logger instanceof LoggerInterface) {
$this->logger->info('Falling back to tag legacy route as specified in config.');
}
$this->logger->info('Falling back to tag legacy route as specified in config.');

$request->attributes->set('_route', FallbackRouter::ROUTE_NAME);
$request->attributes->set('_controller', 'ezpublish_legacy.controller:indexAction');
Expand Down
13 changes: 6 additions & 7 deletions Routing/TagRouter.php
Expand Up @@ -9,6 +9,7 @@
use Netgen\TagsBundle\API\Repository\Values\Tags\Tag;
use Netgen\TagsBundle\Routing\Generator\TagUrlGenerator;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use RuntimeException;
use Symfony\Cmf\Component\Routing\ChainedRouterInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
Expand Down Expand Up @@ -68,8 +69,8 @@ public function __construct(
) {
$this->tagsService = $tagsService;
$this->generator = $generator;
$this->requestContext = $requestContext !== null ? $requestContext : new RequestContext();
$this->logger = $logger;
$this->requestContext = $requestContext ?: new RequestContext();
$this->logger = $logger ?: new NullLogger();
}

/**
Expand Down Expand Up @@ -132,11 +133,9 @@ function (TagsService $tagsService) use ($requestedPath, $languages) {

$request->attributes->set('tagId', $tag->id);

if ($this->logger !== null) {
$this->logger->info(
"TagRouter matched tag #{$tag->id}. Forwarding to tag view controller"
);
}
$this->logger->info(
"TagRouter matched tag #{$tag->id}. Forwarding to tag view controller"
);

return $params;
}
Expand Down

0 comments on commit 148de05

Please sign in to comment.