-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Add type-hints to interfaces and implementations. #32266
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
[DependencyInjection] Add type-hints to interfaces and implementations. #32266
Conversation
d3df351
to
4342375
Compare
@@ -51,7 +48,7 @@ public function set($id, $service); | |||
* | |||
* @see Reference | |||
*/ | |||
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE); | |||
public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE); |
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: We cannot add string $id
because we would violate the PSR interface otherwise.
4342375
to
1b401f9
Compare
1b401f9
to
f421681
Compare
f421681
to
13099b9
Compare
…getInEdges()/getOutEdges() (derrabus) This PR was merged into the 3.4 branch. Discussion ---------- [DependencyInjection] Annotated correct return type for getInEdges()/getOutEdges() | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A This changed annotation was quite helpful when analyzing `PhpDumper` for #32266. Commits ------- 28882f5 Annotated correct return type for getInEdges()/getOutEdges().
@@ -1334,7 +1336,7 @@ public function getParameterBag() | |||
|
|||
EOF; | |||
if (!$this->asFiles) { | |||
$code = preg_replace('/^.*buildParameters.*\n.*\n.*\n/m', '', $code); | |||
$code = preg_replace('/^.*buildParameters.*\n.*\n.*\n\n?/m', '', $code); |
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.
Should be reverted as it does not look related to the purpose of this PR, is it?
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 class generates implementations of the ContainerInterface
that has been changed with this PR. This is why I've adjusted the code template above to add the new type declarations and remove the now-obsolete type cast.
This preg_replace
call removes an if
block from the generated code under certain circumstances. Because I've removed the type cast, this operation would leave an empty line at the beginning of the method, like this:
public function hasParameter(string $name)
{
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
I've adjusted the regular expression, so that this extra new line is also removed in case its there.
9a63519
to
492df5e
Compare
src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/ShareTrait.php
Show resolved
Hide resolved
There are still several uneccessary string casts left, e.g.
|
492df5e
to
d44d0a1
Compare
There seems to be something wrong in the failing tests testBindScalarValueToControllerArgument and testRegistersTraceableBusesToCollector |
I'll look into it. |
…tances as class name to Definition (derrabus) This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Deprecated passing Parameter instances as class name to Definition | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #32279 | License | MIT | Doc PR | N/A This PR deprecates the undocumented possibility to use a `Parameter` instance instead of a string as class name for a `Definition`. This was discovered while working on #32266. Commits ------- edfc9d6 Deprecated passing Parameter instances as class name to Definition.
d44d0a1
to
d45497b
Compare
All right, so the failing test assumes that a service can be a scalar value. Line 348 in 6811aaa
All docblocks on the DI classes and interfaces however promise me that services are always objects.
I trusted these docblocks and used I'm unsure if scalar services should be a thing, but they're possible at the moment, at least to a certain degree. In order to move forward here, I'll remove the |
According to PSR-11 it could also be a scalar value.
But that seems strange and not the original contract of the symfony container. Also parameters are not fetched individually from the container but through a ParameterBag in Symfony which makes more sense to me. |
d45497b
to
68f9f27
Compare
The remaining failing tests are unrelated to my changes. Status: Needs Review |
Follow-up issue: #32411 |
Thank you @derrabus. |
…mplementations. (derrabus) This PR was merged into the 5.0-dev branch. Discussion ---------- [DependencyInjection] Add type-hints to interfaces and implementations. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A Part II for DependencyInjection, concentrating on the main interfaces, `ContainerBuiler` and related classes. Commits ------- 68f9f27 [DependencyInjection] Add type-hints to interfaces and implementations.
Part II for DependencyInjection, concentrating on the main interfaces,
ContainerBuiler
and related classes.