Skip to content

Commit

Permalink
Intial component code
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik P committed Jun 26, 2017
1 parent 78d24f1 commit a71d205
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .gitignore
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
55 changes: 55 additions & 0 deletions Loader.php
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;
}
}
49 changes: 49 additions & 0 deletions README.md
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)
22 changes: 22 additions & 0 deletions composer.json
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\\": ""
}
}
}

0 comments on commit a71d205

Please sign in to comment.