Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add docs for the Dotenv component#7350

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

Merged
xabbuh merged 1 commit intosymfony:masterfromfabpot:env-component
Jan 24, 2017

Conversation

@fabpot
Copy link
Member


.. code-block:: php

$dbUser = getenv('DB_USER);
Copy link
Member

Choose a reason for hiding this comment

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

Missing single quote'DB_USER'


Symfony Env never overwrites existing environment variables.

You should never store a ``.env`` file is your code repository as it might

Choose a reason for hiding this comment

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

Typo. Should be "in your code"

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

w3guy reacted with thumbs up emoji
Copy link
Member

@javiereguiluzjaviereguiluz left a comment

Choose a reason for hiding this comment

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

Thanks for providing the docs for this component. Everything is well explained and easy to understand, but I miss two things ... not for this component itself, but for when using it inside Symfony:

  1. It's not clear enough for me how and when to use this. You mention that this is not for production. So should I create this only fordev? But then, why define it indev if I already haveapp/config/config_dev.yml which works nicely without env vars? In other words, I don't know why I should "complicate" things indev with env vars ... which probably are only needed inprod.
  2. Is there a seamless integration with Symfony? If I define a.env file, could I use those vars with%env()% in my files automatically or should I do something?

environment variables (as recommended for `twelve-factor applications
<http://www.12factor.net/>`_. Using an `.env` file to store those environment
variables eases development and CI management by keeping them in one "standard"
place and agnostic of the technology stack you are using (Nginx vs PHP build-in

Choose a reason for hiding this comment

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

build-in ->built-in ?

jakzal reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed


.. note::

PHP has a lot of different implementation of this "pattern". This

Choose a reason for hiding this comment

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

implementation ->implementations

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

done


Load an ``.env`` file in your PHP application via ``Dotenv::load()``:

.. code-block:: php

Choose a reason for hiding this comment

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

In docs we are not allowed to use thisphp code block and we must the:: trick.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

Symfony Env never overwrites existing environment variables.

You should never store a ``.env`` file is your code repository as it might
contains sensitive information; creates a ``.env.dist`` file with sensible

Choose a reason for hiding this comment

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

creates ->create

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

contains sensitive information; creates a ``.env.dist`` file with sensible
defaults instead.

Symfony Env should only be used in development/testing/staging environments.

Choose a reason for hiding this comment

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

This recommendation contradicts a bit the previous one. If this file should only be used for non-production environments, then there's no problem storing this file in the repo because the credentials will be different. If this is true, then we don't need.env.dist and we can simplify things a lot.

Copy link
Contributor

Choose a reason for hiding this comment

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

@javiereguiluz db connection settings might still be sensitive information for testing/staging environments.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

.env contains data that should bedifferent for each dev, so having it in Git would not make sense.

.. note::

PHP has a lot of different implementation of this "pattern". This
implementation goal is to replicate what ``source .env`` would do. So, it
Copy link
Contributor

@jakzaljakzalJan 11, 2017
edited
Loading

Choose a reason for hiding this comment

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

This implementation's goal

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed


PHP has a lot of different implementation of this "pattern". This
implementation goal is to replicate what ``source .env`` would do. So, it
tries to be as similar as possible with the default shells behavior, and
Copy link
Contributor

Choose a reason for hiding this comment

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

shell's behavior

Copy link
Contributor

Choose a reason for hiding this comment

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

although plural is probably correct in this case too.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

ok

Symfony Env never overwrites existing environment variables.

You should never store a ``.env`` file is your code repository as it might
contains sensitive information; creates a ``.env.dist`` file with sensible
Copy link
Contributor

Choose a reason for hiding this comment

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

it might contain

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

@fabpot
Copy link
MemberAuthor

@javiereguiluz Using a.env file to define env vars in projects is a "standard" used by many frameworks. You don't need to use it of course as we have other mechanisms in Symfony, but this component allows Symfony projects to be more similar with projects written with other frameworks and languages.

Regarding the integration with Symfony, it's going to be part of the whole new "bootstrap" experience I'm working on. More on that later.

HeahDude and mattjanssen reacted with hooray emoji

@fabpotfabpotforce-pushed theenv-component branch 2 times, most recently from38a171f tobb181d5CompareJanuary 11, 2017 23:18

You can install the component in 2 different ways:

* :doc:`Install it via Composer </components/using_components>` (``symfony/env`` on `Packagist`_);
Copy link
Member

Choose a reason for hiding this comment

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

missing.. _Packagist: https://packagist.org/packages/symfony/env at the end of this document

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

=================

The Env Component parses ``.env`` files to make environment variables
stored in them accessible via ``getenv()``, ``$_ENV``, or ``$_SERVER``.
Copy link
Member

Choose a reason for hiding this comment

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

the Oxford comma should be removed

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

arf, I really don't like this but ok, done.


Sensitive information and environment-dependent settings should be defined as
environment variables (as recommended for `twelve-factor applications
<http://www.12factor.net/>`_. Using an `.env` file to store those environment
Copy link
Member

Choose a reason for hiding this comment

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

We do not inline the referenced URLs, but add them add the end of the document.

Copy link
Member

Choose a reason for hiding this comment

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

double backticks needed to enclose the filename

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

done x 2


Given the following ``.env`` file content:

.. code-block:: bash
Copy link
Member

@xabbuhxabbuhJan 12, 2017
edited
Loading

Choose a reason for hiding this comment

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

Don't we have a better code block type we could use here? 

Given the following ``.env`` file content:

.. code-block:: bash

Copy link
Member

Choose a reason for hiding this comment

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

we should add a file comment too:

# .envDB_USER=rootDB_PASS=pass

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

done

@fabpot
Copy link
MemberAuthor

Comments addressed

@xabbuh
Copy link
Member

👍

Status: Reviewed


First, require Symfony Dotenv via Composer:

.. code-block:: bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we useterminal now?


Symfony Env never overwrites existing environment variables.

You should never store a ``.env`` file in your code repository as it might
Copy link
Contributor

Choose a reason for hiding this comment

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

store an.env file

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

No, it's store a dot env file :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, thanks!

Symfony Env never overwrites existing environment variables.

You should never store a ``.env`` file in your code repository as it might
contain sensitive information; create a ``.env.dist`` file with sensible
Copy link
Contributor

Choose a reason for hiding this comment

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

an here too

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

same here

fabpot added a commit to symfony/symfony that referenced this pull requestJan 12, 2017
This PR was merged into the 3.3-dev branch.Discussion----------Add a new Dotenv component| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        |symfony/symfony-docs#7350This introduces a new Dotnv Component that manages `.env` files. Read the referenced doc PR above for more information about usage:But here, I want to explain the rationale behind creating such a component instead of reusing an existing one. * First, this version only implements what you can do in a "real" bash shell script (which is what a `.env` really is): so **no value validation** for instance (and anyway, an env var value is always a string). That's important as in production, we should use real env variables, and we don't have validation for them there; * It allows to only parse a file without populating the env variables (we have 3 stages: `load` `parse` and `populate`); * Strict implementation of what you can do in a `.env` file, same behavior as bash ($VAR and ${VAR} are supported for instance, executing commands as well); * Great error messages: I spent a lot of time being sure that error reporting is top notch; * Clean, simple, and straightforward code (small public API); * It only does `.env` management, there is no uneeded abstractions like being able to add an env variable directly (just use `putenv`);There are some unimplemented features as I don't think they are needed and would increase the complexity of the code: several concatenated strings `FOO='foo'"bar"` for instance.Commits-------5a6be8a [Dotenv] added the component
@fabpotfabpot removed the On hold labelJan 12, 2017
@fabpot
Copy link
MemberAuthor

This one is ready and the related PR on Symfony has been merged now.

@fabpotfabpot changed the titleadded docs for the env componentAdd docs for the env componentJan 12, 2017
@fabpotfabpot changed the titleAdd docs for the env componentAdd docs for the Dotenv componentJan 12, 2017

Sensitive information and environment-dependent settings should be defined as
environment variables (as recommended for `twelve-factor applications`_. Using
an ``.env`` file to store those environment variables eases development and CI
Copy link
Contributor

Choose a reason for hiding this comment

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

Then it'sa here :)

yceruto reacted with laugh emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

touché

ogizanagi, chalasr, HeahDude, and yceruto reacted with laugh emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

@HeahDude
Copy link
Contributor

👍

PHP has a lot of different implementations of this "pattern". This
implementation's goal is to replicate what ``source .env`` would do. So, it
tries to be as similar as possible with the default shell's behavior, and
does not do anything not possible via ``source`` (like value validation).
Copy link
Member

Choose a reason for hiding this comment

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

Double negation is hard to read

-----

Sensitive information and environment-dependent settings should be defined as
environment variables (as recommended for `twelve-factor applications`_. Using
Copy link
Contributor

Choose a reason for hiding this comment

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

A closing parenthesis is missing on this line.

sstok reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

Copy link
Member

@javiereguiluzjaviereguiluz left a comment

Choose a reason for hiding this comment

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

I'm missing a brief explanation about the 3 stages and their purposes: load, parse and populate. Thanks!

DB_USER=root
DB_PASS=${DB_USER}pass # Include the user as a password prefix

Embed commands via ``$()`` (not supported on Windows):
Copy link
Contributor

Choose a reason for hiding this comment

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

Windows 10 added support for a Bash shell, so is this is still valid?
Note that I'm not using Windows atm, nor Windows 10 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Windows is not able to do it out of the box. But you can use it through an emulator like cmder or ConEmu.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait ConEmu support this? Cool :)

Windows 10 added bash support, but using an Ubuntu subsystem 😵 so it will work as expected then.

environment variables (as recommended for `twelve-factor applications`_. Using
a ``.env`` file to store those environment variables eases development and CI
management by keeping them in one "standard" place and agnostic of the
technology stack you are using (Nginx vs PHP built-in server for instance).
Copy link
Contributor

Choose a reason for hiding this comment

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

nginx instead ofNginx?

Copy link
Member

Choose a reason for hiding this comment

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

I think we use Nginx everywhere else.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

indeed, Nginx is used elsewhere


The Dotenv Component parses ``.env`` files to make environment variables
stored in them accessible via ``getenv()``, ``$_ENV`` or ``$_SERVER``.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you add aversionadded section (like in cache and workflow?)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

done

@fabpot
Copy link
MemberAuthor

@javiereguiluz The only entry-point should beload for most developers.load is just a shortcut toparse thenpopulate, but using those last 2 directly should be very rare. So, I don't think we need to "document" them here (phpdocs are enough IMHO).

defaults instead.

Symfony Env should only be used in development/testing/staging environments.
For production environments, use "real" environment variables.

Choose a reason for hiding this comment

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

What doSymfony Env stands for? Does it refer to this component?

Does it mean we should not use this component in production environment?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed, should have beenSymfony Dotenv.

Indeed, in production, you should define "real" env vars.

@fabpot
Copy link
MemberAuthor

Anything blocking the merge (besides time :))?

@teohhanhui
Copy link
Contributor

teohhanhui commentedJan 23, 2017
edited
Loading

Regarding the integration with Symfony, it's going to be part of the whole new "bootstrap" experience I'm working on. More on that later.

I hope it'll bring Symfony closer toThe Twelve-Factor App (esp.https://12factor.net/config), which will be good news for Docker users. Currently the parameters.yml situation is a bit of a pain (probably improved since dynamicenv parameters)...

@xabbuh
Copy link
Member

Thank you@fabpot.

@xabbuhxabbuh merged commit03fda49 intosymfony:masterJan 24, 2017
xabbuh added a commit that referenced this pull requestJan 24, 2017
This PR was merged into the master branch.Discussion----------Add docs for the Dotenv componentSeesymfony/symfony#21234Commits-------03fda49 added docs for the env component
@javiereguiluzjaviereguiluz modified the milestone:3.3Feb 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

@OskarStarkOskarStarkOskarStark left review comments

@xabbuhxabbuhxabbuh left review comments

+10 more reviewers

@jakzaljakzaljakzal left review comments

@lyrixxlyrixxlyrixx left review comments

@jderussejderussejderusse left review comments

@aboksaboksaboks left review comments

@sstoksstoksstok left review comments

@juliendufresnejuliendufresnejuliendufresne left review comments

@ycerutoycerutoyceruto left review comments

@walvawalvawalva left review comments

@w3guyw3guyw3guy left review comments

@HeahDudeHeahDudeHeahDude left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

16 participants

@fabpot@xabbuh@HeahDude@teohhanhui@javiereguiluz@jakzal@lyrixx@jderusse@aboks@sstok@OskarStark@juliendufresne@yceruto@walva@w3guy@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp