Documentation

Config
in package

AbstractYes

A config helper.

This supports a 'cascading' config system. Each config is able to inherit and override values from the preceding config.

This supports both $config and return syntaxes.

$config['key'] = $config['key'] + 1;
return [ 'key' => $config['key'] + 1 ];

Implement the getPaths() method for your project.

Table of Contents

Properties

$cache  : array<string, array<string|int, mixed>>
$instances  : array<string, mixed>
$loaded  : array<string, array<string|int, bool>>
$overrides  : array<string, mixed>

Methods

apply()  : bool
Load and merge configs.
find()  : array<string|int, mixed>
Does this config exist?
get()  : mixed|null
Fetch a config value.
getPaths()  : array<string|int, mixed>
Get the paths to load configs from.
instance()  : static
Get or create an instance of this config.
load()  : array<string|int, mixed>
Load just one config file.
query()  : mixed|null
Returns the value of a key, defined by a 'dot-noted' string, from an array.
querySet()  : void
Sets values in an array by using a 'dot-noted' string.
set()  : void
Set a config override value.

Properties

$cache

protected array<string, array<string|int, mixed>> $cache = []

name => config

$instances

protected static array<string, mixed> $instances = []

name => instance

$loaded

protected array<string, array<string|int, bool>> $loaded = []

name => [paths]

$overrides

protected array<string, mixed> $overrides = []

name => [key => value]

Methods

apply()

Load and merge configs.

public static apply(array<string|int, mixed> &$config, string $path[, string $name = 'config' ]) : bool
Parameters
$config : array<string|int, mixed>
$path : string
$name : string = 'config'
Tags
throws
RuntimeException

if a recursive config file is detected.

Return values
bool

find()

Does this config exist?

public find(string $name) : array<string|int, mixed>
Parameters
$name : string
Tags
throws
InvalidArgumentException

on an invalid config name.

Return values
array<string|int, mixed>

get()

Fetch a config value.

public static get(string $key[, bool $required = true ]) : mixed|null
Parameters
$key : string

a query string like 'foo.bar.baz'

$required : bool = true
Tags
throws
InvalidArgumentException

When a config doesn't exist.

RuntimeException

if a recursive config file is detected.

Return values
mixed|null

getPaths()

Get the paths to load configs from.

public abstract getPaths() : array<string|int, mixed>
Return values
array<string|int, mixed>

instance()

Get or create an instance of this config.

public static instance([bool $refresh = false ]) : static
Parameters
$refresh : bool = false
Return values
static

load()

Load just one config file.

public static load(string $path[, string $name = 'config' ]) : array<string|int, mixed>

This does not apply overrides, nor uses $paths or caches.

Parameters
$path : string
$name : string = 'config'
Tags
throws
RuntimeException

if a recursive config file is detected.

Return values
array<string|int, mixed>

query()

Returns the value of a key, defined by a 'dot-noted' string, from an array.

public static query(array<string|int, mixed> $array, string $query) : mixed|null
Parameters
$array : array<string|int, mixed>

array to search

$query : string

dot-noted string: foo.bar.baz

Return values
mixed|null

querySet()

Sets values in an array by using a 'dot-noted' string.

public static querySet(array<string|int, mixed> &$array, string $query[, mixed $value = null ]) : void
Parameters
$array : array<string|int, mixed>

array to set keys in (reference)

$query : string

dot-noted string: foo.bar.baz

$value : mixed = null

fill value for the key

set()

Set a config override value.

public static set(string $key, mixed $value) : void
Parameters
$key : string

a query string like 'foo.bar.baz'

$value : mixed
On this page

Search results