Skip to content

Commit bad795d

Browse files
author
Agung Jati Kusumo
committed
Merge branch 'release/v0.1.1'
2 parents f0a8f1d + 8f9b2f5 commit bad795d

File tree

7 files changed

+84
-64
lines changed

7 files changed

+84
-64
lines changed

.DS_Store

6 KB
Binary file not shown.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2010-2017 Google, Inc. http://angularjs.org
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

cover.png

59.6 KB
Loading

readme.md

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,62 @@
1-
PHP dotenv for codeigniter
2-
==========================
3-
4-
Loads environment variables from `.env` to `getenv()` automagically.
5-
6-
This is a PHP version of the original [Ruby
7-
dotenv](https://github.com/bkeepers/dotenv).
8-
9-
Why .env?
10-
---------
11-
**You should never store sensitive credentials in your code**. Storing
12-
[configuration in the environment](http://www.12factor.net/config) is one of
13-
the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is
14-
likely to change between deployment environments – such as database credentials
15-
or credentials for 3rd party services – should be extracted from the
16-
code into environment variables.
17-
18-
Basically, a `.env` file is an easy way to load custom configuration
19-
variables that your application needs without having to modify .htaccess
20-
files or Apache/nginx virtual hosts. This means you won't have to edit
21-
any files outside the project, and all the environment variables are
22-
always set no matter how you run your project - Apache, Nginx, CLI, and
23-
even PHP 5.4's built-in webserver. It's WAY easier than all the other
24-
ways you know of to set environment variables, and you're going to love
25-
it.
26-
27-
* NO editing virtual hosts in Apache or Nginx
28-
* NO adding `php_value` flags to .htaccess files
29-
* EASY portability and sharing of required ENV values
30-
* COMPATIBLE with PHP's built-in web server and CLI runner
1+
# PHP dotenv for codeigniter
2+
> Autodetect environment type and load variables from `.env` to `getenv()` automagically.
3+
4+
This is a PHP version of the original [Ruby dotenv](https://github.com/bkeepers/dotenv).
5+
6+
![](cover.png)
7+
8+
## Manual Installation without Composer
9+
1. Copy folder **system** to your codeigniter projects.
10+
2. Add this code to your codeigniter index.php before codeigniter core loaded (before this text "* LOAD THE BOOTSTRAP FILE") :
11+
```php
12+
/*
13+
* --------------------------------------------------------------------
14+
* LOAD PHP DOT ENV FILE
15+
* --------------------------------------------------------------------
16+
*
17+
* And away we go...
18+
*
19+
*/
20+
require_once BASEPATH . 'dotenv/autoloader.php';
21+
22+
$dotenv = new Dotenv\Dotenv(__DIR__);
23+
$dotenv->load();
24+
```
25+
26+
## Configuration
27+
1. Create **.env** according your environment by copy file **.env.example** for database configuration and the other configuration.
28+
Example : **.env.development**, **.env.testing**, **.env.production**
29+
30+
2. Load configuration, in file **application/config/database.php** change to this configuration
31+
```php
32+
$db['default']['hostname'] = getenv('DB_HOST');
33+
$db['default']['username'] = getenv('DB_USERNAME');
34+
$db['default']['password'] = getenv('DB_PASSWORD');
35+
$db['default']['database'] = getenv('DB_DATABASE');
36+
$db['default']['dbdriver'] = getenv('DB_CONNECTION');
37+
```
38+
3. Add ".env" to your .gitignore file
39+
4. It will be running, thank you
3140

41+
## Release History
3242

33-
Manual Installation without Composer
34-
------------------------------------
35-
- copy folder "system" to your codeigniter projects
43+
* 0.1.1
44+
* CHANGE: Autodetect environment & Update Readme
45+
* 0.1.0
46+
* Initial version
3647

37-
- add this code to your codeigniter index.php before codeigniter core loaded
38-
(before this text "* LOAD THE BOOTSTRAP FILE")
39-
```php
40-
/*
41-
* --------------------------------------------------------------------
42-
* LOAD PHP DOT ENV FILE
43-
* --------------------------------------------------------------------
44-
*
45-
* And away we go...
46-
*
47-
*/
48-
require_once BASEPATH . 'dotenv/autoloader.php';
48+
## Meta
4949

50-
$dotenv = new Dotenv\Dotenv(__DIR__);
51-
$dotenv->load();
52-
```
50+
Agung Jati Kusumo – [@its_agungjk](https://twitter.com/its_agungjk)agungjk.social@gmail.com
5351

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

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

65-
- add ".env" to your .gitignore file
56+
## Contributing
6657

67-
- and it will be running, thank you
58+
1. Fork it (<https://github.com/agungjk/phpdotenv-for-codeigniter/fork>)
59+
2. Create your feature branch (`git checkout -b feature/fooBar`)
60+
3. Commit your changes (`git commit -am 'Add some fooBar'`)
61+
4. Push to the branch (`git push origin feature/fooBar`)
62+
5. Create a new Pull Request

system/.DS_Store

6 KB
Binary file not shown.

system/dotenv/Dotenv.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Dotenv
2525

2626
public function __construct($path, $file = '.env')
2727
{
28+
if ($file == '.env') {
29+
$file = '.env.' . strtolower(ENVIRONMENT);
30+
}
2831
$this->filePath = $this->getFilePath($path, $file);
2932
}
3033

system/dotenv/Loader.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ protected function ensureFileIsReadable()
7575
{
7676
$filePath = $this->filePath;
7777
if (!is_readable($filePath) || !is_file($filePath)) {
78-
throw new InvalidArgumentException(sprintf(
79-
'Dotenv: Environment file .env not found or not readable. '.
80-
'Create file with your environment settings at %s',
81-
$filePath
82-
));
78+
echo "Related \".env\" not found, please configure \"". basename($filePath) ."\" it before running codeigniter application"; exit;
79+
// throw new InvalidArgumentException(sprintf(
80+
// 'Dotenv: Environment file .env not found or not readable. '.
81+
// 'Create file with your environment settings at %s',
82+
// $filePath
83+
// ));
8384
}
8485
}
8586

0 commit comments

Comments
 (0)