Skip to content

Find general .env file before falling back to .env.[environment] #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/dotenv/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Dotenv

public function __construct($path, $file = '.env')
{
if ($file == '.env') {
if ($file != '.env') {
$file = '.env.' . strtolower(ENVIRONMENT);
}
$this->filePath = $this->getFilePath($path, $file);
Expand Down
2 changes: 1 addition & 1 deletion system/dotenv/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function ensureFileIsReadable()
{
$filePath = $this->filePath;
if (!is_readable($filePath) || !is_file($filePath)) {
echo "Related \".env\" not found, please configure \"". basename($filePath) ."\" it before running codeigniter application"; exit;
echo "\".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',
Expand Down
24 changes: 24 additions & 0 deletions system/dotenv/autoloader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
<?php

require_once 'Dotenv.php';
require_once 'Loader.php';
require_once 'Validator.php';


if (!function_exists('env')) {
// Define function `env` if it doesn't already exists

/**
* Gets the environment varaible if set or returns the second argument
*
* @param string $varname
* The variable. null will return all environment varaibles
*
* @param mixed $default_value
* The value to return if $varname is not set
*
* @return array|mixed
*/
function env($varname = null, $default_value = "") {
if (is_null($varname)) {
return getenv();
}
return getenv($varname) ? getenv($varname) : $default_value;
}
}