Pre/Post event methods #20

Closed
opened 2017-06-20 00:16:21 +00:00 by jamie · 5 comments
jamie commented 2017-06-20 00:16:21 +00:00 (Migrated from git.hazaar.io)

A situation has arisen where I would like to chain some events together because they get triggered at the same time, however one relies on the other to set some data first. I can change my trigger method in the application, however I would like to support a specific trigger format (specific to the application) that allows events to get triggered in a chain.

The solution I have come up with is a pre/post event methods. Basically I would like to have generic Service::beforeEvent($raw_packet) and Service::afterEvent($raw_packet) methods that get executed before and after EVERY event method. This was I can have a single method that can inspect the trigger payload to see if needs to do other things before or after an event. This should allow me to chain my events, but I think this is a nice feature to have so that developers can execute common code regardless of the event being triggered at the time the event is received.

I have also added the ability to return FALSE from these methods to abort further execution. Obviously except for afterEvent(). So if beforeEvent() returns false, the event method is not executed. If the event methods returns false, then the afterEvent() method is not executed.

Normally these methods don't return anything (ie: return null) so if a true/null/or anything else is returned, then execution will continue.

A situation has arisen where I would like to chain some events together because they get triggered at the same time, however one relies on the other to set some data first. I can change my trigger method in the application, however I would like to support a specific trigger format (specific to the application) that allows events to get triggered in a chain. The solution I have come up with is a pre/post event methods. Basically I would like to have generic ```Service::beforeEvent($raw_packet)``` and ```Service::afterEvent($raw_packet)``` methods that get executed before and after EVERY event method. This was I can have a single method that can inspect the trigger payload to see if needs to do other things before or after an event. This should allow me to chain my events, but I think this is a nice feature to have so that developers can execute common code regardless of the event being triggered at the time the event is received. I have also added the ability to return ```FALSE``` from these methods to abort further execution. Obviously except for ```afterEvent()```. So if ```beforeEvent()``` returns false, the event method is not executed. If the event methods returns false, then the ```afterEvent()``` method is not executed. Normally these methods don't return anything (ie: return null) so if a true/null/or anything else is returned, then execution will continue.
jamie commented 2017-06-20 00:21:11 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2017-06-20 00:21:12 +00:00 (Migrated from git.hazaar.io)

assigned to @jamie

assigned to @jamie
jamie commented 2017-06-20 00:23:52 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2017-06-20 00:42:27 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2017-06-20 00:57:05 +00:00 (Migrated from git.hazaar.io)

closed via commit f11fbc1722

closed via commit f11fbc17229a726275db90d67d124aa7828ba17f
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/hazaar-warlock#20
No description provided.