Skip to content

Commit d802f99

Browse files
samizdamn.gnato
authored andcommitted
NullLogger as default
1 parent 06795b6 commit d802f99

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88

9+
## [4.1.1] - 2025-03-21
10+
11+
## Fixed
12+
- Inject NullLogger to LoggerAwareInterface services, when logger is not set to container
13+
914
## [4.1.0] - 2025-03-15
1015

1116
### Fixed

src/Injector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function createInstance($class): object
9191
$logger = $logger($this);
9292
}
9393
} else {
94-
$logger = $this->getService(LoggerInterface::class);
94+
$logger = $this->has(LoggerInterface::class) ? $this->getService(LoggerInterface::class) : new NullLogger();
9595
}
9696

9797
$instance->setLogger($logger);

tests/InjectorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ public function testLoggerInjection()
228228
$this->assertSame($logger, $loggerAware->getLogger());
229229
}
230230

231+
public function testLoggerInjectionWithoutSpecifiedDefaultLoggerImpl()
232+
{
233+
$injector = new Injector();
234+
$injector->enableLoggerAwareInjection(true);
235+
236+
/**@var LoggerAwareClass $loggerAware */
237+
$loggerAware = $injector->createInstance(LoggerAwareClass::class);
238+
239+
$this->assertInstanceOf(NullLogger::class, $loggerAware->getLogger());
240+
}
241+
231242
public function testLoggerMap()
232243
{
233244
$logger = new NullLogger();

0 commit comments

Comments
 (0)