\CodeIgniter\ConfigDotEnv

Environment-specific configuration

Summary

Methods
Properties
Constants
__construct()
load()
normaliseVariable()
No public properties found
No constants found
setVariable()
sanitizeValue()
resolveNestedVariables()
getVariable()
$path
N/A
No private methods found
No private properties found
N/A

Properties

$path

$path : string

The directory where the .env file can be located.

Type

string

Methods

__construct()

__construct(string  $path, string  $file = '.env') 

Builds the path to our file.

Parameters

string $path
string $file

load()

load() : boolean

The main entry point, will load the .env file and process it so that we end up with all settings in the PHP environment vars (i.e. getenv(), $_ENV, and $_SERVER)

Returns

boolean

normaliseVariable()

normaliseVariable(string  $name, string  $value = '') : array

Parses for assignment, cleans the $name and $value, and ensures that nested variables are handled.

Parameters

string $name
string $value

Returns

array

setVariable()

setVariable(string  $name, string  $value = '') 

Sets the variable into the environment. Will parse the string first to look for {name}={value} pattern, ensure that nested variables are handled, and strip it of single and double quotes.

Parameters

string $name
string $value

sanitizeValue()

sanitizeValue(string  $value) : string

Strips quotes from the environment variable value.

This was borrowed from the excellent phpdotenv with very few changes. https://github.com/vlucas/phpdotenv

Parameters

string $value

Throws

\InvalidArgumentException

Returns

string

resolveNestedVariables()

resolveNestedVariables(  $value) : string

Resolve the nested variables.

Look for ${varname} patterns in the variable value and replace with an existing environment variable.

This was borrowed from the excellent phpdotenv with very few changes. https://github.com/vlucas/phpdotenv

Parameters

$value

Returns

string

getVariable()

getVariable(string  $name) : string|null

Search the different places for environment variables and return first value found.

This was borrowed from the excellent phpdotenv with very few changes. https://github.com/vlucas/phpdotenv

Parameters

string $name

Returns

string|null