-
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
Add container compilation #218
Conversation
… find out if a parameter is variadic
…dInstance to ContainerBuilder
This PR leaves one final question, at least for me, how to scan classes for attributes? Should we add such an attribute scanner? Which one is used by other projects? Or does each framework has its own scanner? @koriym How are you solving that in your project? |
@frederikbosch BEAR.Sunday needed to support a mix of doctrine/annotations and PHP8 attributes, so I created Koriym.Attribute. (Mentioned in PHP Annotated - 2022 Spring ) The attribute read part is very simple. https://github.com/koriym/Koriym.Attributes/blob/1.x/src/AttributeReader.php#L87-L93 |
I have no idea on this. May be want to look into other compiler DI . Also please do look into the recent discussions on the php-fig regarding compiled container. |
4c18d26
to
c5c7176
Compare
I removed the comments I made earlier on. The solutions have been simplified significantly. When the Furthermore, the documentation contains:
|
7d6ef5b
to
5acc9bf
Compare
I renamed |
A goal of compiling the container, is that reflection does not need to be used anymore after compilation. A compiled container knows all the object meta information to resolve/construct objects. It has only one task left: instantiating new instances.
Therefore, before creating the container compiler, we need to make sure reflection is not a requirement after unification of objects, which is a process inside
Resolver
. This PR will change two things.Blueprint
class constructs new objects, but used reflection to do so. From now on, it will usenew $className
.expandParams
call inResolver
will be moved to theBlueprint
because it is part of the object construction. The method also used reflection to determine whether a parameter is variadic. From now on, theBlueprint
knows all parameters of an object with itsparameter settings
, including if it is variadic or not. This removes another need for reflection during object construction.And finally, this PR adds the feature of container compilation. All objects that are added through
$di->params
,$di->setters
and$di->mutations
, plus extra objects that can be passed, are compiled into blueprints.After this PR is merged, a container might be constructed as follows.