Index

Container

MMO\core\helpers · 1 symbol · generated 30 Sep 2026

class

Container

Container.php:25

Implementation of PSR ContainerInterface: a nested, json-path-addressable data container (backed by

class MMO\core\helpers\Container implements Psr\Container\ContainerInterface, MMO\core\interfaces\iArray, JsonSerializable use MMO\core\classes\tArray
Namespace
MMO\core\helpers
Implements
ContainerInterface, iArray, JsonSerializable
Uses traits
tArray
See
tArray's plain $content array), usable both as a general-purpose config/data holder and as a dependency container. Containers can be nested (getParent / getRoot), and every instance with a non-null getId is registered process-wide so it can be looked up again by that id (Fetch).
$c = new Container(['a' => ['b' => 1]]); $c->get('a/b'); // 1 $c->set('a/c', 2); $c->has('a/nope'); // false

Index

MAX_REFERENCE_DEPTH
content
id
IDS static
parent
clear()Empty the underlying content, keeping the object itself.
count()\Countable::count
delete($id)Remove the value at $id and return it.
Exists($url) static
Fetch($url) staticGet the container registered under $url ($IDS), fetching (and caching) it via the Fetch event if it isn't already loaded.
get($id, $default)Get a value from the container.
getContent()
getId()
getIterator()\IteratorAggregate::getIterator
getParent()
getRoot()
has($id)
inject($id, $config, $recursive)Merge $config into the content at $id (each of $config's own keys is injected at $id/$key).
isEmpty()
jsonSerialize($options)
keys()
load($configs)Merge one or more configs into this container's content (via inject).
loadArray($data)Load 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)\ArrayAccess::offsetExists
offsetGet($key)\ArrayAccess::offsetGet
offsetSet($key, $value)\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.
offsetUnset($key)\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)Push a value in content
set($id, $value, $create)Set a value at $id, creating intermediate structure as needed.
setContent($content)Replace the whole content wholesale.
setId($id)
toArray()Convert the content to a plain array, recursively converting any nested iArray value (e.g.
UnFetch($url) staticForget the container registered under $url (it can be Fetch-ed again afterward, rebuilding it).
UnFetchAll() staticForget every registered container.
__construct($content, $id, $parent)Create container

Constants1

MAX_REFERENCE_DEPTH

const MAX_REFERENCE_DEPTH = 10

Properties4

content

protected $content = []

id

#[MMO\core\attributes\Serialize(unserialize: 'setId', order: -100)] protected ?string $id = null
Type
null | string

IDS

static
#[MMO\core\attributes\Serialize(false)] protected static array $IDS = []
Type
array

parent

protected ?self $parent
Type
null | self

Methods30

clear()

tArray.php:25

Empty the underlying content, keeping the object itself.

function clear()
returns
$bag->clear(); // count($bag) === 0 afterwards

delete($id)

Container.php:222

Remove the value at $id and return it. A path starting with '/' is applied to getRoot instead of $this.

function delete(string $id): mixed
$idstring
returnsmixedthe removed value
$container->delete('a/b');

Exists($url)

staticContainer.php:59
static function Exists(string $url): bool
$urlstring
returnsbooltrue if a container is currently registered under $url

Fetch($url)

staticContainer.php:46

Get the container registered under $url ($IDS), fetching (and caching) it via the Fetch event if it isn't already loaded.

static function Fetch(string $url): static
$urlstring
returnsstatic
throwsif the fetched data is neither an array nor an instance of static
throwsif nothing answers the Fetch event for $url

get($id, $default)

Container.php:187

Get a value from the container. A path starting with '/' is resolved from getRoot instead of $this, so a nested container can still reach data owned by an ancestor.

function get($id, mixed $default = null): mixed
$idif string, MUST be a valid JSON path.
$default = nullmixedreturned if $id's leaf is missing. See get's own docblock for the exact (and slightly surprising) missing-leaf-vs-missing-intermediate-segment rules.
returnsmixedthe extracted data
throwsif an INTERMEDIATE path segment cannot be resolved (e.g. it isn't an array at all)
$container->get('a/b');$container->get('a/nope', 'fallback');

getParent()

Container.php:118
function getParent(): ?self
returnsnull | selfthe container this one was constructed with as its $parent

has($id)

Container.php:196
function has($id): bool
$id
returnsbooltrue if $id resolves to an actual (possibly null) value
$container->has('a/b');

inject($id, $config, $recursive)

Container.php:251

Merge $config into the content at $id (each of $config's own keys is injected at $id/$key). A path starting with '/' is applied to getRoot instead of $this.

function inject(string $id, array $config, bool $recursive = true): void
$idstring
$configarray
$recursive = trueboolpassed through to inject
returnsvoid
$container->inject('a', ['d' => 5]);

isEmpty()

tArray.php:33
function isEmpty()
returnstrue if the underlying content has no elements
$bag->isEmpty(); // true right after clear(), false as soon as an item is set

jsonSerialize($options)

Container.php:146
function jsonSerialize(array $options = []): mixed
$options = []array
returnsmixedthe raw content, for json_encode()

keys()

tArray.php:82
function keys(): array
returnsarraythe list of keys currently set
$bag->keys(); // e.g. ['x', 0]

load($configs)

Container.php:158

Merge one or more configs into this container's content (via inject).

function load(array|string ...$configs): void
...$configsarray | string
returnsvoid
throwsif a string config resolves to something that isn't an array/Container
$container->load(['a' => 1], 'path/to/config.php');

loadArray($data)

tArray.php:71

Load every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g. for validation or type coercion, is honored for every entry).

function loadArray(array $data): static
$dataarray
returnsstatic$this, for chaining
$bag->loadArray(['x' => 1, 'y' => 2]); // equivalent to $bag['x'] = 1; $bag['y'] = 2;

offsetExists($key)

tArray.php:130

\ArrayAccess::offsetExists

function offsetExists(mixed $key): bool
$keymixed
returnsbool

offsetSet($key, $value)

tArray.php:122

\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.

function offsetSet(mixed $key, mixed $value): void
$keymixed
$valuemixed
returnsvoid

offsetUnset($key)

tArray.php:107

\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 PHP list; on an associative array, the key is simply removed.

function offsetUnset(mixed $key): void
$keymixed
returnsvoid
unset($bag[0]); // on a list: every following index shifts down by one, like array_splice()

push($id, $value, $create)

Container.php:236

Push a value in content

function push(string $id, mixed $value, bool $create = true): ArrayAccess|array
$idstringthe content's path to add value to.
$valuemixedthe value to push
$create = trueboolif false, a missing intermediate segment is not auto-created
returnsArrayAccess | arraya reference on the array in which the value has been pushed
$container->push('list', 'x');

set($id, $value, $create)

Container.php:209

Set a value at $id, creating intermediate structure as needed. A path starting with '/' is applied to

function set(string $id, mixed $value, bool $create = true): void
See
getRoot instead of $this.
$idstring
$valuemixed
$create = trueboolif false, a missing intermediate segment is not auto-created (raises eItemNotFound instead)
returnsvoid
$container->set('a/b', 1);

setContent($content)

Container.php:141

Replace the whole content wholesale.

function setContent(array $content): void
$contentarray
returnsvoid

toArray()

tArray.php:56

Convert the content to a plain array, recursively converting any nested iArray value (e.g. another object using this same trait) into its own plain-array form as well.

function toArray(): array
returnsarray
$inner = new Bag(); $inner['a'] = 1; $outer = new Bag(); $outer['inner'] = $inner; $outer->toArray(); // ['inner' => ['a' => 1]] -- $inner is recursively expanded, not left as an object

UnFetch($url)

staticContainer.php:68

Forget the container registered under $url (it can be Fetch-ed again afterward, rebuilding it).

static function UnFetch(string $url): void
$urlstring
returnsvoid

UnFetchAll()

staticContainer.php:76

Forget every registered container.

static function UnFetchAll(): void
returnsvoid

__construct($content, $id, $parent)

Container.php:89

Create container

function __construct(array $content = [], ?string $id = null, ?self $parent = null)
$content = []array
$id = nullnull | stringif given, registers this container under $id (Fetch / Exists)
$parent = nullnull | self