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

DocumentInit

MMO\core\events · 1 symbole · générée le 27 Oct 2026

class

DocumentInit

DocumentInit.php:18

Dispatched whenever a document's body is (re)set (from Document::__construct or Document::setBody), letting listeners inspect or react to the new body (e.g. logging, validation, normalization hooks).

class MMO\core\events\DocumentInit implements MMO\core\interfaces\iEvent use MMO\core\classes\tEvent
Espace de noms
MMO\core\events
Implémente
iEvent
Utilise les traits
tEvent
DocumentInit::AddListener(function (DocumentInit $e) { \MMO\debug($e, 'document body set: {body}', ['body' => $e->getBody()]); }); new Document(['title' => 'Hello']); // fires the listener above

Index

document readonlyThe document whose body was just set.
Listeners static
AddListener($handler, $order) staticRegister a listener directly (as opposed to ConnectListeners's attribute-based discovery).
ConnectListeners($obj) staticScan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class.
DisconnectListeners($obj) staticUndo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class.
dispatch()Invoke every GetListeners listener with $this.
getBody()
GetListeners() staticCollect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep …
getOrigin()
HasListener($handler) static
RemoveListener($handler) staticRemove the last added handler from the listeners.
Send($args) staticConstruct a new instance of this class with $args, then dispatch it to every listener.
SetListenerOrder($handler, $order) staticChange the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here).
__construct($document)

Propriétés2

document

readonly

The document whose body was just set.

readonly MMO\core\documents\Document $document
Type
Document

Listeners

static
protected static array $Listeners = []
Type
array

Méthodes12

AddListener($handler, $order)

statictEvent.php:62

Register a listener directly (as opposed to ConnectListeners's attribute-based discovery).

static function AddListener(callable $handler, int $order = 0): void
$handlercallablecalled as $handler($eventInstance) when this event class is Send / dispatch-ed
$order = 0intlisteners run in ascending order (lower first); listeners with an equal order run in the order they were added
retournevoid
UserCreated::AddListener(function (UserCreated $e) {...}, 10);

ConnectListeners($obj)

statictEvent.php:37

Scan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class. connect does the actual reflection/registration.

static function ConnectListeners(object|string $obj): void
$objobject | stringan instance (or class name, for static-only listener methods)
retournevoid
lève
class UserService { #[Listen(UserCreated::class, order: 1)] public function onUserCreated(UserCreated $e): void {...} } UserCreated::ConnectListeners(new UserService()); // onUserCreated() is now called on every UserCreated::Send()

DisconnectListeners($obj)

statictEvent.php:49

Undo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class.

static function DisconnectListeners(object|string $obj): void
$objobject | string
retournevoid
lève
UserCreated::DisconnectListeners($service); // $service's #[Listen] methods stop firing

dispatch()

tEvent.php:153

Invoke every GetListeners listener with $this. If the class also implements PSR-14's StoppableEventInterface, dispatch stops early as soon as isPropagationStopped() becomes true.

function dispatch(): static
retournestatic$this, for chaining
(new UserCreated('Marc'))->dispatch(); // what Send() does internally

GetListeners()

statictEvent.php:123

Collect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep insertion order).

static function GetListeners(): array
retournearray[[callable $handler, int $order], ...]
UserCreated::GetListeners(); // [[$handlerB, 5], [$handlerA, 10]] -- lower order first

HasListener($handler)

statictEvent.php:109
static function HasListener(callable|object $handler): bool
$handlercallable | objecteither the exact callable passed to AddListener, or (for a [$obj, $methodName] listener registered via ConnectListeners) just the object, to check whether any of its methods are currently listening
retournebool
UserCreated::HasListener($handler); // true if $handler is currently registeredUserCreated::HasListener($service); // true if any of $service's methods were connected via #[Listen]

RemoveListener($handler)

statictEvent.php:91

Remove the last added handler from the listeners.

static function RemoveListener(callable $handler): boolNOTE: if you added the same handler multiple time, you need to call this function the same amount of times.
$handlercallable
retournebooltrue if a listener was removed

Send($args)

statictEvent.php:143

Construct a new instance of this class with $args, then dispatch it to every listener.

static function Send(mixed ...$args): static
...$argsmixed
retournestaticthe constructed (and dispatched) event instance
UserCreated::Send('Marc'); // equivalent to (new UserCreated('Marc'))->dispatch()

SetListenerOrder($handler, $order)

statictEvent.php:75

Change the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here).

static function SetListenerOrder(callable $handler, int $order): bool
$handlercallable
$orderint
retournebooltrue if $handler was found and its order changed
UserCreated::SetListenerOrder($handler, 20); // moves $handler later in the dispatch order