emberfuse / lockbox
A simple PHP environment variables repository.
Requires
- php: ^7.4|^8.0
- ext-json: *
- ext-mbstring: *
- phpoption/phpoption: ^1.7
- vlucas/phpdotenv: ^5.3
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2021-10-11 05:20:50 UTC
README
Introduction
a .env
file is an easy way to load custom configuration variables that your application needs without having to modify .htaccess
files or Apache/nginx virtual hosts.
Installation
This library uses vlucas/phpdotenv
library by Vance Lucas & Graham Campbell. So, keep in mind that you may want to include vlucas/phpdotenv
as a dependency to use this library.
Installation made easy via Composer:
$ composer require emberfuse/lockbox
or add it by hand to your composer.json
file.
Usage
Add your application configuration to a .env
file at the root of your project. Make sure the .env
file is added to your .gitignore
so it is not checked-in the code
API_TOKEN="you-shall-not-pass" SECRET_KEY="itsunderthemattress"
Before using Lockbox you need to load up all your environment variables. To do so you will have to use vlucas/phpdotenv
in the following way:
$dotenv = Dotenv\Dotenv::create( Emberfuse\Lockbox\Env::createRepository(), // The repository where all environment variables are saved. __DIR__, // Full path to where the environment file is located. '.env' // Environment file. ); $dotenv->load(); // Load them all up.
For more information on how to use vlucas/phpdotenv
check out the full documentation here.
The above example will write loaded values to $_ENV
and putenv
, but when interpolating environment variables, we'll only read from $_ENV
. Moreover, it will never replace any variables already set before loading the file.
Now that your environment variables are loaded up you may access them using the following method.
use Emberfuse\Lockbox\Env; return [ 'database' => [ 'name' => Env::get('DB_NAME', 'default_db_name'), ], ];
You may also use the helper methods provided to do the same as above.
return [ 'database' => [ 'name' => env('DB_NAME', 'default_db_name'), ], ];
Contributing
Thank you for considering contributing to Lockbox! You can read the contribution guide here.
Code of Conduct
To ensure that the Emberfuse community is welcoming to all, please review and abide by the Code of Conduct.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
Emberfuse Lockbox is open-sourced software licensed under the MIT license.