The library for using .env files. You can find the full documentation on the website:
https://quillstack.org/dotenv
The .env should be used for sensitive information like passwords, hosts, keys, credentials, and all other values that
can be changed depending on the environment, e.g., debug mode settings or logs level.
To install this package, run the standard command using Composer:
composer require quillstack/dotenvYou can use Quillstack Dotenv package when you want to use .env files in your project.
If you created the .env file in the root directory of your proejct:
APP_DEBUG=trueYou can load this .env file in your application:
$dotenv = new Dotenv('.env');
$dotenv->load();Every time you need to know if your application works in debug mode, you can check it using this helper function:
if (env('APP_DEBUG')) {
echo 'Debug mode';
}You can also define a default value depending on the context:
if (env('APP_DEBUG', false)) {
echo 'Debug mode';
}You can use another helper method for required keys. If required key is not found an exception will be thrown:
$dbHost = required('DATABASE_HOST');The result if the key DATABASE_HOST is not set in the .env file:
DotenvValueNotSetException:
Value not set for key: DATABASE_HOST
You can define multi-line values in your .env file by using \n separator instead of new lines for example:
PRIVATE_KEY="line1\nline2\nline3"
Run tests using a command:
phpdbg -qrr ./vendor/bin/unit-tests$ docker-compose up -d
$ docker exec -w /var/www/html -it quillstack_dotenv sh