Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a61749b

Browse files
committed
minor #546 Removed legacy getter from LoggerChannelPass (HypeMC)
This PR was merged into the 4.x branch. Discussion ---------- Removed legacy getter from `LoggerChannelPass` | Q | A | ------------- | --- | Branch? | 4.x | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Follow-up to #545 The `LoggerChannelPass::getChannels()` method was originally added in 4d5a969 for the `DebugHandlerPass` and was later used in the `FixEmptyLoggerPass`. Since both passes have been removed, this method is no longer needed. Commits ------- 833daad Removed legacy getter from `LoggerChannelPass`
2 parents a56dedf + 833daad commit a61749b

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

‎src/DependencyInjection/Compiler/LoggerChannelPass.php‎

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
*/
2929
class LoggerChannelPass implements CompilerPassInterface
3030
{
31-
/** @var list<string> */
32-
protected array $channels = ['app'];
33-
3431
public function process(ContainerBuilder $container): void
3532
{
3633
if (!$container->hasDefinition('monolog.logger')) {
3734
return;
3835
}
3936

37+
/** @var list<string> $createdLoggers */
38+
$createdLoggers = ['app'];
39+
4040
// create channels necessary for the handlers
4141
foreach ($container->findTaggedServiceIds('monolog.logger') as $id => $tags) {
4242
foreach ($tags as $tag) {
@@ -48,7 +48,7 @@ public function process(ContainerBuilder $container): void
4848

4949
$definition = $container->getDefinition($id);
5050
$loggerId = \sprintf('monolog.logger.%s', $resolvedChannel);
51-
$this->createLogger($resolvedChannel, $loggerId, $container);
51+
$this->createLogger($resolvedChannel, $loggerId, $container, $createdLoggers);
5252

5353
foreach ($definition->getArguments() as $index => $argument) {
5454
if ($argument instanceof Reference && 'logger' === (string) $argument) {
@@ -86,15 +86,15 @@ public function process(ContainerBuilder $container): void
8686
continue;
8787
}
8888
$loggerId = \sprintf('monolog.logger.%s', $chan);
89-
$this->createLogger($chan, $loggerId, $container);
89+
$this->createLogger($chan, $loggerId, $container, $createdLoggers);
9090
$container->getDefinition($loggerId)->setPublic(true);
9191
}
9292
$container->getParameterBag()->remove('monolog.additional_channels');
9393

9494
// wire handlers to channels
9595
$handlersToChannels = $container->getParameter('monolog.handlers_to_channels');
9696
foreach ($handlersToChannels as $handler => $channels) {
97-
foreach ($this->processChannels($channels) as $channel) {
97+
foreach ($this->processChannels($channels, $createdLoggers) as $channel) {
9898
try {
9999
$logger = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel);
100100
} catch (InvalidArgumentException $e) {
@@ -105,37 +105,29 @@ public function process(ContainerBuilder $container): void
105105
}
106106
}
107107

108-
/**
109-
* @return list<string>
110-
*/
111-
public function getChannels(): array
112-
{
113-
return $this->channels;
114-
}
115-
116-
protected function processChannels(?array $configuration): array
108+
protected function processChannels(?array $configuration, array $createdLoggers): array
117109
{
118110
if (null === $configuration) {
119-
return $this->channels;
111+
return $createdLoggers;
120112
}
121113

122114
if ('inclusive' === $configuration['type']) {
123-
return $configuration['elements'] ?: $this->channels;
115+
return $configuration['elements'] ?: $createdLoggers;
124116
}
125117

126-
return array_diff($this->channels, $configuration['elements']);
118+
return array_diff($createdLoggers, $configuration['elements']);
127119
}
128120

129121
/**
130122
* Create new logger from the monolog.logger_prototype.
131123
*/
132-
protected function createLogger(string $channel, string $loggerId, ContainerBuilder $container): void
124+
protected function createLogger(string $channel, string $loggerId, ContainerBuilder $container, array &$createdLoggers): void
133125
{
134-
if (!\in_array($channel, $this->channels, true)) {
126+
if (!\in_array($channel, $createdLoggers, true)) {
135127
$logger = new ChildDefinition('monolog.logger_prototype');
136128
$logger->replaceArgument(0, $channel);
137129
$container->setDefinition($loggerId, $logger);
138-
$this->channels[] = $channel;
130+
$createdLoggers[] = $channel;
139131
}
140132

141133
$container->registerAliasForArgument($loggerId, LoggerInterface::class, $channel.'.logger');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /