From a9d3eca511f9124ab77a8718b5a44c032e12ef2e Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 5 Aug 2024 15:40:24 +0200 Subject: [PATCH 1/4] fix Dotenv\Dotenv loading --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f50c5c..fba7dd4 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ $ composer install ``` // Use this code if your .env files on *CodeIgniter ROOT* folder $hook['pre_system'] = function() { - $dotenv = Dotenv\Dotenv::create(FCPATH); + $dotenv = Dotenv\Dotenv::createImmutable(FCPATH); $dotenv->load(); }; ``` @@ -46,7 +46,7 @@ or ``` // Use this code if your .env files on *application* folder $hook['pre_system'] = function() { - $dotenv = Dotenv\Dotenv::create(APPPATH); + $dotenv = Dotenv\Dotenv::createImmutable(APPPATH); $dotenv->load(); }; ``` From a1958581a3bb5cccb1e6bbd1a3108b38334a36b0 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 19 Aug 2024 12:36:35 +0200 Subject: [PATCH 2/4] getenv deprecated use $_ENV --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fba7dd4..e6b4414 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,11 @@ $ cp .env.example .env to ``` - 'hostname' => getenv('DB_HOSTNAME'), - 'username' => getenv('DB_USERNAME'), - 'password' => getenv('DB_PASSWORD'), - 'database' => getenv('DB_DATABASE'), - 'dbdriver' => getenv('DB_DRIVER'), + 'hostname' => $_ENV['DB_HOSTNAME'], + 'username' => $_ENV['DB_USERNAME'], + 'password' => $_ENV['DB_PASSWORD'], + 'database' => $_ENV['DB_DATABASE'], + 'dbdriver' => $_ENV['DB_DRIVER'], ``` From 83ba26e588b185fbdc9a34d665ba1ddb911d2617 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 19 Aug 2024 13:28:32 +0200 Subject: [PATCH 3/4] autoload in index.php --- README.md | 45 +++++++++++++-------------------------- application/composer.json | 2 +- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index e6b4414..b93ee29 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,9 @@ # PHP DotEnv for CodeIgniter -> Autodetect environment type and load variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically. +> Autodetect environment type and load variables from `.env`, `$_ENV` and `$_SERVER` automagically. ![](cover.png) - - - ## Installation 1. Install Composer ``` @@ -21,45 +18,37 @@ $ composer install ``` - - - ## Configuration 1. Enable your Composer Autoload and Hooks: `application/config/config.php` -`$config['enable_hooks'] = FALSE;` to `$config['enable_hooks'] = TRUE;` - `$config['composer_autoload'] = FALSE;` to `$config['composer_autoload'] = TRUE;` +1. Add this code on index.php : `/index.php` -2. Add this code to your application hooks: `application/config/hooks.php` +beefore `require_once BASEPATH.'core/CodeIgniter.php';` -``` -// Use this code if your .env files on *CodeIgniter ROOT* folder -$hook['pre_system'] = function() { - $dotenv = Dotenv\Dotenv::createImmutable(FCPATH); - $dotenv->load(); -}; -``` -or ``` -// Use this code if your .env files on *application* folder -$hook['pre_system'] = function() { - $dotenv = Dotenv\Dotenv::createImmutable(APPPATH); - $dotenv->load(); -}; +require_once __DIR__ . '/vendor/autoload.php'; +$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); +$dotenv->load(); + +/* + * -------------------------------------------------------------------- + * LOAD THE BOOTSTRAP FILE + * -------------------------------------------------------------------- + * + * And away we go... + */ ``` -3. Create your *.env* files +1. Create your *.env* files ``` $ cp .env.example .env ``` - - ## Usage Example ### Database Configuration @@ -83,10 +72,6 @@ to ``` - - - - ## Contributing 1. Fork it! 2. Create your feature branch (`git checkout -b my-new-feature`) diff --git a/application/composer.json b/application/composer.json index 170aedf..d7c6bb7 100644 --- a/application/composer.json +++ b/application/composer.json @@ -1,5 +1,5 @@ { "require": { - "vlucas/phpdotenv": "^3.3" + "vlucas/phpdotenv": "^5.6" } } From aacddb0a9f37c55af55e96dfaee568a1c833776a Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 19 Aug 2024 13:29:15 +0200 Subject: [PATCH 4/4] add for version CI 3.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b93ee29..a93e54f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHP DotEnv for CodeIgniter +# PHP DotEnv for CodeIgniter 3.2.x > Autodetect environment type and load variables from `.env`, `$_ENV` and `$_SERVER` automagically. ![](cover.png)