Env
in package
`.env` loading for the `bot.php` / `autoplay.php` entry points.
The base-directory walk-up that has to run BEFORE the Composer autoloader stays inline in the entry scripts; this class covers everything after it.
Tags
Table of Contents
Methods
- flag() : bool
- True unless `getenv($key)` is one of the "off" spellings.
- float() : float
- `getenv($key)` as a float, or `$default` when unset/blank.
- int() : int
- `getenv($key)` as an int, or `$default` when unset/blank.
- load() : void
- Loads `KEY=VALUE` lines from `$path` into the process environment via `putenv()`. Blank lines and `#` comments are skipped, and a key already present in `$_ENV` is left alone (a real environment variable wins).
- locate() : string|null
- Finds the `.env` file: beside `$baseDir`, else in the current working directory. Returns `null` when neither exists.
- string() : string|null
- `getenv($key)` coerced to a non-empty string, or `null`.
Methods
flag()
True unless `getenv($key)` is one of the "off" spellings.
public
static flag(string $key[, bool $default = true ]) : bool
Parameters
- $key : string
- $default : bool = true
Return values
boolfloat()
`getenv($key)` as a float, or `$default` when unset/blank.
public
static float(string $key, float $default) : float
Parameters
- $key : string
- $default : float
Return values
floatint()
`getenv($key)` as an int, or `$default` when unset/blank.
public
static int(string $key, int $default) : int
Parameters
- $key : string
- $default : int
Return values
intload()
Loads `KEY=VALUE` lines from `$path` into the process environment via `putenv()`. Blank lines and `#` comments are skipped, and a key already present in `$_ENV` is left alone (a real environment variable wins).
public
static load(string $path) : void
Parameters
- $path : string
Tags
locate()
Finds the `.env` file: beside `$baseDir`, else in the current working directory. Returns `null` when neither exists.
public
static locate(string $baseDir) : string|null
Parameters
- $baseDir : string
Return values
string|nullstring()
`getenv($key)` coerced to a non-empty string, or `null`.
public
static string(string $key) : string|null
Parameters
- $key : string