PHP code example of ivoba / dotenv-service-provider

1. Go to this page and download the library: Download ivoba/dotenv-service-provider 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/ */

    

ivoba / dotenv-service-provider example snippets


$app['env'] = getenv('SILEX_ENV') ? getenv('SILEX_ENV') : 'dev';
if($app['env'] === 'dev'){
    \Dotenv::load();
}
$app['debug'] = getenv('SILEX_DEBUG') ? getenv('SILEX_DEBUG') : false;
$app['this'] = getenv('this') ? getenv('this') : 'that';
//...
\Dotenv::

$app->register(new \Ivoba\Silex\EnvProvider(), ['env.options' => ['prefix' => 'MYPREFIX',
    'use_dotenv' => function () use ($app) {
        return $app['env'] === 'dev';
    },
    'dotenv_dir' => __DIR__ . '/../../../..',
    'var_config' => []]
]);
$app['env.load'];

$envOptions = ['env.options' => ['var_config' => [
    'hoo' => [EnvProvider::CONFIG_KEY_ALLOWED => 'this'],
    'zack' => [EnvProvider::CONFIG_KEY_REQUIRED => true],
    'dong' => [EnvProvider::CONFIG_KEY_CAST => EnvProvider::CAST_TYPE_BOOLEAN],
    'zip' => [EnvProvider::CONFIG_KEY_DEFAULT => 'zippi']]
]];
$app->register(new \Ivoba\Silex\EnvProvider(), $envOptions);
$app['env.load'];