-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5.x with attribute injection #210
Conversation
@frederikbosch I think @koriym has done something like this with https://github.com/bearsunday/BEAR.Sunday -- if you have not asked him already, he may have insight/warnings/recommendations here. |
@pmjones Thanks for brining this to my attention. I found the manual of Ray.Di. After having a look at that packages, I think I am going to add the possibility for client users to create their own attributes. They have upfront knowledge of their own codebase, and hence they could create specific injections. use MyApp\Config\Attribute\Config;
class ApiConnection
{
public function __construct(
#[Config('api.key')]
private string $key,
) {
}
} Then the attribute would result in the following call: /** @var MyApp\Config\Bag $config */
$config = $di->get('config');
$config->get('api.key'); Basically, in this case, it creates an advanced Also, I could consider setter injection in a similar manner as Ray.Di. First, annotate the method with Finally, I don't think the attributes have to implemented feature complete. When we would release a 5.0, there is always a possibility for adding features in a 5.1 release. |
@frederikbosch First of all, let me tell you that Ray.Di and its manual is a clone of Google Guice with almost all of its features. My few design decisions are limited to removing property injection, which was also controversial in Guice.
This is a very good idea! Creating a custom class is more self explanatory and you can make the custom class the place of the documentation; even Guice recommends custom annotations over |
Thanks for your input @koriym. It confirms I am taking the right direction: keep the included attributes easy and small. People can always create their own attributes for more specific use cases. And for the naming of the attributes, I try to stay close to terminology that has always been used in this package. I thought of using |
Next to the attributes, there have been four major changes.
// old code
new Container(new InjectionFactory(new Resolver(new Reflector())));
// new code
new Container(new Resolver(new Reflector()));
|
I would suggest to accept this code and set 5.x as the default branch. Then I will continue with the other plans I have created for 5.x. |
…in for quite a while now
Don't we need to change the branch to 5.x ? |
drop psr/container 1.x
Drop sec advisories
Add support for PHPUnit 10
I think this PR is just demonstrating the changes in 5.x to 4.x . So no need for merge. Regarding review, I think @koriym is the best person for this. In case if I have any thoughts I will write here. Thanks again for your wonderful work. |
LGTM. (I think it is good that you only support constructor injection for a start.) However, it seems that some phpdoc changes have not kept up with the code changes - why not check the IDE or use psalm/phpstan to make corrections? Thanks for your wonderful work. |
@@ -47,10 +49,10 @@ class LazyGet implements LazyInterface | |||
* @param string $service The service to retrieve. | |||
* | |||
*/ | |||
public function __construct(ContainerInterface $container, $service) | |||
public function __construct(string $service, ?ContainerInterface $delegatedContainer = 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.
PHPDoc needs to be modified.
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 are several others.
I thought so too. Why not "draft pull request" then? |
Good idea to include phpstan, will do that and fix the docblocks. |
We dropped PHP 7.x, so we don't need |
Great idea to remove it, see #217 |
Design choices:
->params[FakeConstructAttributeClass::class]['fakeService'] = ...
will overwrite the attribute.Limitations:
params
to#[Instance]
attributes. If you want to overwrite constructor parameters of an injected instance, you would have to change to an#[Service]
attribute or reside to inject by code.params
to#[Service('service', 'method')]
attributes. You would have to reside to the method using code, or define an additional service and then use#[Service('new.service)]
.I will continue with the implementation if there is no objection towards this direction. I will take at least a week before continuing.