MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

Container

MMO\core\helpers · 1 symbole · générée le 27 Oct 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
Espace de noms
MMO\core\helpers
Implémente
ContainerInterface, iArray, JsonSerializable
Utilise les traits
tArray
Voir
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

Constantes1

MAX_REFERENCE_DEPTH

const MAX_REFERENCE_DEPTH = 10

Propriétés4

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

Méthodes30

clear()

tArray.php:25

Empty the underlying content, keeping the object itself.

function clear()
retourne
$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
retournemixedthe removed value
$container->delete('a/b');

Exists($url)

staticContainer.php:59
static function Exists(string $url): bool
$urlstring
retournebooltrue 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
retournestatic
lèveif the fetched data is neither an array nor an instance of static
lèveif 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.
retournemixedthe extracted data
lèveif 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
retournenull | selfthe container this one was constructed with as its $parent

has($id)

Container.php:196
function has($id): bool
$id
retournebooltrue 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
retournevoid
$container->inject('a', ['d' => 5]);

isEmpty()

tArray.php:33
function isEmpty()
retournetrue 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
retournemixedthe raw content, for json_encode()

keys()

tArray.php:82
function keys(): array
retournearraythe 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
retournevoid
lèveif 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
retournestatic$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
retournebool

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
retournevoid

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
retournevoid
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
retourneArrayAccess | 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
Voir
getRoot instead of $this.
$idstring
$valuemixed
$create = trueboolif false, a missing intermediate segment is not auto-created (raises eItemNotFound instead)
retournevoid
$container->set('a/b', 1);

setContent($content)

Container.php:141

Replace the whole content wholesale.

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

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
retournearray
$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
retournevoid

UnFetchAll()

staticContainer.php:76

Forget every registered container.

static function UnFetchAll(): void
retournevoid

__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