-
Notifications
You must be signed in to change notification settings - Fork 29
Inject logger instance via constructor #34
Inject logger instance via constructor #34
Conversation
.gitignore
Outdated
@@ -5,3 +5,4 @@ | |||
/vendor/ | |||
/zf-mkdoc-theme.tgz | |||
/zf-mkdoc-theme/ | |||
/.idea |
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.
Please don't mind this change, it will be reverted when I complete the PR
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.
👍
.gitignore
Outdated
@@ -5,3 +5,4 @@ | |||
/vendor/ | |||
/zf-mkdoc-theme.tgz | |||
/zf-mkdoc-theme/ | |||
/.idea |
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.
👍
$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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This was the test, only. Just commited the code changes ;-)
CHANGELOG.md
Outdated
- [#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 comment
The 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 comment
The 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 comment
The 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.
CHANGELOG.md
Outdated
- [#33](https://github.com/zendframework/zend-di/pull/32) add ability to pass | ||
`Psr\Log\LoggerInterface` to `Zend\Di\CodeGenerator\InjectorGenerator`'s constructor | ||
|
||
|
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.
Just for the records: I chose the Aware implementation of PSR-3 since it is aliving PSR standard and it states a purely optional dependency that does not affect the classes core behaviour. But aware implementations are discouraged. Since this was already discussed - it will be removed without further arguing. (@Ocramius a ref would be awesome, if you got it at hand). @Ocramius just two things to prevent this in the future and reference potential PR's to this:
|
Removed the added note since it might lead to confusion to the reader and moved the ref to PR zendframework#23 to the Removed and Fixed section which states more clearly what happened
Minor issue, given the interface stability
Always discouraged. Only ever use traits in tests, as any downstream users may also use them and therefore we increase the BC surface by A LOT.
This is the bigger issue - there is no need to expose that, as it is an internal implementation detail. Also, dependencies should not be mutable, and the |
The existence of the setter is actually the bigger issue here. |
Thanks a lot for the clearification. 👍
The internal use only, could be stated with an "internal" annotation, but I got your point. Even though it was marked internal someone will use it and blame the framework when the trait changes. I'll open a PR removing remaining traits in this component (but this will be low prio). By now no more introduction of new traits.
Even though it is not an actual dependency, more a utility aggregation (the generator's functionality itself does not actually depend on a logger)? I find this a bit too dogmatic, but I'm fine with cutting this. edit: thank's github for mentioning internal ... |
/** | ||
* 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null
type in php doc.
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.
Correct, on $namespace as well ...
CHANGELOG.md
Outdated
- Nothing. | ||
- [#33](https://github.com/zendframework/zend-di/pull/32) removes the implementation of | ||
`Psr\Log\LoggerAwareInterface` from `Zend\Di\CodeGenerator\InjectorGenerator` that | ||
was introduced with [#32](https://github.com/zendframework/zend-di/pull/32) |
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.
I think we should remove it, because #32 is not going to be released, because this PR replaces it. The same in Fixed
section.
Notes in Added
section are enough. But this is my option and maybe I am wrong?
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.
I agree, in fact I was a bit unsure about it. I'd like to remove these entries for the same reason.
@Ocramius any objections?
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.
I agree with @webimpress. Instead, note that #32 and #34 provide the ability to log generator processing, and give a short example of how that can be enabled.
@Ocramius since you brought this up: Can you please approve? |
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.
LGTM 👍
Surround annotation markings with code markers to avoid that: |
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.
Looks good; I've noted a few documentation/changelog changes.
Also: I think marking any traits developed for internal purposes with an @internal
class-level annotation is reasonable. That can be done later, though.
CHANGELOG.md
Outdated
- Nothing. | ||
- [#33](https://github.com/zendframework/zend-di/pull/32) removes the implementation of | ||
`Psr\Log\LoggerAwareInterface` from `Zend\Di\CodeGenerator\InjectorGenerator` that | ||
was introduced with [#32](https://github.com/zendframework/zend-di/pull/32) |
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.
I agree with @webimpress. Instead, note that #32 and #34 provide the ability to log generator processing, and give a short example of how that can be enabled.
CHANGELOG.md
Outdated
|
||
### Fixed | ||
|
||
- Nothing. | ||
- [#33](https://github.com/zendframework/zend-di/pull/32) fixes discouraged use of | ||
`Psr\Log\LoggerAware*` that was introduced with [#32](https://github.com/zendframework/zend-di/pull/32) |
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.
No need to add this here, as it was never previously released.
docs/book/codegen.md
Outdated
The `InjectorGenerator` implements the PSR-3 [`LoggerAwareInterface`](http://www.php-fig.org/psr/psr-3/#4-psrlogloggerawareinterface). | ||
So you can pass any PSR-3 logger to its `setLogger()` method. | ||
The `InjectorGenerator` allows to pass a [PSR-3 logger](http://www.php-fig.org/psr/psr-3/) as optional | ||
fourth construction parameter. |
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.
Rephrase:
The
InjectorGenerator
allows passing a PSR-3 logger instance via an optional, fourth constuctor parameter.
*/ | ||
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 comment
The 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 null
value. (Something @webimpress demonstrated to me recently.)
Now I'm confused again. Since #34 is replacing #32, I'd just remove the refs to #32.
In the changelog? I'd just place a constructor example, would that be sufficient? Maybe it's too late and I should finish for today, and you can enlighten me tomorrow in the slack channel. |
Just note whatever PRs led to the logger capabilities; I may be a bit fuzzy on which ones to use. 😄
Perfect! |
Typehints of parameters, that have a default value of `null` do not have to be marked nullable explicitly, i.e. `?string` can be just `string`.
@weierophinney I incorporated the resquested changes. I also changed the title of this PR to reflect what was actually changed. Can you approve, please? |
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.
I've noted a slight rephrase of the changelog entry, but you can do that on merge.
Looks great! 👍
- [#32](https://github.com/zendframework/zend-di/pull/32) adds the implementation of | ||
`Psr\Log\LoggerAwareInterface` to `Zend\Di\CodeGenerator\InjectorGenerator` | ||
- [#34](https://github.com/zendframework/zend-di/pull/34) adds ability to pass | ||
`Psr\Log\LoggerInterface` to `Zend\Di\CodeGenerator\InjectorGenerator`'s constructor |
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.
Rephrase slightly:
... adds the ability to pass a
Psr\Log\LoggerInterface
instance to the constructor ofZend\Di\CodeGenerator\InjectorGenerator
Inject logger instance via constructor
PR #32 introduces logging capabilities by the use of an "Aware" interface (
LoggerAwareInterface
of PSR-3). This is discouraged in ZF.This pull request changes it to constructor injection and removes the introduced usage of Aware.
Since this fixes a violation that only exists in the develop branch, this PR is targeted against develop instead of master.
Are you fixing a bug?
CHANGELOG.md
entry for the fix.Is this related to quality assurance?
As stated by @Ocramius in PR Add Logging To Code Generators (WIP) #32, the usage of aware-interfaces are discouraged throughout the Framework