jimchen/yii2-dotenv

phpdotenv for yii2

0.2.0-alpha 2019-03-17 08:34 UTC

README

Phpdotenv for yii2.

Installing

You can install the package via composer:

$ composer require jimchen/yii2-dotenv

Usage

If you want to cache web.php,

// In `web/index.php`
use jimchen\dotenv\web\YiiConfig;

require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';

// Must defind the alias `@config-cache` first
Yii::setAlias('@config-cache', __DIR__ . '/../config/cache');
$yiiConfig = new YiiConfig([
    'environmentPath' => '../',
    'environmentFile' => '.env',
    'configFile'      => '../config/web.php',
]);

$yiiConfig->load();

var_dump($yiiConfig->getItems());

If you want to cache console.php

// In `yii`
use jimchen\dotenv\console\YiiConfig;

require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';

// Must defind the alias `@config-cache` first
Yii::setAlias('@config-cache', __DIR__ . '/../config/cache');
$yiiConfig = new YiiConfig([
    'environmentPath' => '/',
    'environmentFile' => '.env',
    'configFile'      => '../config/console.php',
]);

$yiiConfig->load();

var_dump($yiiConfig->getItems());

Notice: You should create your .env file according to your environmentPath.

Console

Cache web configuration, the file is in @config-cache/config.web.php

$ php yii web-config/cache

Cache console configuration, the file is in @config-cache/config.console.php

$ php yii console-config/cache

License

The MIT License (MIT). Please see License File for more information.