PHP code example of neemzy / environ

1. Go to this page and download the library: Download neemzy/environ 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/ */

    

neemzy / environ example snippets


$environ = new Neemzy\Environ\Manager();

$environ
    ->add(
        'dev',
        new Neemzy\Environ\Environment(
            function () {
                return preg_match('/localhost/', $_SERVER['SERVER_NAME']);
            },
            function () {
                $pdo = new PDO('sqlite:dev.db');
            }
        )
    )
    ->add(
        'prod',
        new Neemzy\Environ\Environment(
            function () {
                return true;
            },
            function () {
                $pdo = new PDO('mysql:host=MYHOST;dbname=MYDBNAME', 'MYUSER', 'MYPASSWORD');
            }
        )
    );

$environ->init();

// This will print 'dev'
echo($environ->get());

// Triggers the callback as well
$environ->set('prod');

if ($environ->is('prod')) {
    // There you go !
}