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

[Contracts] FixServiceMethodsSubscriberTrait for nullable service#60267

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

Conversation

StevenRenaux
Copy link
Contributor

QA
Branch?7.2
Bug fix?yes
New feature?no
Deprecations?no
LicenseMIT

Used in a bundle context.

If you use the following example, you will get an exception:
ServiceNotFoundException: The service "twig" in the container provided to "App\Service\Dependency" has a dependency on a non-existent service "Twig\Environment".

Thenullable argument of theSubscribedService attribute is ignored.

// src/Service/TwigAware.phpnamespaceApp\Service;useTwig\Environment;useSymfony\Contracts\Service\Attribute\SubscribedService;trait TwigAware{   #[SubscribedService('twig', nullable:true)]privatefunctiontwig():Environment    {if (!$this->container->has('twig') ) {thrownew \LogicException(\sprintf('Twig is required to use "%s" method. Try to run "composer require symfony/twig-bundle".',__METHOD__));        }return$environment;    }}// src/Service/MyService.phpnamespaceApp\Service;useSymfony\Contracts\Service\ServiceSubscriberInterface;useSymfony\Contracts\Service\ServiceSubscriberTrait;class MyServiceimplements ServiceSubscriberInterface{use ServiceSubscriberTrait, TwigAware;publicfunctiondoWithTwig():void    {// $this->twig() ...    }}

Related to#60265

@carsonbotcarsonbot added this to the7.2 milestoneApr 25, 2025
@StevenRenauxStevenRenauxforce-pushed thefix/Fix-nullable-argument-for-SubscribedService-attribute branch from1a9c3a2 to7d7e4a0CompareApril 25, 2025 09:12
@StevenRenauxStevenRenauxforce-pushed thefix/Fix-nullable-argument-for-SubscribedService-attribute branch 2 times, most recently fromdb4b606 to562600fCompareApril 25, 2025 09:33
@StevenRenauxStevenRenauxforce-pushed thefix/Fix-nullable-argument-for-SubscribedService-attribute branch from562600f toe67db9aCompareApril 25, 2025 09:37
@stof
Copy link
Member

#60268 should be merged first and upmerged to 7.2, so that this PR can then be only about the new things for 7.2

welcoMattic reacted with thumbs up emoji

@carsonbotcarsonbot changed the titleFixServiceMethodsSubscriberTrait for nullable service[Contracts] FixServiceMethodsSubscriberTrait for nullable serviceApr 25, 2025
@StevenRenaux
Copy link
ContributorAuthor

StevenRenaux commentedApr 25, 2025
edited
Loading

#60268 should be merged first and upmerged to 7.2, so that this PR can then be only about the new things for 7.2

@stof
I'm agree but since 6.4 the tests about ServiceSubscriberTraits was updated, you can see with LegacyParentTestService. Or we need to updated it after the merge.

Let me know

@stof
Copy link
Member

@StevenRenaux I'm not saying this PR is useless. This PR should be updated after the upmerge (which will happen anyway)

StevenRenaux reacted with thumbs up emoji

Copy link
Member

@welcoMatticwelcoMattic left a comment

Choose a reason for hiding this comment

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

As@stof said, this one must be rebased after merge (and upmerge) of#60268.
Otherwise, it's 👍 for me

StevenRenaux reacted with thumbs up emoji
@fabpot
Copy link
Member

Thank you@StevenRenaux.

@fabpotfabpot merged commit070869c intosymfony:7.2Apr 30, 2025
11 checks passed
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot approved these changes

@welcoMatticwelcoMatticwelcoMattic approved these changes

@nicolas-grekasnicolas-grekasAwaiting requested review from nicolas-grekas

Assignees
No one assigned
Projects
None yet
Milestone
7.2
Development

Successfully merging this pull request may close these issues.

6 participants
@StevenRenaux@stof@fabpot@welcoMattic@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp