-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[DependencyInjection][FrameworkBundle] Introducing container non-empty parameters #57611
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 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 |
@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
to
9ee1430
Compare
I 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!
8e02b47
to
84b3d59
Compare
@symfony/mergers any objection to move forward in this direction? more changes in PhpDumper are coming... |
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 :)
src/Symfony/Component/DependencyInjection/Exception/ParameterNotFoundException.php
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php
Outdated
Show resolved
Hide resolved
6251ed8
to
53f737d
Compare
Comments addressed (Windows failures look unrelated). |
src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php
Outdated
Show resolved
Hide resolved
53f737d
to
22e9c87
Compare
src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php
Show resolved
Hide resolved
22e9c87
to
2a3923f
Compare
2a3923f
to
cb7edc6
Compare
cb7edc6
to
eaf976a
Compare
Just rebased |
Are we sure we want to use |
Agreed, IMHO, the valid "empty" parameters values could be:
WDYT? |
eaf976a
to
98156f7
Compare
Agreed! I've updated it to consider only |
I'd add false personally. |
After reconsidering, I don’t see However, |
Thank you @yceruto. |
…rameters (yceruto) This PR was merged into the 7.2 branch. Discussion ---------- [DependencyInjection] Documenting non-empty container parameters PR symfony/symfony#57611 Closes #20233 Commits ------- a78ff47 documenting non-empty parameters
This new iteration (following up #57462, #56985 and symfony/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, see https://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.