Skip to content

Commit

Permalink
fix deprecation on rootNode of configuration file and tests files (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deamon authored Oct 7, 2019
1 parent 17a475e commit dbbd8fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
9 changes: 7 additions & 2 deletions DependencyInjection/Configuration.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('deamon_logger_extra');
$treeBuilder = new TreeBuilder('deamon_logger_extra');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('deamon_logger_extra');
} else {
$rootNode = $treeBuilder->getRootNode();
}

$rootNode->children()
->arrayNode('application')->isRequired()
Expand Down
21 changes: 19 additions & 2 deletions Processors/Monolog/DeamonLoggerExtraWebProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Deamon\LoggerExtraBundle\Processors\Monolog;

use Deamon\LoggerExtraBundle\Services\DeamonLoggerExtraContext;
use Symfony\Bridge\Monolog\Processor\WebProcessor as BaseWebProcessor;
use Monolog\Processor\WebProcessor as BaseWebProcessor;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
Expand Down Expand Up @@ -56,7 +58,7 @@ class DeamonLoggerExtraWebProcessor extends BaseWebProcessor

public function __construct(?array $config = null)
{
parent::__construct();
parent::__construct([]);
$this->channelPrefix = $config['channel_prefix'];
$this->displayConfig = $config['display'];
$this->userClass = $config['user_class'];
Expand Down Expand Up @@ -202,6 +204,21 @@ private function configShowExtraInfo(string $extraInfo): bool
return isset($this->displayConfig[$extraInfo]) && $this->displayConfig[$extraInfo];
}

public function onKernelRequest(RequestEvent $event)
{
if ($event->isMasterRequest()) {
$this->serverData = $event->getRequest()->server->all();
$this->serverData['REMOTE_ADDR'] = $event->getRequest()->getClientIp();
}
}

public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => ['onKernelRequest', 4096],
];
}

/**
* @param DeamonLoggerExtraContext $loggerExtraContext
*/
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DeamonLoggerExtraExtensionTest extends TestCase
*/
private $container;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down

0 comments on commit dbbd8fb

Please sign in to comment.