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] FixServiceSubscriberTrait for nullable service#60268

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?6.4
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 the6.4 milestoneApr 25, 2025
@StevenRenauxStevenRenaux changed the titleFixServiceMethodsSubscriberTrait for nullable service for LTs versionFixServiceMethodsSubscriberTrait for nullable service for LTS versionApr 25, 2025
@welcoMatticwelcoMattic changed the titleFixServiceMethodsSubscriberTrait for nullable service for LTS versionFixServiceSubscriberTrait for nullable service for LTS versionApr 25, 2025
@stofstof changed the titleFixServiceSubscriberTrait for nullable service for LTS versionFixServiceSubscriberTrait for nullable serviceApr 25, 2025
@carsonbotcarsonbot changed the titleFixServiceSubscriberTrait for nullable service[Contracts] FixServiceSubscriberTrait for nullable serviceApr 25, 2025
@fabpot
Copy link
Member

Thank you@StevenRenaux.

StevenRenaux reacted with thumbs up emoji

@fabpotfabpot merged commitb59a25a intosymfony:6.4Apr 30, 2025
10 of 11 checks passed
This was referencedMay 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

@mtarldmtarldmtarld approved these changes

@Jean-BeruJean-BeruJean-Beru approved these changes

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

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

7 participants
@StevenRenaux@fabpot@welcoMattic@mtarld@Jean-Beru@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp