envhandler / envhandler
There is no license information available for the latest version (v1.0) of this package.
Simple and minimal yet powerful env handler
v1.0
2020-12-22 00:19 UTC
README
To install with composer:
composer require envhandler/envhandler
Env Sample Format
APP_NAME=null APP_URL=http://localhost APP_ENV=development DB_CONNECTIONS=pdo DB_USERNAME=dumpy_username DB_PASSWORD=dumpy_password DB_NAME=dump_dbname DB_HOST=localhost DB_PORT=8080 MAILER=PHPMailer MAIL_MAILER=null MAIL_HOST=null MAIL_PORT=null MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME=null
You can Create your own key=value pair in .env.
CUSTOM_KEY=VALUE
Usage
require __DIR__ ."/vendor/autoload.php"; // The class the will automatically creates the env.example file during instantiation. $env = new \EnvHandler\Environment\Environment(__DIR__);
// true parameter will automatically creates the .env at the root path of your project with the value from .env.example $env->load(true);
// To manually create an env file, call the load method with an empty parameter. // And create the .env file at the root path of your project with key=value format. $env->load();
// Output an associative array value from .env file. var_dump($env->getEnvFileContent());
Sample Output
Call the value you stored in .env anywhere in your project.
echo getEnv('APP_URL'); // Output: http://localhost echo getEnv('APP_NAME'); // Output: App Name echo getEnv('APP_ENV'); // Output: development echo getEnv('YOUR_CUSTOM_KEY_HERE_FROM_ENV')