Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Dotenv] Make load() variadic #23242

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

Merged
merged 1 commit into from
Jun 21, 2017
Merged

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Jun 20, 2017

Q A
Branch? 4.0
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets Dotenv.php#L50
License MIT
Doc PR n/a

*
* @throws FormatException when a file has a syntax error
* @throws PathException when a file does not exist or is not readable
*/
public function load($path/*, ...$paths*/)
public function load(...$paths)
Copy link
Member

Choose a reason for hiding this comment

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

I would keep the $path, ...$paths signature as it conveys the fact that at least one path is required.

Copy link
Member Author

Choose a reason for hiding this comment

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

got it, fixed

@chalasr chalasr force-pushed the dotenv4-variadic branch 2 times, most recently from f962fec to 96081cd Compare June 20, 2017 21:13
@chalasr
Copy link
Member Author

chalasr commented Jun 20, 2017

Should we update the signature from ($path, ...$paths) to (string $path, string ...$paths) (Dotenv is final)?

@ogizanagi ogizanagi mentioned this pull request Jun 21, 2017
file_put_contents($path1, 'FOO=BAR');
file_put_contents($path2, 'BAR=BAZ');

(new DotEnv())->load($path1, $path2);
Copy link
Member

Choose a reason for hiding this comment

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

The test loading multiple paths should actually be added in 3.3

Copy link
Member Author

Choose a reason for hiding this comment

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

See #23245

@@ -45,10 +45,11 @@
* @throws FormatException when a file has a syntax error
* @throws PathException when a file does not exist or is not readable
*/
public function load($path/*, ...$paths*/)
public function load($path, ...$paths)
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we change load($path, ...$paths) to load(...$paths) in Symfony 4?

Copy link
Member Author

@chalasr chalasr Jun 21, 2017

Choose a reason for hiding this comment

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

@javiereguiluz see #23242 (comment).
Imho, we could have kept only ... $paths, maybe throwing if $paths is empty, but having both in the signature looks a bit weird

Copy link
Member

Choose a reason for hiding this comment

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

well, having load($path, ...$paths) means that the signature itself tells people that at least 1 argument is required (and IDEs know it too then). load(...$paths) allows 0 arguments

Copy link
Contributor

Choose a reason for hiding this comment

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

imo it's not that bad if the ...$paths is empty. No file loaded, no env variable created

Copy link
Member

Choose a reason for hiding this comment

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

@Taluu writing $dotenv->load() in your code which is always a no-op because you misused it is a bad DX (and this is the experience talking: it was the initial API of the component when merging it in Symfony)

Copy link
Member Author

@chalasr chalasr Jun 21, 2017

Choose a reason for hiding this comment

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

Indeed, can sound like calling load() will automagically look for some .env but nothing happens.

fabpot added a commit that referenced this pull request Jun 21, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[Dotenv] Test load() with multiple paths

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

dabecde [Dotenv] Test load() with multiple paths
Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Can be rebase now that the test has been merged in 3.3.

fabpot added a commit that referenced this pull request Jun 21, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

[DI] Uncomment code

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see comment below -->
| Bug fix?      | no
| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | N/A <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

I was about fixing all [other occurrences of commented code and `func_get/num_arg(s)`](https://github.com/symfony/symfony/search?utf8=%E2%9C%93&q=func_num_args&type=) as BC layer usages at once, but the following PRs will already cover it:

- HttpFoundation: #22863
- Serializer: #23241
- Process: #22836
- DotEnv: #23242

So it only remains DI ones.

Commits
-------

03f33b5 [DI] Uncomment code
@chalasr chalasr force-pushed the dotenv4-variadic branch from 96081cd to 408a33e Compare June 21, 2017 14:17
@chalasr
Copy link
Member Author

chalasr commented Jun 21, 2017

rebased, not added string typehints, let me know if I should.

@fabpot
Copy link
Member

fabpot commented Jun 21, 2017

For typehints, we should have a discussion about how we want to introduce them.

@fabpot
Copy link
Member

fabpot commented Jun 21, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 408a33e into symfony:master Jun 21, 2017
fabpot added a commit that referenced this pull request Jun 21, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

[Dotenv] Make load() variadic

| Q             | A
| ------------- | ---
| Branch?       | 4.0
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | [Dotenv.php#L50](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Dotenv/Dotenv.php#L50)
| License       | MIT
| Doc PR        | n/a

Commits
-------

408a33e [Dotenv] Make load() variadic
@chalasr chalasr deleted the dotenv4-variadic branch June 21, 2017 14:21
@chalasr
Copy link
Member Author

chalasr commented Jun 21, 2017

@fabpot Actually, passing a value that can't be casted as string to this method would break. Given the class is final, I think adding them would be safe.

@stof
Copy link
Member

stof commented Jun 22, 2017

@chalasr passign a non-castable value already breaks (inside the function). So I'm totally +1 for adding the typehint here (we cannot add them on non-final non-private methods due to BC, but we can here)

@chalasr
Copy link
Member Author

chalasr commented Jun 22, 2017

@stof see #23262

fabpot added a commit that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b [Yaml] use scalar type hints where possible
6ce70e4 Add scalar typehints/return types on final/internal/private code
symfony-splitter pushed a commit to symfony/console that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b078 [Yaml] use scalar type hints where possible
6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
symfony-splitter pushed a commit to symfony/routing that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b078 [Yaml] use scalar type hints where possible
6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b [Yaml] use scalar type hints where possible
6ce70e4 Add scalar typehints/return types on final/internal/private code
symfony-splitter pushed a commit to symfony/security-http that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b078 [Yaml] use scalar type hints where possible
6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
symfony-splitter pushed a commit to symfony/security that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b078 [Yaml] use scalar type hints where possible
6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
symfony-splitter pushed a commit to symfony/lock that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b078 [Yaml] use scalar type hints where possible
6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
symfony-splitter pushed a commit to symfony/property-access that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b078 [Yaml] use scalar type hints where possible
6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
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.

6 participants