Documentation

MutableEvent extends Event
in package

Mutable events allow the plugins to modify the payload of the event, providing the application with the ability to override the payload.

This is interesting in applications where the payload is passed with the intent of receiving a modified version from the plugin.

For example, if your application wishes to use a plugin to generate a URl to the user's profile, overriding the generic URL that the system may generate itself, you can do something like:

event(new MutableEvent('user.profile.url', $username));

Your plugin can then have a listener like this registered:

event()->on('user.profile.url', function (MutableEvent$e) { $e->setBody('https://yourhomepage/user/' . $e->getOriginal()); });

Since your plugin is always referring to the original body of the event, you never risk generating conflicts (beyond overwriting) between the plugins. So, for example, if your application registers both:

event()->on('user.profile.url', function (MutableEvent$e) { $e->setBody('https://yourhomepage/user/' . $e->getOriginal()); }); event()->on('user.profile.url', function (MutableEvent$e) { $e->setBody('https://youraccountserver/user/' . $e->getOriginal()); });

The system simply will pick the last one, overriding the first one.

Tags
author

César de la Cal Bretschneider cesar@magic3w.com

Table of Contents

$action  : mixed
$body  : mixed
$override  : mixed
__construct()  : mixed
getAction()  : mixed
getBody()  : mixed
getOriginal()  : mixed
setBody()  : mixed

Properties

$action

private mixed $action

Methods

__construct()

public __construct(mixed $action, mixed $body) : mixed
Parameters
$action : mixed
$body : mixed
Return values
mixed

getAction()

public getAction() : mixed
Return values
mixed

getBody()

public getBody() : mixed
Return values
mixed

getOriginal()

public getOriginal() : mixed
Return values
mixed

setBody()

public setBody(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

Search results