-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Allow null as default env value #20590
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
68e4929
to
ec71fb8
Compare
public function testGetEndAllowsNull() | ||
{ | ||
$bag = new EnvPlaceholderParameterBag(); | ||
$bag->set('env(ARRAY_VAR)', null); |
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.
can you call this one NULL_VAR?
{ | ||
$bag = new EnvPlaceholderParameterBag(); | ||
$bag->set('env(ARRAY_VAR)', null); | ||
$bag->get('env(ARRAY_VAR)'); |
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.
this test case is missing an assertion
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.
what do you mean? 🤔
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.
oh yeah, true!
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.
Added 👍
👍 |
ec71fb8
to
92b7ec9
Compare
92b7ec9
to
28ff2b8
Compare
👍 |
@@ -139,4 +139,26 @@ public function testResolveThrowsOnBadDefaultValue() | |||
$bag->set('env(Array_Var)', array()); | |||
$bag->resolve(); | |||
} | |||
|
|||
public function testGetEndAllowsNull() |
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.
This should be GetEnv
right?
if (!is_scalar($defaultValue)) { | ||
throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar, but "%s" given to "%s".', gettype($defaultValue), $name)); | ||
if (null !== $defaultValue && !is_scalar($defaultValue)) { | ||
throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', gettype($defaultValue), $name)); |
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.
Meanwhile, can you please update the below message on line 100, to say "scalar or null" there also instead of "string or null"? (you should have a test to tweak also).
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.
Updated 👍
Good catch, thanks @sroze. |
This PR was squashed before being merged into the 3.2 branch (closes #20590). Discussion ---------- [DI] Allow null as default env value | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ø | License | MIT | Doc PR | ø This PR allows the environment variable default value to be null. The way, we can allow optional environment variables, such as in this example: ```yaml parameters: # Default values env(DATABASE_HOST): database env(DATABASE_PORT): ~ env(DATABASE_NAME): symfony env(DATABASE_USERNAME): root env(DATABASE_PASSWORD): ~ # Database configuration database_host: "%env(DATABASE_HOST)%" database_port: "%env(DATABASE_PORT)%" database_name: "%env(DATABASE_NAME)%" database_user: "%env(DATABASE_USERNAME)%" database_password: "%env(DATABASE_PASSWORD)%" ``` Commits ------- 519a471 [DI] Allow null as default env value
This PR was merged into the 7.3 branch. Discussion ---------- [Notifier][Webhook] Add Smsbox support | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT |Doc | [#20590](symfony/symfony-docs#20590) Add support for Webhook to Smsbox Notifier Event statuses come from Smsbox [documentation](https://en.smsbox.net/docs/doc-APIReceive-SMSBOX-EN.pdf). Commits ------- 08062e8 [Notifier][Webhook] Add Smsbox support
This PR allows the environment variable default value to be null. The way, we can allow optional environment variables, such as in this example: