Statistics
56
4
0
58d
Badges
Requirements

nette-dotenv

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

This little utility helps you to work with environment variables in config.neon.

Also, this parses the .env file - a feature known for Laravel users.

To be specific, it returns the $_SERVER variable (after populating it with .env variables). To make values compatible with Nette, it replaces % with %%.

Install

Via Composer

$ composer require wodcz/nette-dotenv

Usage

// in app/bootstrap.php file (or wherever you create \Nette\Configurator)
// add these lines

$parametersLoader = new \wodCZ\NetteDotenv\ParametersLoader(__DIR__.'/../'))
$configurator->addParameters($parametersLoader->getParameters());

Then, in your config.neon you can use any variable you configured in .env file. Or use ENV variables inside your Docker container, or CI build, you have the idea... Please see vlucas/phpdotenv documentation for .env file syntax.

parameters:
    someVariable: %ENV.DB_HOST%

database:
    default:
        dsn: "mysql:host=%ENV.DB_HOST%;dbname=%ENV.DB_NAME%"
        user: %ENV.DB_USER%
        password: %ENV.DB_PASSWORD%

Available ParametersLoader variables:

new ParametersLoader(
    $directory, // Where your .env file is stored
    $fileName = '.env', // You may choose file name other than `.env` 
    $namespace = 'ENV', // Key, under which will be ENV variables saved to Nette parameters
    $overload = false // Controls whether .env file variables should override existing ENV variables
)

If you change $namespace parameter, for example to ENVIRONMENT, then in config.neon:

parameters:
	someVariable: %ENVIRONMENT.DB_HOST%

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email admin@ikw.cz instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com