DiscordPHP-BridgeBot Documentation

Environment
in package

FinalYes

The process environment, plus a `.env` file, read once and shared.

Every connector needs settings of its own, and each one reading the file itself would mean parsing it several times and — worse — disagreeing about precedence. So the app loads this once and hands it to whatever needs it.

The process environment wins over the file, so a container can override a setting without the image being rebuilt or the file edited.

Secrets only ever come from here, never from the JSON store — that is runtime state a server admin edits through chat, and it should be safe to read, back up, or paste into an issue.

Tags
author

Valithor Obsidion valithor@discordphp.org

Table of Contents

Properties

$path  : string
$file  : array<string|int, mixed>

Methods

fromArray()  : self
For tests, and for anything that already has its settings in hand.
get()  : string|null
A setting, or `null` when it is absent or empty.
has()  : bool
Whether every one of these is set, for deciding whether to install a connector at all.
load()  : self
Reads `$path` if it is there, and falls back to the process environment.
or()  : string
A setting, or `$default`.
require()  : string
A setting, or a thrown explanation naming what is missing.
__construct()  : mixed

Properties

$file read-only

private array<string|int, mixed> $file

Methods

fromArray()

For tests, and for anything that already has its settings in hand.

public static fromArray(array<string|int, mixed> $values[, string $path = '' ]) : self
Parameters
$values : array<string|int, mixed>
$path : string = ''
Return values
self

get()

A setting, or `null` when it is absent or empty.

public get(string $key) : string|null
Parameters
$key : string
Return values
string|null

has()

Whether every one of these is set, for deciding whether to install a connector at all.

public has(string ...$keys) : bool
Parameters
$keys : string
Return values
bool

load()

Reads `$path` if it is there, and falls back to the process environment.

public static load(string $path) : self
Parameters
$path : string
Return values
self

or()

A setting, or `$default`.

public or(string $key, string $default) : string
Parameters
$key : string
$default : string
Return values
string

require()

A setting, or a thrown explanation naming what is missing.

public require(string $key) : string
Parameters
$key : string
Tags
throws
RuntimeException
Return values
string

__construct()

private __construct(array<string, string> $file, string $path) : mixed
Parameters
$file : array<string, string>
$path : string
On this page

Search results