-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Karthik P
committed
Jun 26, 2017
1 parent
78d24f1
commit a71d205
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# phpstorm project files | ||
.idea | ||
|
||
# netbeans project files | ||
nbproject | ||
|
||
# zend studio for eclipse project files | ||
.buildpath | ||
.project | ||
.settings | ||
|
||
# windows thumbnail cache | ||
Thumbs.db | ||
|
||
# composer vendor dir | ||
/vendor | ||
|
||
# composer itself is not needed | ||
composer.phar | ||
# composer lock file | ||
composer.lock | ||
|
||
# Mac DS_Store Files | ||
.DS_Store | ||
|
||
# phpunit itself is not needed | ||
phpunit.phar | ||
# local phpunit config | ||
/phpunit.xml | ||
|
||
# vagrant runtime | ||
/.vagrant | ||
*.cache* | ||
|
||
# PHP tidy cache | ||
.phptidy-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace cyberinferno\yii\phpdotenv; | ||
|
||
use Dotenv\Dotenv; | ||
use yii\base\Component; | ||
|
||
/** | ||
* Class Loader | ||
* | ||
* @property Dotenv $dotenv | ||
* | ||
* @package yii\phpdotenv | ||
*/ | ||
class Loader extends Component | ||
{ | ||
/** | ||
* @var string Use if custom environment variable directory | ||
*/ | ||
public $file; | ||
/** | ||
* @var bool Whether to overload already existing environment variables | ||
*/ | ||
public $overload = false; | ||
/** | ||
* @var Dotenv | ||
*/ | ||
private $_dotenv; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
if ($this->file !== null) { | ||
$this->_dotenv = new Dotenv(__DIR__, $this->file); | ||
} else { | ||
$this->_dotenv = new Dotenv(__DIR__); | ||
} | ||
if ($this->overload) { | ||
$this->_dotenv->overload(); | ||
} else { | ||
$this->_dotenv->load(); | ||
} | ||
} | ||
|
||
/** | ||
* Get dotenv | ||
* @return Dotenv | ||
*/ | ||
public function getDotenv() | ||
{ | ||
return $this->_dotenv; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Phpdotenv extension for Yii 2 | ||
=============================================== | ||
|
||
This is a Yii2 extension for [vulcas/phpdotenv](https://github.com/vlucas/phpdotenv) | ||
|
||
Installation | ||
------------ | ||
|
||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). | ||
|
||
Either run | ||
|
||
``` | ||
php composer.phar require cyberinferno/yii2-phpdotenv | ||
``` | ||
|
||
or add | ||
|
||
```json | ||
"cyberinferno/yii2-phpdotenv": "~1.0.0" | ||
``` | ||
|
||
to the require section of your composer.json. | ||
|
||
|
||
Configuration | ||
------------- | ||
|
||
Usage: | ||
|
||
```php | ||
return [ | ||
//.... | ||
'components' => [ | ||
'dotenv' => [ | ||
'class' => 'cyberinferno\yii\phpdotenv\Loader', | ||
'file' => '.env', // Optional parameter if custom environment variable directory | ||
'overload' => false, // Optional parameter whether to overload already existing environment variables. Defaults to false | ||
], | ||
] | ||
]; | ||
``` | ||
Accessing ``Dotenv`` object: | ||
|
||
```php | ||
$dotenv = \Yii::$app->dotenv->dotenv; | ||
``` | ||
|
||
For further information about methods available in ``Dotenv`` class refer [Phpdotevn README](https://github.com/vlucas/phpdotenv/blob/master/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "cyberinferno/yii2-phpdotenv", | ||
"description": "phpdotenv Yii2 extension", | ||
"type": "yii2-extension", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Karthik Panjaje", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"yiisoft/yii2": "~2.0.0", | ||
"vlucas/phpdotenv": "^2.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"cyberinferno\\yii\\phpdotenv\\": "" | ||
} | ||
} | ||
} |