Skip to content

Commit

Permalink
Merge branch 'release/v0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Agung Jati Kusumo committed Jul 6, 2017
2 parents f0a8f1d + 8f9b2f5 commit bad795d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 64 deletions.
Binary file added .DS_Store
Binary file not shown.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010-2017 Google, Inc. http://angularjs.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Binary file added cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 54 additions & 59 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,62 @@
PHP dotenv for codeigniter
==========================

Loads environment variables from `.env` to `getenv()` automagically.

This is a PHP version of the original [Ruby
dotenv](https://github.com/bkeepers/dotenv).

Why .env?
---------
**You should never store sensitive credentials in your code**. Storing
[configuration in the environment](http://www.12factor.net/config) is one of
the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is
likely to change between deployment environments – such as database credentials
or credentials for 3rd party services – should be extracted from the
code into environment variables.

Basically, a `.env` file is an easy way to load custom configuration
variables that your application needs without having to modify .htaccess
files or Apache/nginx virtual hosts. This means you won't have to edit
any files outside the project, and all the environment variables are
always set no matter how you run your project - Apache, Nginx, CLI, and
even PHP 5.4's built-in webserver. It's WAY easier than all the other
ways you know of to set environment variables, and you're going to love
it.

* NO editing virtual hosts in Apache or Nginx
* NO adding `php_value` flags to .htaccess files
* EASY portability and sharing of required ENV values
* COMPATIBLE with PHP's built-in web server and CLI runner
# PHP dotenv for codeigniter
> Autodetect environment type and load variables from `.env` to `getenv()` automagically.
This is a PHP version of the original [Ruby dotenv](https://github.com/bkeepers/dotenv).

![](cover.png)

## Manual Installation without Composer
1. Copy folder **system** to your codeigniter projects.
2. Add this code to your codeigniter index.php before codeigniter core loaded (before this text "* LOAD THE BOOTSTRAP FILE") :
```php
/*
* --------------------------------------------------------------------
* LOAD PHP DOT ENV FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
require_once BASEPATH . 'dotenv/autoloader.php';

$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
```

## Configuration
1. Create **.env** according your environment by copy file **.env.example** for database configuration and the other configuration.
Example : **.env.development**, **.env.testing**, **.env.production**

2. Load configuration, in file **application/config/database.php** change to this configuration
```php
$db['default']['hostname'] = getenv('DB_HOST');
$db['default']['username'] = getenv('DB_USERNAME');
$db['default']['password'] = getenv('DB_PASSWORD');
$db['default']['database'] = getenv('DB_DATABASE');
$db['default']['dbdriver'] = getenv('DB_CONNECTION');
```
3. Add ".env" to your .gitignore file
4. It will be running, thank you

## Release History

Manual Installation without Composer
------------------------------------
- copy folder "system" to your codeigniter projects
* 0.1.1
* CHANGE: Autodetect environment & Update Readme
* 0.1.0
* Initial version

- add this code to your codeigniter index.php before codeigniter core loaded
(before this text "* LOAD THE BOOTSTRAP FILE")
```php
/*
* --------------------------------------------------------------------
* LOAD PHP DOT ENV FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
require_once BASEPATH . 'dotenv/autoloader.php';
## Meta

$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
```
Agung Jati Kusumo – [@its_agungjk](https://twitter.com/its_agungjk)[email protected]

- in file "application/config/database.php" change to this configuration
```php
$db['default']['hostname'] = getenv('DB_HOST');
$db['default']['username'] = getenv('DB_USERNAME');
$db['default']['password'] = getenv('DB_PASSWORD');
$db['default']['database'] = getenv('DB_DATABASE');
$db['default']['dbdriver'] = getenv('DB_CONNECTION');
```
Distributed under the MIT license. See ``LICENSE`` for more information.

- create ".env" by copy file ".env.example" for database configuration and the other configuration
[https://github.com/agungjk/phpdotenv-for-codeigniter](https://github.com/agungjk/phpdotenv-for-codeigniter)

- add ".env" to your .gitignore file
## Contributing

- and it will be running, thank you
1. Fork it (<https://github.com/agungjk/phpdotenv-for-codeigniter/fork>)
2. Create your feature branch (`git checkout -b feature/fooBar`)
3. Commit your changes (`git commit -am 'Add some fooBar'`)
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request
Binary file added system/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions system/dotenv/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Dotenv

public function __construct($path, $file = '.env')
{
if ($file == '.env') {
$file = '.env.' . strtolower(ENVIRONMENT);
}
$this->filePath = $this->getFilePath($path, $file);
}

Expand Down
11 changes: 6 additions & 5 deletions system/dotenv/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ protected function ensureFileIsReadable()
{
$filePath = $this->filePath;
if (!is_readable($filePath) || !is_file($filePath)) {
throw new InvalidArgumentException(sprintf(
'Dotenv: Environment file .env not found or not readable. '.
'Create file with your environment settings at %s',
$filePath
));
echo "Related \".env\" not found, please configure \"". basename($filePath) ."\" it before running codeigniter application"; exit;
// throw new InvalidArgumentException(sprintf(
// 'Dotenv: Environment file .env not found or not readable. '.
// 'Create file with your environment settings at %s',
// $filePath
// ));
}
}

Expand Down

0 comments on commit bad795d

Please sign in to comment.