Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[DependencyInjection][FrameworkBundle] Introducing container non-empty parameters#57611
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 was wondering if we couldn't go with another API, namely a new argument to the constructor of the Parameter class?
new Parameter(string $id, string $errorOnEmpty = null)
Independently:
The name$container->requireParameter()
made me think this would be checked ahead of time, not just before it's needed. In this regard, the naming is confusing to me because any parameter is required.
We could keep both approaches at once, but is it worth it?
Looks good to me. I guess this error message would override the general one since it's more specific, right?
Yeah, I wasn’t 100% convinced about this name/method. Following your previous idea, I think that adding $container->setParamater('kernel.secret',$value,'A non-empty secret is required.');
I think so. I’ll give it a try and see |
I would not add this in Adding this in the |
I was thinking of setting it to null by default (programmatically, for BC) which maintains the current behavior. In other words, the non-empty validation will only run with a custom message if it's set. This means the third (optional) argument in
I agree, although some PHP definitions could benefit from it as well. Anyway, I'll explore that further once the initial proposal is solid. |
@yceruto but this |
yceruto commentedJul 1, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@stof I see your point. That brings me back to the current proposal of a separate method that enables this validation, no matter how/where the parameter is defined. I'm open to hearing other alternative names for |
957f908
to9ee1430
CompareI updated the proposal terminology from "require" to "non-empty". Hopefully it's clearer now. |
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.
By addressing the todo/comment below, many fixtures will be updated. Before continuing, I’d like to get confirmation that this approach is acceptable. Thanks!
Uh oh!
There was an error while loading.Please reload this page.
8e02b47
to84b3d59
Compare@symfony/mergers any objection to move forward in this direction? morechanges in PhpDumper are coming... |
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
LGTM. Minor comments only :)
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Exception/ParameterNotFoundException.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
6251ed8
to53f737d
CompareComments addressed (Windows failures look unrelated). |
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
53f737d
to22e9c87
Comparesrc/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
22e9c87
to2a3923f
Compare2a3923f
tocb7edc6
Comparecb7edc6
toeaf976a
CompareJust rebased |
Are we sure we want to use |
Agreed, IMHO, the valid "empty" parameters values could be:
WDYT? |
eaf976a
to98156f7
Compareyceruto commentedSep 18, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Agreed! I've updated it to consider only |
nicolas-grekas commentedSep 18, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'd add false personally. |
yceruto commentedSep 19, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
After reconsidering, I don’t see However, |
Thank you@yceruto. |
ce8be29
intosymfony:7.2Uh oh!
There was an error while loading.Please reload this page.
…rameters (yceruto)This PR was merged into the 7.2 branch.Discussion----------[DependencyInjection] Documenting non-empty container parametersPRsymfony/symfony#57611Closes#20233Commits-------a78ff47 documenting non-empty parameters
Uh oh!
There was an error while loading.Please reload this page.
This new iteration (following up#57462,#56985 andsymfony/recipes#1317) is about to improve the DX when we're dealing with optional parameters (this is the case for
kernel.secret
now and likely others out there) .Nicolas regarding your comment on#57462 (comment), I tried, but after some tests I realized that the impact of deprecating the
kernel.secret
is huge and, in some cases, counterproductive, as we used to reference that parameter in many configurations, seehttps://github.com/search?q=language%3APHP+%25kernel.secret%25+&type=code&p=3, which is currently a convenient way to share a config value.So I gave this new concept for container parameters a try. Basically, a non-empty parameter is one that must exist and cannot be empty (
null
,''
or[]
). It's evaluated when theParameterBag::get()
method is invoked.Additionally, we can now connect the parameter with its source by passing a custom error message with details on how to proceed if it fails, thus improving the DX.
This is what we can achieve with this feature:
when the
security_service
is initiated/used, theapp.secret
parameter will be evaluated based on the non-empty conditions. If it's missing or empty, a helpful exception message will be thrown.Before (case when it's missing):
After:
This would also address our concern about third-party services depending on the
kernel.secret
parameter whenAPP_SECRET
is empty (and thesecrets
option is disabled). In that case, even if they are not checking for empty secret value in their own, it'll fail.