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][FrameworkBundle] Fix using PHP 8.1 enum as parameters#44868

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
nicolas-grekas merged 0 commits intosymfony:4.4fromogizanagi:enum-di-parameters
Feb 4, 2022

Conversation

@ogizanagi
Copy link
Contributor

@ogizanagiogizanagi commentedDec 30, 2021
edited
Loading

QA
Branch?4.4
Bug fix?yesish
New feature?no
Deprecations?no
TicketsFix#44834
LicenseMIT
Doc PRN/A

While#40857 allowed using enums in DI, it does not allow using these in parameters.

This would be the actual fix for#44834, which shows the error you'll get trying to use enum as DI parameters (appart from the binding issue fixed in#44838):

image

given:

namespaceApp;enum Status {case Draft;case Deleted;case Published;}
# services.yamlparameters:default_status:!php/const App\Status::Draft

The exception happens because thePhpDumper misses the leading slash:

    protected function getDefaultParameters(): array    {        return [-            'default_status' => App\Status::Draft,+            'default_status' => \App\Status::Draft,        ];    }

While this would fix using enums as DI parameters as of Symfony < 6,
theParameterBagInterface::get/set andContainerInterface::setParameter/getParameter are not allowing\UnitEnum and adding these in phpdoc is an issue since actual typehints and return types were added as of Symfony 6.
=> So this PR is a BC break, but hopefully nobody will be hit by it 🤞🏻

(poke@ismail1432 -
https://twitter.com/SmaineDev/status/1476237072826613763?s=20)

ismail1432 and juuuuuu reacted with thumbs up emoji
@carsonbotcarsonbot added this to the4.4 milestoneDec 30, 2021
@ogizanagiogizanagi added the RFCRFC = Request For Comments (proposals about features that you want to be discussed) labelDec 30, 2021
@derrabus
Copy link
Member

Either way, allowing enums in parameters would be a new feature. I don't think we should add that functionality to 4.4.

@ogizanagi
Copy link
ContributorAuthor

I kind of agree, despite#40857 being on 4.4. But the difference is parameters never supported objects.
So let's make that clear by throwing in 4.4 and see what we can do/if we want to support enum in parameters later?

derrabus reacted with thumbs up emoji

@derrabus
Copy link
Member

Sounds good. 🙂

@nicolas-grekas
Copy link
Member

How do we move forward on this one?

@ogizanagi
Copy link
ContributorAuthor

Sorry, didn't have time to go further. The plan was to throw either in theParameterBag or thePhpDumper so that's explicit enum types are not supported as parameters ; since it even goes against theParameterBagInterface::get/set contract.

derrabus reacted with thumbs up emoji

@ogizanagiogizanagi removed the RFCRFC = Request For Comments (proposals about features that you want to be discussed) labelJan 12, 2022
@ogizanagiogizanagi changed the title[DependencyInjection] Fix using PHP 8.1 enum as parameters[DependencyInjection] Throw on attempting to set enum parametersJan 26, 2022
@ogizanagiogizanagiforce-pushed theenum-di-parameters branch 2 times, most recently from2a73c69 tod2bea6aCompareJanuary 26, 2022 09:58
@ogizanagi
Copy link
ContributorAuthor

Updated the PR so that we simply throw on attempting to set an enum or array containing an enum as a DI parameter : this should be enough for our goal: explicit the fact enums aren't supported as such.
Of course, the phpdoc already tells this, and we won't check for any other infringement to it ; but since the DI loaders allow such a thing indirectly:

# services.yamlparameters:default_status:!php/const App\Status::Draftstatuses:         -!php/constApp\Status::Draft        -!php/constApp\Status::Deleted        -!php/constApp\Status::Published

we might want to handle this specific case here so the user notices it.

ismail1432 reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedJan 28, 2022
edited
Loading

I'm sorry I'm not super convinced by this. It would be strange to me to allow direct references to enums in service arguments, but to disallow indirect references via DI parameters:

parameters:foo:!php/const Some\Enum::Caseservices:bar:['%foo%']

I'd prefer to fix supporting them when dumping, and widen the types on 6.0. I don't think anybody is going to be hit by the BC break.

ogizanagi, chalasr, yceruto, and ismail1432 reacted with thumbs up emoji

@ogizanagi
Copy link
ContributorAuthor

Honestly, I'd be way more satisfied this way too :)
I'll revert to the previous state of this PR.

@ogizanagiogizanagi changed the title[DependencyInjection] Throw on attempting to set enum parameters[DependencyInjection] Fix using PHP 8.1 enum as parametersJan 31, 2022
@carsonbotcarsonbot changed the title[DependencyInjection] Fix using PHP 8.1 enum as parameters[DependencyInjection][FrameworkBundle] Fix using PHP 8.1 enum as parametersJan 31, 2022
@ogizanagiogizanagiforce-pushed theenum-di-parameters branch 3 times, most recently from5a18657 to4eaf136CompareJanuary 31, 2022 18:18
@ogizanagi
Copy link
ContributorAuthor

Alright, PR updated. Hopefully I haven't missed anything.

@ogizanagiogizanagiforce-pushed theenum-di-parameters branch 4 times, most recently fromf0acb77 toda3f323CompareFebruary 1, 2022 12:56
@fabpot
Copy link
Member

We stopped adding new features for supporting newer PHP versions a while ago, so this is a new feature that should go into 6.1.

@nicolas-grekas
Copy link
Member

This is edgy, but after a private chat with@fabpot, I've got a go for merging. Now doing it.

derrabus, ogizanagi, chalasr, and t-richard reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

Thank you@ogizanagi.

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

@derrabusderrabusderrabus approved these changes

@chalasrchalasrchalasr approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

6 participants

@ogizanagi@derrabus@nicolas-grekas@fabpot@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp