PHP code example of datahihi1 / tiny-env

1. Go to this page and download the library: Download datahihi1/tiny-env library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

datahihi1 / tiny-env example snippets




use Datahihi1\TinyEnv\TinyEnv;

$env = new TinyEnv(__DIR__);
$env->load();

echo env('DB_HOST', 'localhost');

$env->load();                           // Load all
$env->load(specificKeys: ['DB_HOST']);  // Load specific keys
$env->load([], forceReload: true);      // Force reload (overwrite existing values)
$env->load([], noFile: true);           // Load without requiring .env file to exist

$env = new TinyEnv(__DIR__, true); // Load immediately and populate $_SERVER|$_ENV but only .env and not recommended for production

$env->envfiles(['.env', '.env.production', '.env.local']); // Load in order, pre-declaration file has the highest priority by default (.env > .env.production > .env.local)
$env->envfiles(['.env.production', '.env.local'], prioritizeEnv: true); // Prioritize .env file by loading it first, allows overwriting other files

$env = new TinyEnv(__DIR__);
$env->allowWrapperSchemes(['phar']); // opt-in to allow phar://... values
$env->load();

$env = new TinyEnv(__DIR__); // By default, superglobals are NOT populated to avoid unintended side effects. You can enable it explicitly:
$env->populateSuperglobals(); // Enable superglobals population
$env->populateServerglobals(); // Enable server globals population
$env->load();

echo env('NAME');                // Get value
echo env('NOT_FOUND', 'backup'); // With default
print_r(env());                  // Get all (in .env file)
print_r(sysenv());               // Get all system variables