Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [4.1.1] - 2025-03-21

## Fixed
- Inject NullLogger to LoggerAwareInterface services, when logger is not set in container

## [4.1.0] - 2025-03-15

### Fixed
Expand Down Expand Up @@ -125,7 +130,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- All classes.

[Unreleased]: https://github.com/FreeElephants/php-di/compare/4.1.0...HEAD
[Unreleased]: https://github.com/FreeElephants/php-di/compare/4.1.1...HEAD
[4.1.1]: https://github.com/FreeElephants/php-di/compare/4.1.0...4.1.1
[4.1.0]: https://github.com/FreeElephants/php-di/compare/4.0.1...4.1.0
[4.0.1]: https://github.com/FreeElephants/php-di/compare/4.0.0...4.0.1
[4.0.0]: https://github.com/FreeElephants/php-di/compare/3.1.1...4.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function createInstance($class): object
$logger = $logger($this);
}
} else {
$logger = $this->getService(LoggerInterface::class);
$logger = $this->has(LoggerInterface::class) ? $this->getService(LoggerInterface::class) : new NullLogger();
}

$instance->setLogger($logger);
Expand Down
11 changes: 11 additions & 0 deletions tests/InjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ public function testLoggerInjection()
$this->assertSame($logger, $loggerAware->getLogger());
}

public function testLoggerInjectionWithoutSpecifiedDefaultLoggerImpl()
{
$injector = new Injector();
$injector->enableLoggerAwareInjection(true);

/**@var LoggerAwareClass $loggerAware */
$loggerAware = $injector->createInstance(LoggerAwareClass::class);

$this->assertInstanceOf(NullLogger::class, $loggerAware->getLogger());
}

public function testLoggerMap()
{
$logger = new NullLogger();
Expand Down