2017 © Pedro Peláez
 

yii2-extension yii2-phpdotenv

phpdotenv Yii2 extension

image

cyberinferno/yii2-phpdotenv

phpdotenv Yii2 extension

  • Thursday, June 29, 2017
  • by cyberinferno
  • Repository
  • 1 Watchers
  • 6 Stars
  • 203 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 9 % Grown

The README.md

Phpdotenv extension for Yii 2

This is a Yii2 extension for vulcas/phpdotenv, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require cyberinferno/yii2-phpdotenv

or add, (*4)

"cyberinferno/yii2-phpdotenv": "~2.0.0"

to the require section of your composer.json., (*5)

Configuration

Usage:, (*6)

return [
    //....
    'bootstrap' => [
        [
            'class' => 'cyberinferno\yii\phpdotenv\Loader',
            'path' => '@vendor/../', // Directory of the .env file 
            'file' => '.env', // Optional parameter if custom environment variable file
            'overload' => false, // Optional parameter whether to overload already existing environment variables. Defaults to false
        ],
    ]
];

To use components which will access environment variables extend Loader class like this:, (*7)

<?php

namespace common\components;

use cyberinferno\yii\phpdotenv\Loader;
use yii\helpers\ArrayHelper;

class PhpdotenvLoader extends Loader
{
    public function bootstrap($app)
    {
        parent::bootstrap($app);
        $app->setComponents(ArrayHelper::merge($app->getComponents(),
            [
                'db' => [
                    'class' => 'yii\db\Connection',
                    'dsn' => getenv('DB_DSN'),
                    'username' => getenv('DB_USERNAME'),
                    'password' => getenv('DB_PASSWORD'),
                    'charset' => 'utf8',
                ],
            ]
        ));
    }
}

Bootstrap this class in your config like this:, (*8)

return [
    //....
    'bootstrap' => [
        [
            'class' => 'common\components\PhpdotenvLoader'
        ],
    ]
];

This extension was tested to be working well with Yii2 Advanced Template
but can be used in any Yii2 application by sending proper .env file path while bootstrapping the extension., (*9)

The Versions

29/06 2017

dev-master

9999999-dev

phpdotenv Yii2 extension

  Sources   Download

MIT

The Requires

 

by Karthik Panjaje

29/06 2017

2.0.1

2.0.1.0

phpdotenv Yii2 extension

  Sources   Download

MIT

The Requires

 

by Karthik Panjaje

27/06 2017

2.0.0

2.0.0.0

phpdotenv Yii2 extension

  Sources   Download

MIT

The Requires

 

by Karthik Panjaje

26/06 2017

1.0.0

1.0.0.0

phpdotenv Yii2 extension

  Sources   Download

MIT

The Requires

 

by Karthik Panjaje