Index
# Events Events are special objects that are used to trigger specific behavior. There are two types: - <@\MMO\core\interfaces\iEvent>: simple event, trigger when the application encounters an error, an exception, its shutdown... - <@\MMO\core\interfaces\iSignal>: an event with a returned value. It is used to change the result of an operation, like fetching an url, decoding a file, etc... ## Get Started - In order to attach a callback to an event, you need to call the static function `AddListener` on the event class. - It takes an optional order argument. This is used to order (ASC) the callback when the event is dispatched. By design we use negative order for callback that needs to be called first. - You can dispatch an event either by instantiating a new object and call `dispacth()` or by calling the static method `::Send()`. ## Heritage If you connect to an Event class, you will capture all events from this class or its extended classes. ## <@\MMO\core\attributes\Listen> This attribute allows class to declare methods to handle certain event. You need to call `Event::ConnectListeners($myobject)` to apply these binding. Any module does it already after serialization. ```php fragment class MyObject { #[\MMO\core\attributes\Listen('MyEvent', -5)] public function onMyEvent(MyEvent $event) {..} } ``` ## <@\MMO\core\events\Fetch> The fetch signal is used to retrieve the content from an url. ## References ### See also ## Tags <#event>, <#signal>