-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] [POC] Introduce build parameters #47608
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't finish my review but I'm wondering: instead of adding new methods, wouldn't it be better and simpler to have a naming convention for build-time parameters? My proposal would be to consider that any parameter who's name starts with a dot will removed from the compiled container.
parameters:
.abc: def
* | ||
* @var array<string, false> | ||
*/ | ||
public array $buildParameters = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better have a getter, no need to make it internal
|
||
public function removeParameter(string $parameter): void | ||
{ | ||
$this->parameterBag->remove($parameter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the removeParamter method I suppose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, for DX purpose this could be a dedicated PR if needed.
@@ -259,7 +259,15 @@ class %s extends {$options['class']} | |||
foreach ($ids as $id) { | |||
$c .= ' '.$this->doExport($id)." => true,\n"; | |||
} | |||
$files['removed-ids.php'] = $c."];\n"; | |||
$files['removed-service-ids.php'] = $c."];\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd keet the current name and name the new one removed-parameters.php
I considered it, but I'm worried about potential BC breaks this could cause. |
Might be worth adding some global config option or DI parameter as we did for the autowiring' strict mode? |
I'm not sure if I prefer convention over an explicit option. And needing an explicit option to turn on a convention in order to use this feature seems even less than ideal to me :) |
The BC break seems theoretical to me. I think that's still my preferred solution and how I'd like this topic be solved. |
See #47680 for the suggested implementation. |
Thanks. Closing in favor of #47680 |
…meters (HeahDude) This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [DependencyInjection][HttpKernel] Introduce build parameters | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | ~ | License | MIT | Doc PR | TODO Alternative implementation of #47608. Add a convention for parameters named with a starting dot to be available at compile-time only: ```php $containerBuilder->setParameter('foo'); // nothing changes $containerBuilder->setParameter('.bar'); // will not be dumped ``` Calling `$container->getParameter('.bar')` on a compiled container will throw. Commits ------- c75dbca [DependencyInjection][HttpKernel] Introduce build parameters
We miss a way to optimise dumped container with compile-time only parameters, or ability to remove them in a straightforward/easy to discover way: