-
Notifications
You must be signed in to change notification settings - Fork 29
Inject logger instance via constructor #34
Changes from 5 commits
86b40ea
d01d106
bc72b60
5f9bb1f
c488646
df8b616
6a5ff77
f629444
5304a77
814501f
77f8759
2f65872
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file, in reverse | |
|
||
### Added | ||
|
||
- [#33](https://github.com/zendframework/zend-di/pull/32) add ability to pass | ||
`Psr\Log\LoggerInterface` to `Zend\Di\CodeGenerator\InjectorGenerator`'s constructor | ||
|
||
|
||
- [#32](https://github.com/zendframework/zend-di/pull/32) adds the implementation of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note is fine as long as you aggregate it with the changes in this patch. What matters is that the reader of the release notes understands what happened. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it would be more confusing then, since it may lead people to the assumption that 3.1 introduces the Aware implementation which is actually not the case. I moved the reference to PR #32 to the Removed and Fixed entries to state clearly that this is not the case. |
||
`Psr\Log\LoggerAwareInterface` to `Zend\Di\CodeGenerator\InjectorGenerator` | ||
|
||
|
@@ -27,11 +31,13 @@ All notable changes to this project will be documented in this file, in reverse | |
|
||
### Removed | ||
|
||
- Nothing. | ||
- [#33](https://github.com/zendframework/zend-di/pull/32) removes the implementation of | ||
`Psr\Log\LoggerAwareInterface` from `Zend\Di\CodeGenerator\InjectorGenerator` | ||
|
||
### Fixed | ||
|
||
- Nothing. | ||
- [#33](https://github.com/zendframework/zend-di/pull/32) fixes discouraged use of | ||
`Psr\Log\LoggerAware*` | ||
|
||
## 3.0.1 - TBD | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
namespace Zend\Di\CodeGenerator; | ||
|
||
use Psr\Log\LoggerAwareInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
use Throwable; | ||
use Zend\Code\Generator\ClassGenerator; | ||
|
@@ -25,7 +26,7 @@ | |
* type, if available. This factory will contained pre-resolved dependencies | ||
* from the provided configuration, definition and resolver instances. | ||
*/ | ||
class InjectorGenerator implements LoggerAwareInterface | ||
class InjectorGenerator | ||
{ | ||
use GeneratorTrait; | ||
|
||
|
@@ -60,25 +61,33 @@ class InjectorGenerator implements LoggerAwareInterface | |
*/ | ||
private $autoloadGenerator; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* Constructs the compiler instance | ||
* | ||
* @param ConfigInterface $config The configuration to compile from | ||
* @param DependencyResolverInterface $resolver The resolver to utilize | ||
* @param string $namespace Namespace to use for generated class; defaults | ||
* to Zend\Di\Generated. | ||
* @param LoggerInterface $logger An optional logger instance to log failures | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, on $namespace as well ... |
||
* and processed classes. | ||
*/ | ||
public function __construct( | ||
ConfigInterface $config, | ||
DependencyResolverInterface $resolver, | ||
?string $namespace = null | ||
?string $namespace = null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an FYI: you don't need to use a nullable type here when providing a default |
||
LoggerInterface $logger = null | ||
) { | ||
$this->config = $config; | ||
$this->resolver = $resolver; | ||
$this->namespace = $namespace ? : 'Zend\Di\Generated'; | ||
$this->factoryGenerator = new FactoryGenerator($config, $resolver, $this->namespace . '\Factory'); | ||
$this->autoloadGenerator = new AutoloadGenerator($this->namespace); | ||
$this->logger = new NullLogger(); | ||
$this->logger = $logger ?? new NullLogger(); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,11 +74,10 @@ public function testGeneratorLogsDebugForEachClass() | |
{ | ||
$config = new Config(); | ||
$resolver = new DependencyResolver(new RuntimeDefinition(), $config); | ||
$generator = new InjectorGenerator($config, $resolver); | ||
$logger = $this->prophesize(LoggerInterface::class); | ||
|
||
$generator = new InjectorGenerator($config, $resolver, null, $logger->reveal()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you also change the constructor, or was it already accepting an optional logger? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the test, only. Just commited the code changes ;-) |
||
$generator->setOutputDirectory($this->dir); | ||
$generator->setLogger($logger->reveal()); | ||
$generator->generate([ | ||
TestAsset\B::class | ||
]); | ||
|
@@ -90,11 +89,10 @@ public function testGeneratorLogsErrorWhenFactoryGenerationFailed() | |
{ | ||
$config = new Config(); | ||
$resolver = new DependencyResolver(new RuntimeDefinition(), $config); | ||
$generator = new InjectorGenerator($config, $resolver); | ||
$logger = $this->prophesize(LoggerInterface::class); | ||
$generator = new InjectorGenerator($config, $resolver, null, $logger->reveal()); | ||
|
||
$generator->setOutputDirectory($this->dir); | ||
$generator->setLogger($logger->reveal()); | ||
$generator->generate([ | ||
'Bad.And.Undefined.ClassName' | ||
]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted: Double space willl be removed -> single space.