Documentation

Config
in package

Provides static methods to get and set configuration values from the `core/config.php` file.

Tags
author

Samerton

version
2.0.0
license

MIT

Table of Contents

Properties

$_config_cache  : array<string|int, mixed>|null

Methods

all()  : array<string|int, mixed>
Read `core/config.php` file and load into cache.
exists()  : bool
get()  : false|mixed
Get a config value from `core/config.php` file.
set()  : void
Write a value to `core/config.php` file.
setMultiple()  : void
Write multiple values to `core/config.php` file.
write()  : void
Overwrite new `core/config.php` file.
writeable()  : bool
arrayToString()  : string
Converts an array to a string to be inserted into the config file, with shorthand array syntax.
parsePath()  : string|array<string|int, mixed>
Parse a string path to an array of config paths.

Properties

$_config_cache

private static array<string|int, mixed>|null $_config_cache = \null

Methods

all()

Read `core/config.php` file and load into cache.

public static all() : array<string|int, mixed>
Return values
array<string|int, mixed>

The entire config array

exists()

public static exists() : bool
Return values
bool

Whether config file exists

get()

Get a config value from `core/config.php` file.

public static get(string $path[, mixed $fallback = null ]) : false|mixed
Parameters
$path : string

. seperated path of key to get from config file.

$fallback : mixed = null

Value to return if option is not present in config file. If set to null, false is returned.

Tags
throws
RuntimeException

If the config file is not found.

Return values
false|mixed

Returns false if key doesn't exist, otherwise returns the value.

set()

Write a value to `core/config.php` file.

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

. seperated path of key to set.

$value : mixed

Value to set under $key.

setMultiple()

Write multiple values to `core/config.php` file.

public static setMultiple(array<string|int, mixed> $values) : void
Parameters
$values : array<string|int, mixed>

Array of key/value pairs

write()

Overwrite new `core/config.php` file.

public static write(array<string|int, mixed> $config) : void
Parameters
$config : array<string|int, mixed>

New config array to store.

writeable()

public static writeable() : bool
Return values
bool

Whether /core folder is writable to create config.php file in, or if the file exists and is writable.

arrayToString()

Converts an array to a string to be inserted into the config file, with shorthand array syntax.

private static arrayToString(array<string|int, mixed> $config) : string
Parameters
$config : array<string|int, mixed>

Config array to convert to string.

Tags
link
https://gist.github.com/Bogdaan/ffa287f77568fcbb4cffa0082e954022
Return values
string

PHP code for the config array

parsePath()

Parse a string path to an array of config paths.

private static parsePath(string $path) : string|array<string|int, mixed>

Will log a warning if a legacy path (using / is used).

Parameters
$path : string

Path to parse.

Return values
string|array<string|int, mixed>

Path split into sections or plain string if no section seperator was found.


        
On this page

Search results