Index

Configuration

MMO\core · 1 symbol · generated 5 Oct 2026

class

Configuration

Configuration.php:19

The framework's central configuration/DI container: a nested array of settings and lazily-instantiated objects (unserialize's '$' => ClassName convention), addressable by path (get/walk) and mergeable from multiple sources (load).

class MMO\core\Configuration extends MMO\core\helpers\Container implements MMO\core\interfaces\iSingleton
Namespace
MMO\core
Extends
Container
Implements
iSingleton
Configuration::Shared()->load(['MyClass' => ['option' => 'value']]); Configuration::Shared()->get('MyClass/option'); // 'value'

Index

createInstance($class, $args)Create a new instance using default arguments stored in the configuration: 1.
freeInstance($class, $config)Release an already-unserialized instance stored at $class's own key (the following get/getInstance call re-creates it).
get($id, $default)
getInstance($class)Unserialize an instance stored in the configuration.
hasInstance($class)
IsShared() static
load($configs)Merge one or more configurations into the current one (inject), in order -- each $configs argument is either an already-decoded array, or a path to a .php file (returning an…
onCreate($event)
Shared() static
Unshare() staticRemove the shared instance
__construct()Registers this instance for Create event dispatch (onCreate) via connect.

Methods11

createInstance($class, $args)

Configuration.php:153
Create a new instance using default arguments stored in the configuration: 1. If a configuration is set at the classname (if instantiating class `MyClass`, it will look for a configuration set at `MyClass`), it is injected in the current given arguments.function createInstance(string $class, array $args = []): object2. If the arguments has the key `$`, the instance is created by unserializing the arguments (WARNING: constructor won't be called) Else, the arguments are unserialized and then the class constructor is called with these arguments. ## Using the key `$` NOTE: be careful, when using the `$` configuration, the constructor is not called, as the process become an unserialization. - You can change the classname to instantiate: - You can set a factory to create the class:
$classstringthe classname to instantiate or a valid path in the config. If it is a path, there MUST be the key '$' in the configuration to indicate which class to instantiate.
$args = []array
returnsobject
throwsif the configuration is invalid or no class is defined
throwsif the class does not exist
throwsif an instance is already present at the path and cannot be injected
with the configuration [MyClass:class => ['$' => MyOtherClass::class]], createInstance(MyClass:class) => MyOtherClass{}function createMyClass(...$args) {return new MyOtherClass(...$args);} with the configuration [MyClass:class => ['$' => 'createMyClass']],

freeInstance($class, $config)

Configuration.php:204

Release an already-unserialized instance stored at $class's own key (the following get/getInstance call re-creates it).

function freeInstance(string $class, ?array $config = null): bool
$classstring
$config = nullnull | arrayif given, replaces the stored config entry with this (a fresh instance will be built from it next); if null, the key is removed entirely (falls back to whatever load put there, if anything).
returnsboolfalse if $class had no instance stored there (nothing to free).

get($id, $default)

Configuration.php:102
function get($id, mixed $default = null): mixed
$ida /-separated path into the configuration tree.
$default = nullmixedreturned if $id doesn't exist -- only if actually passed (checked via func_num_args(), so passing null explicitly still suppresses the exception); if omitted, a missing $id throws instead.
returnsmixedthe value at $id -- if it (or an ancestor along the path) is a serialized object descriptor (isSerialized), it's lazily unserialized into a real object (and cached in place) the first time it's reached.
throwsif $id doesn't exist and $default wasn't passed.
Configuration::Shared()->get('MyClass/missing', 'fallback'); // 'fallback', no exception

getInstance($class)

Configuration.php:187

Unserialize an instance stored in the configuration.

function getInstance(string $class): objectSimilar to get, but if no configuration is found, it will create an instance of this class anyway (get will throw an exception) and store it at its classname.
$classstring
returnsobject

hasInstance($class)

Configuration.php:214
function hasInstance(string $class): bool
$classstring
returnsboolwhether $class's own key currently holds an already-unserialized object (vs. raw config, or nothing).

IsShared()

staticConfiguration.php:40
static function IsShared(): bool
returnsboolwhether the shared instance has been created yet.

load($configs)

Configuration.php:51

Merge one or more configurations into the current one (inject), in order -- each $configs argument is either an already-decoded array, or a path to a .php file (returning an array) or .json file to load one from.

function load(array|string ...$configs): void
...$configsarray | string
returnsvoid
throwsif a string config's extension isn't .php/.json, or a .php config doesn't return an array.

onCreate($event)

Configuration.php:240
#[MMO\core\attributes\Listen('MMO\\core\\events\\Create', order: 100)] function onCreate(MMO\core\events\Create $event): void
See
Create event handler: fulfills any not-yet-handled Create event via createInstance.
$eventCreate
returnsvoid
Inherited members (32)
ConstantsDeclared byDescription
MAX_REFERENCE_DEPTHContainer
PropertiesDeclared byDescription
contentContainer
idContainer
IDSContainer
parentContainer
MethodsDeclared byDescription
clear()ContainerEmpty the underlying content, keeping the object itself.
count()Container\Countable::count
delete($id)ContainerRemove the value at $id and return it.
Exists($url)Container
Fetch($url)ContainerGet the container registered under $url ($IDS), fetching (and caching) it via the Fetch event if it isn't already loaded.
getContent()Container
getId()Container
getIterator()Container\IteratorAggregate::getIterator
getParent()Container
getRoot()Container
has($id)Container
inject($id, $config, $recursive)ContainerMerge $config into the content at $id (each of $config's own keys is injected at $id/$key).
isEmpty()Container
jsonSerialize($options)Container
keys()Container
loadArray($data)ContainerLoad every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g.
offsetExists($key)Container\ArrayAccess::offsetExists
offsetGet($key)Container\ArrayAccess::offsetGet
offsetSet($key, $value)Container\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.
offsetUnset($key)Container\ArrayAccess::offsetUnset -- on a list (sequential integer keys, as produced by $bag[] = ...), the element is spliced out (closing the gap and reindexing), matching \unset() semantics on a plain …
push($id, $value, $create)ContainerPush a value in content
set($id, $value, $create)ContainerSet a value at $id, creating intermediate structure as needed.
setContent($content)ContainerReplace the whole content wholesale.
setId($id)Container
toArray()ContainerConvert the content to a plain array, recursively converting any nested iArray value (e.g.
UnFetch($url)ContainerForget the container registered under $url (it can be Fetch-ed again afterward, rebuilding it).
UnFetchAll()ContainerForget every registered container.