Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] Fix support for unions/intersections together withServiceSubscriberInterface#43930

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@kbond
Copy link
Member

@kbondkbond commentedNov 4, 2021
edited by nicolas-grekas
Loading

QA
Branch?5.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

Continuation of#43479 perdiscussion with@nicolas-grekas.

Todo:

  • intersection type support/tests
  • ServiceSubscriberTrait support

@carsonbotcarsonbot added this to the5.4 milestoneNov 4, 2021
@carsonbotcarsonbot changed the title[WIP][DependencyInjection] Enable union/intersect services inServiceSubscriberInterface[DependencyInjection] [WIP] Enable union/intersect services inServiceSubscriberInterfaceNov 4, 2021
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we'll also need to filter out any built-in types from union types, and to order the list of types for both union and intersection types.
We could do this in AutowirePass, when TypedReference are wired

@kbondkbondforce-pushed theservice-subscriber-union branch from662c282 to81cd56fCompareNovember 4, 2021 16:00
@kbond
Copy link
MemberAuthor

I think we'll also need to filter out any built-in types from union types, and to order the list of types for both union and intersection types.
We could do this in AutowirePass, when TypedReference are wired

Sorry, I'm quite out of my element here. I'm not sure how/where to do this.

@nicolas-grekas
Copy link
Member

Using pseudo-code, this is what is missing to me:

--- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php+++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php@@ -100,7 +100,7 @@ class AutowirePass extends AbstractRecursivePass     private function doProcessValue(mixed $value, bool $isRoot = false): mixed     {         if ($value instanceof TypedReference) {-            if ($ref = $this->getAutowiredReference($value)) {+            if ($ref = $this->getAutowiredReference($value, true)) {                 return $ref;             }             if (ContainerBuilder::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {@@ -291,7 +291,7 @@ class AutowirePass extends AbstractRecursivePass             }              $getValue = function () use ($type, $parameter, $class, $method) {-                if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE, Target::parseName($parameter)))) {+                if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE, Target::parseName($parameter)), false)) {                     $failureMessage = $this->createTypeNotFoundMessageCallback($ref, sprintf('argument "$%s" of method "%s()"', $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));                      if ($parameter->isDefaultValueAvailable()) {@@ -346,7 +346,7 @@ class AutowirePass extends AbstractRecursivePass     /**      * Returns a reference to the service matching the given type, if any.      */-    private function getAutowiredReference(TypedReference $reference): ?TypedReference+    private function getAutowiredReference(TypedReference $reference, bool $filterType): ?TypedReference     {         $this->lastFailure = null;         $type = $reference->getType();@@ -355,6 +355,13 @@ class AutowirePass extends AbstractRecursivePass             return $reference;         }+        if ($filterType) {+            if (is_union_type($type)) {+                $type = remove_builtin_types($types);+            }+            $types = sort_types_in_union_or_intersection($types);+        }+         if (null !== $name = $reference->getName()) {

@nicolas-grekas
Copy link
Member

And we'll also need a change on this line, since the leading\ will be missing in union/intersect lists:

$returnedType =sprintf(': %s\%s', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >=$value->getInvalidBehavior() ?'' :'?',$value->getType());

Addingstr_replace(['|', '&'], ['|\\', '&\\'], ...) around the call togetType() should do it.

@kbond
Copy link
MemberAuthor

Thank you, I've added the requested code. Still not sure how to test this.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

thanks, we're almost done :)
can you try adding a few test cases that involve AutowirePass?

@nicolas-grekasnicolas-grekas changed the title[DependencyInjection] [WIP] Enable union/intersect services inServiceSubscriberInterface[DependencyInjection] Fix support for unions/intersections together withServiceSubscriberInterfaceNov 6, 2021
@nicolas-grekasnicolas-grekas added Bug and removed Feature labelsNov 6, 2021
@nicolas-grekas
Copy link
Member

Thank you@kbond.

@nicolas-grekasnicolas-grekas merged commit63f5e27 intosymfony:5.4Nov 6, 2021
@kbondkbond deleted the service-subscriber-union branchNovember 6, 2021 12:35
This was referencedNov 14, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

3 participants

@kbond@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp