hookBefore, hookAfter and replace original method? #3

Open
opened 2019-12-31 12:58:46 -08:00 by pwFoo · 1 comment
pwFoo commented 2019-12-31 12:58:46 -08:00 (Migrated from github.com)

Your example show how to modifiy the arguments before executing the original method ("hookBefore").

But would it possible to replace /stop the execution of the original method? Example from a cms I know.

// $event is the current object with all additional features of the cms like "global" variables, ...
$event->replace = true; // do not execute the original method after the hook finishes

Or "hookAfter" original method is executed to manipulate the output?

$event->return = $value; // manipulate or replace the return value of the original method
Your example show how to modifiy the arguments before executing the original method ("hookBefore"). But would it possible to replace /stop the execution of the original method? Example from a cms I know. ``` // $event is the current object with all additional features of the cms like "global" variables, ... $event->replace = true; // do not execute the original method after the hook finishes ``` Or "hookAfter" original method is executed to manipulate the output? ``` $event->return = $value; // manipulate or replace the return value of the original method ```
pwFoo commented 2019-12-31 13:18:39 -08:00 (Migrated from github.com)

Sorry, hookBefore / hookAfter works as should. Interesting part is how to replace a original method.
If the hooks / methods executed in a loop the return value or a property could be checked to break / skip the loop?

Sorry, hookBefore / hookAfter works as should. Interesting part is how to replace a original method. If the hooks / methods executed in a loop the return value or a property could be checked to break / skip the loop?
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
sciactive/hookphp#3
No description provided.