Interesting. I have a couple of observations.
Dude, use the current source on
GitHub :) The sourceforge code is moldy -- lots of changes since then.
If you put this hook in to Model\Read you would never be able to trust the expected return from anything. Any installed module would be able to interfere with any handler no matter if it was the active module or not. Sounds like a free for all that could get unstable very easily, and that is not good.
Doing this to an individual handler (extending and method override) is trivial.
Combine that with the existing
Events class (what XoopsPreload grew into,) and you can accomplish this with less collateral risk.
One of the improvements is the addition of Events::addListener(). You can dynamically listen for any event and have it invoke any callable. This way, you don't have to set up the listeners unless it is needed.
There is no triggerFunction(), but since there is always the chance of more than one listener, you could never really rely on which return value you would get. You would have to include a strategy to combine or choose from possibly multiple returns.
The existing triggerEvent() takes one argument, but that can be anything. Historically, that has often been an array, but using an object as the argument is often a better choice. For
example, the psr4loader event brings the
Psr4ClassLoader object with it, so the preload listeners can just register what they need -- the return is done through the passed object. Even a humble
ArrayObject or
SplQueue can be quite useful here.
Using a custom object for a complex result mechanism would allow you to more cleanly document what is actually occurring, making it easier to use and reuse the solution.
Put these pieces together, you can build something that doesn't open up so many potential issues.