zablose / dotenv
Read '.env' file to an array.
1.2.3
2024-07-13 08:49 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5.2
README
Read '.env' file to a static array.
Installation
composer require zablose/dotenv
Usage
Read '.env' file(s)
Probably in your index.php
after auto loader.
use Zablose\DotEnv\Env; // Auto loader (new Env())->setArrays(['PROTECTED']) ->read(__DIR__.'/../.env') ->read(__DIR__.'/../.env-extra');
Get ENV
use Zablose\DotEnv\Env; $db_name = Env::string('DB_NAME', 'dotenv'); $db_password = Env::string('DB_PASSWORD'); $db_port = Env::int('DB_PORT');
Or
Works, if helper function is in use - added to the project's composer
autoload -> files
section.
$db_name = env_string('DB_NAME', 'dotenv'); $db_password = env_string('DB_PASSWORD'); $db_port = env_int('DB_PORT');
What is supported?
Look at ENVs testing examples for more info.
Variables
USER=username
EMAIL=${USER}@domain.com
Arrays
PROTECTED_0=_token
PROTECTED_1=password
Value Types
Development
Check submodule's readme for more details about development environment used.
Hosts
Append to /etc/hosts
.
127.0.0.1 dotenv.zdev
127.0.0.1 www.dotenv.zdev
Quick Start
$ git clone -b 'dev' --single-branch --depth 1 https://github.com/zablose/dotenv.git dotenv
$ cd dotenv
$ git submodule update --init
# Copy env file, then ammend it to your needs.
$ cp .env.example .env
$ docker-compose -p zdev up -d
# To see post-script logs, while container is starting.
$ tail -f docker-damp/logs/all.log
# To enter container, using Bash shell.
$ docker exec -it dotenv-damp bash
(dotenv-damp)$ phpunit
License
This package is free software distributed under the terms of the MIT license.