PHP Класс Dotenv\Loader

Loads Variables by reading a file from disk and: - stripping comments beginning with a # - parsing lines that look shell variable setters, e.g export key = value, key="value"
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$filePath string The file path.
$immutable boolean Are we immutable?

Открытые методы

Метод Описание
__construct ( string $filePath, boolean $immutable = false ) : void Create a new loader instance.
clearEnvironmentVariable ( string $name ) : void Clear an environment variable.
getEnvironmentVariable ( string $name ) : string | null Search the different places for environment variables and return first value found.
load ( ) : array Load .env file in given directory.
processFilters ( string $name, string $value ) : array Process the runtime filters.
setEnvironmentVariable ( string $name, string | null $value = null ) : void Set an environment variable.

Защищенные методы

Метод Описание
beginsWithAQuote ( string $value ) : boolean Determine if the given string begins with a quote.
ensureFileIsReadable ( ) : void Ensures the given filePath is readable.
isComment ( string $line ) : boolean Determine if the line in the file is a comment, e.g. begins with a #.
looksLikeSetter ( string $line ) : boolean Determine if the given line looks like it's setting a variable.
normaliseEnvironmentVariable ( string $name, string $value ) : array Normalise the given environment variable.
readLinesFromFile ( string $filePath ) : array Read lines from the file, auto detecting line endings.
resolveNestedVariables ( string $value ) : mixed Resolve the nested variables.
sanitiseVariableName ( string $name, string $value ) : array Strips quotes and the optional leading "export " from the environment variable name.
sanitiseVariableValue ( string $name, string $value ) : array Strips quotes from the environment variable value.
splitCompoundStringIntoParts ( string $name, string $value ) : array Split the compound string into parts.

Описание методов

__construct() публичный Метод

Create a new loader instance.
public __construct ( string $filePath, boolean $immutable = false ) : void
$filePath string
$immutable boolean
Результат void

beginsWithAQuote() защищенный Метод

Determine if the given string begins with a quote.
protected beginsWithAQuote ( string $value ) : boolean
$value string
Результат boolean

clearEnvironmentVariable() публичный Метод

This is not (currently) used by Dotenv but is provided as a utility method for 3rd party code. This is done using: - putenv, - unset($_ENV, $_SERVER).
См. также: setEnvironmentVariable()
public clearEnvironmentVariable ( string $name ) : void
$name string
Результат void

ensureFileIsReadable() защищенный Метод

Ensures the given filePath is readable.
protected ensureFileIsReadable ( ) : void
Результат void

getEnvironmentVariable() публичный Метод

Search the different places for environment variables and return first value found.
public getEnvironmentVariable ( string $name ) : string | null
$name string
Результат string | null

isComment() защищенный Метод

Determine if the line in the file is a comment, e.g. begins with a #.
protected isComment ( string $line ) : boolean
$line string
Результат boolean

load() публичный Метод

Load .env file in given directory.
public load ( ) : array
Результат array

looksLikeSetter() защищенный Метод

Determine if the given line looks like it's setting a variable.
protected looksLikeSetter ( string $line ) : boolean
$line string
Результат boolean

normaliseEnvironmentVariable() защищенный Метод

Takes value as passed in by developer and: - ensures we're dealing with a separate name and value, breaking apart the name string if needed, - cleaning the value of quotes, - cleaning the name of quotes, - resolving nested variables.
protected normaliseEnvironmentVariable ( string $name, string $value ) : array
$name string
$value string
Результат array

processFilters() публичный Метод

Called from the VariableFactory, passed as a callback in $this->loadFromFile().
public processFilters ( string $name, string $value ) : array
$name string
$value string
Результат array

readLinesFromFile() защищенный Метод

Read lines from the file, auto detecting line endings.
protected readLinesFromFile ( string $filePath ) : array
$filePath string
Результат array

resolveNestedVariables() защищенный Метод

Look for {$varname} patterns in the variable value and replace with an existing environment variable.
protected resolveNestedVariables ( string $value ) : mixed
$value string
Результат mixed

sanitiseVariableName() защищенный Метод

Strips quotes and the optional leading "export " from the environment variable name.
protected sanitiseVariableName ( string $name, string $value ) : array
$name string
$value string
Результат array

sanitiseVariableValue() защищенный Метод

Strips quotes from the environment variable value.
protected sanitiseVariableValue ( string $name, string $value ) : array
$name string
$value string
Результат array

setEnvironmentVariable() публичный Метод

This is done using: - putenv, - $_ENV, - $_SERVER. The environment variable value is stripped of single and double quotes.
public setEnvironmentVariable ( string $name, string | null $value = null ) : void
$name string
$value string | null
Результат void

splitCompoundStringIntoParts() защищенный Метод

If the $name contains an = sign, then we split it into 2 parts, a name & value disregarding the $value passed in.
protected splitCompoundStringIntoParts ( string $name, string $value ) : array
$name string
$value string
Результат array

Описание свойств

$filePath защищенное свойство

The file path.
protected string $filePath
Результат string

$immutable защищенное свойство

Are we immutable?
protected bool $immutable
Результат boolean