Download the PHP package etelford/phpdotenv-include-extension without Composer
On this page you can find all versions of the php package etelford/phpdotenv-include-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download etelford/phpdotenv-include-extension
More information about etelford/phpdotenv-include-extension
Files in etelford/phpdotenv-include-extension
Package phpdotenv-include-extension
Short Description An extension for vlucas/phpdotenv to load .env variables from include files. as well as group them into array-like underscore syntax.
License MIT
Informations about the package phpdotenv-include-extension
PHP dotenv extension for vlucas/phpdotenv to load .env variables from include files.
How & Why?
This package works as an add-on to the great vlucas/phpdotenv.
When .env
files start to get large it could be convenient to separate
variables out into smaller pieces. This helps solve that problem.
NB: If you're new to the idea of a .env
file, I recommend you start by
checking out vlucas/phpdotenv first.
Installation
composer.json:
"require": {
"etelford/phpdotenv-include-extension": "0.1.*"
}
Example
Create your .env
file as usual, but where you want to separate out sections
of it, use an include.
When you want to retrieve an env
variable from an include file, create an
instance of Etelford\Dotenv
and then retrieve the variables using whichever
method you normally use to include environment variables:
As you can see, the variables in an include file become namespaced. In the
example above, .database.env
is included by using a namespace (DATABASE
)
followed by and underscore (_
) and the word INCLUDE
.
Using With Laravel 5.x
If you'd like to use this with the Laravel framework,
open your bootstrap/app.php
and add the following after the application is
initially created:
That's it! Now you can use included .env
files as much as you like.
Conventions
- The path of an include is always relative to your root
.env
file. - You declare that a variable points to an include file using the
_INCLUDE
keyword. If you wish to override this you can with the third argument when you create theDotenv
class:$dotenv = new Etelford\Dotenv(__DIR__, '.env', 'PATH');
Note that the_
should not be provided if you use this customization.
Caveat
This package will not work as a command line script.