forked from agungjk/phpdotenv-for-codeigniter
-
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.
Detect Environment and Update Readme
- Loading branch information
Agung Jati Kusumo
committed
Jul 6, 2017
1 parent
f0a8f1d
commit 8f9b2f5
Showing
7 changed files
with
84 additions
and
64 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,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. |
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 |
---|---|---|
@@ -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 not shown.
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
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