Skip to content

Commit

Permalink
feature #368 Autoconfigure resettable processors with the kernel.rese…
Browse files Browse the repository at this point in the history
…t tag (alexandre-abrioux)

This PR was squashed before being merged into the 3.x-dev branch.

Discussion
----------

Autoconfigure resettable processors with the kernel.reset tag

fixed #361 for more details.

### TODO

- [x] add the `kernel.reset` tag to processors implementing the `ResettableInterface`
- [x] add a test in the `MonologExtensionTest` class

Commits
-------

cbbb6f8 Autoconfigure resettable processors with the kernel.reset tag
  • Loading branch information
lyrixx committed Oct 27, 2020
2 parents e0b661e + cbbb6f8 commit 747b86b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.6.1 (xxxx-xx-xx)

* Register resettable processors (`ResettableInterface`) for autoconfiguration (tag: `kernel.reset`)

## 3.6.0 (2020-10-06)

* Added support for Symfony Mailer
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public function load(array $configs, ContainerBuilder $container)
$container->registerForAutoconfiguration(WebProcessor::class)
->addTag('monolog.processor');
}
if (interface_exists(ResettableInterface::class)) {
$container->registerForAutoconfiguration(ResettableInterface::class)
->addTag('kernel.reset', ['method' => 'reset']);
}
$container->registerForAutoconfiguration(TokenProcessor::class)
->addTag('monolog.processor');
if (interface_exists(HttpClientInterface::class)) {
Expand Down
19 changes: 19 additions & 0 deletions Tests/DependencyInjection/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use InvalidArgumentException;
use Monolog\Handler\RollbarHandler;
use Monolog\Logger;
use Monolog\Processor\UidProcessor;
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -696,6 +697,24 @@ public function provideLoglevelParameterConfig()
];
}

public function testProcessorAutoConfiguration()
{
if (!interface_exists('Monolog\ResettableInterface')) {
$this->markTestSkipped('The ResettableInterface is not available.');
}
$service = new Definition(UidProcessor::class);
$service->setAutoconfigured(true);
$container = $this->getContainer([], ['processor.uid' => $service]);
$this->assertTrue($container->hasDefinition('processor.uid'));
$processor = $container->getDefinition('processor.uid');
$tags = $processor->getTags();
$this->assertArrayHasKey('kernel.reset', $tags);
$this->assertIsArray($tags['kernel.reset']);
$this->assertCount(1, $tags['kernel.reset']);
$this->assertIsArray($tags['kernel.reset'][0]);
$this->assertArrayHasKey('method', $tags['kernel.reset'][0]);
$this->assertEquals('reset', $tags['kernel.reset'][0]['method']);
}

protected function getContainer(array $config = [], array $thirdPartyDefinitions = [])
{
Expand Down

0 comments on commit 747b86b

Please sign in to comment.