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
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…
Configuration.php:153Create 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:
the 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.
if the configuration is invalid or no class is defined
throws
if the class does not exist
throws
if 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']],
if 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).
returned 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.
the 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.
throws
if $id doesn't exist and $default wasn't passed.
Configuration::Shared()->get('MyClass/missing', 'fallback'); // 'fallback', no exception
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.
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.
\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 …