Documentation

Dotenv

Built-in dotenv library. All credit for this library goes to the CodeIgniter Team.

Tags
author

CodeIgniter Team

link
https://codeigniter.com/
version
1.0.0
since
1.0.0
license

MIT https://mit-license.org

Table of Contents

$path  : string
The directory where the .env file can be located.
__construct()  : mixed
Builds the path to our file.
load()  : bool
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)
normaliseVariable()  : array<string|int, mixed>
Parses for assignment, cleans the $name and $value, and ensures that nested variables are handled.
parse()  : array<string|int, mixed>|null
Parse the .env file into an array of key => value
getVariable()  : string|null
Search the different places for environment variables and return first value found.
resolveNestedVariables()  : string
Resolve the nested variables.
sanitizeValue()  : string
Strips quotes from the environment variable value.
setVariable()  : void
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.

Properties

$path

The directory where the .env file can be located.

protected string $path

Methods

__construct()

Builds the path to our file.

public __construct(string $path[, string $file = '.env' ]) : mixed
Parameters
$path : string
$file : string = '.env'
Return values
mixed

load()

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)

public load() : bool
Return values
bool

normaliseVariable()

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

public normaliseVariable(string $name[, string $value = '' ]) : array<string|int, mixed>
Parameters
$name : string
$value : string = ''
Return values
array<string|int, mixed>

parse()

Parse the .env file into an array of key => value

public parse() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

getVariable()

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

protected getVariable(string $name) : string|null

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

Parameters
$name : string
Return values
string|null

resolveNestedVariables()

Resolve the nested variables.

protected resolveNestedVariables(string $value) : string

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 : string
Return values
string

sanitizeValue()

Strips quotes from the environment variable value.

protected sanitizeValue(string $value) : string

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

Parameters
$value : string
Tags
throws
InvalidArgumentException
Return values
string

setVariable()

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.

protected setVariable(string $name[, string $value = '' ]) : void
Parameters
$name : string
$value : string = ''
Return values
void

Search results