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"
파일 보기 프로젝트 열기: vlucas/phpdotenv 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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