From a71d205c252ef6b107a63a4eb0a37f6985cfda76 Mon Sep 17 00:00:00 2001 From: Karthik P Date: Mon, 26 Jun 2017 16:49:16 +0530 Subject: [PATCH] Intial component code --- .gitignore | 36 +++++++++++++++++++++++++++++++++ Loader.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++ composer.json | 22 +++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 .gitignore create mode 100644 Loader.php create mode 100644 README.md create mode 100644 composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42e6404 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/Loader.php b/Loader.php new file mode 100644 index 0000000..216bc85 --- /dev/null +++ b/Loader.php @@ -0,0 +1,55 @@ +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; + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..69152cb --- /dev/null +++ b/README.md @@ -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) \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c1f4470 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "cyberinferno/yii2-phpdotenv", + "description": "phpdotenv Yii2 extension", + "type": "yii2-extension", + "license": "MIT", + "authors": [ + { + "name": "Karthik Panjaje", + "email": "karthikreadnovel@gmail.com" + } + ], + "require": { + "php": ">=5.4.0", + "yiisoft/yii2": "~2.0.0", + "vlucas/phpdotenv": "^2.4" + }, + "autoload": { + "psr-4": { + "cyberinferno\\yii\\phpdotenv\\": "" + } + } +}