Skip to content

Conversation

@sroze
Copy link
Contributor

@sroze sroze commented Nov 22, 2016

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:

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)%"

public function testGetEndAllowsNull()
{
$bag = new EnvPlaceholderParameterBag();
$bag->set('env(ARRAY_VAR)', null);
Copy link
Member

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)');
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, true!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 👍

@stof
Copy link
Member

stof commented Nov 22, 2016

👍

@sroze sroze force-pushed the allow-null-as-default-env-value branch from ec71fb8 to 92b7ec9 Compare November 22, 2016 12:51
@sroze sroze force-pushed the allow-null-as-default-env-value branch from 92b7ec9 to 28ff2b8 Compare November 22, 2016 12:56
@nicolas-grekas
Copy link
Member

👍

$bag->resolve();
}

public function testGetEndAllowsNull()
Copy link
Contributor

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));
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍

@nicolas-grekas
Copy link
Member

Good catch, thanks @sroze.

nicolas-grekas added a commit that referenced this pull request Nov 23, 2016
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
@fabpot fabpot mentioned this pull request Nov 27, 2016
@sroze sroze deleted the allow-null-as-default-env-value branch October 2, 2017 10:29
OskarStark added a commit that referenced this pull request Feb 28, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants