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] Accessing processed extension configs#48408

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

Closed

Conversation

@yceruto
Copy link
Member

QA
Branch?6.3
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PRTODO

This proposal adds a new container parameter.extension.processed_configs that holds all processed extension configs from all registered extensions in order to improve the DX during the DI compilation phase (load extension, compiler pass).

Before

Currently, it's not possible to access processed configs, so this new parameter will avoid unsafely and hacking workarounds just to query a config value that belongs to another (already processed) extension and derives some DI definitions from it.

Some workarounds involve:

  • Collect extension configs during the "prepend extension" phase (even if other extensions can prepend more config after)
  • Duplicated configs with similar meanings in two or more extensions
  • Call/override theprocessConfiguration() method from another extension is forbidden as it's protected and final, meaning you'll have to process twice this config outside the extension owner.
  • Useless container parameters have to be defined to pass config information from "prepend" to "load" or/and from "load" to "compiler passes".

After

With this proposal, you'll access these configs through the.extension.processed_configs parameter. It's an array of extensions configs, where the array key matches the extension alias:

class AppExtensionextends AbstractExtension{publicfunctionloadExtension(array$config,ContainerConfigurator$container,ContainerBuilder$builder):void    {$processedConfigs =$builder->getParameter('.extension.processed_configs');// $processedConfigs['framework']    }}

Note that inload orloadExtension you have access only to already loaded extensions depending on the extension/bundle definition order. If you need access to other extension configs that are not loaded yet then move your logic to a compiler pass or change the bundle/extension order in thebundle.php file of your project.

Also available in any compiler pass with the capability to resolve env placeholders:

class AppCompilerPassimplements CompilerPassInterface{publicfunctionprocess(ContainerBuilder$container):void    {$processedConfigs =$container->getParameter('.extension.processed_configs');$processedConfigs =$container->resolveEnvPlaceholders($processedConfigs,true);// $processedConfigs['framework']    }}

After merging#47680 this.extension.processed_configs parameter is considered a "build parameter" finally, so it will be used during compiler time only and will be removed at the end of the process.

@carsonbotcarsonbot added Status: Needs Review DependencyInjection DXDX = Developer eXperience (anything that improves the experience of using Symfony) Feature labelsNov 30, 2022
@carsonbotcarsonbot added this to the6.3 milestoneNov 30, 2022
@carsonbotcarsonbot changed the title[DX][DependencyInjection] Accessing to processed extension configs[DependencyInjection] Accessing to processed extension configsNov 30, 2022
@ycerutoycerutoforce-pushed theextension_processed_config branch from9a47590 to6be13c9CompareNovember 30, 2022 14:20
@OskarStark
Copy link
Contributor

Regarding the PR headline

- [DependencyInjection] Accessing to processed extension configs+ [DependencyInjection] Accessing processed extension configs
yceruto reacted with thumbs up emoji

@stof
Copy link
Member

Big -1 for this, as it means that the structure of the processed config becomes a public API covered by BC, making it impossible to refactor the config anymore, while the Configuration class is currently the perfect tool to provide a BC layer for the config structure (converting old structure into the new structure expected by the extension).

ogizanagi, yceruto, and dmaicher reacted with thumbs up emoji

@stof
Copy link
Member

stof commentedNov 30, 2022
edited
Loading

Another -1 is that you expose that parameter with a partial value to DI extensions, making them very sensible to the bundle loading order. Currently, each DI extension receives a dedicated ContainerBuilder that has none of the services defined by other bundles precisely to reduce the risk of implementing something in the DI extension that should be done in a compiler pass instead to allow collecting services from any other bundle.

Note that the early preview versions of Symfony 2.0 did not have this isolation layer, and it caused lots of issues for early adopters when doing stuff in DI extensions instead of implementing a compiler pass. So we have implementation experience proving that it is a bad architecture (making it easier to write broken code than correct code).

yceruto and dmaicher reacted with thumbs up emoji

@ycerutoyceruto changed the title[DependencyInjection] Accessing to processed extension configs[DependencyInjection] Accessing processed extension configsNov 30, 2022
@yceruto
Copy link
MemberAuthor

Fair enough, thanks for the feedback.

@ycerutoyceruto closed thisDec 4, 2022
@ycerutoyceruto deleted the extension_processed_config branchDecember 4, 2022 19:01
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

DependencyInjectionDXDX = Developer eXperience (anything that improves the experience of using Symfony)FeatureStatus: Needs Review

Projects

None yet

Milestone

6.3

Development

Successfully merging this pull request may close these issues.

4 participants

@yceruto@OskarStark@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp