A new feature for SilverStripe should be ...

Add events system

Currently we have a few ad-hoc events (like preRequestFilter and postRequestFilter), and a few event-like methods that are caught by extensions (onBeforeWrite, etc).

These are both un-ideal from a performance point of view. Both the event raiser and all event handlers need to be loaded at all times, and the event-like behaviour of extensions is one of the things stopping us from replacing them with traits.

Important to this working would be the ability to bind event raisers to event handlers in the config system, while still being able to specify some level of filtering (for instance be able to bind to Page#onAfterWrite not just all onAfterWrite events). This is one reason why a lot of existing PHP event systems wouldn't be useable (they want the handlers to be pre-constructed before binding, even if those events end up never being raised in the particular request).

80 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Hamish Friedlander shared this idea  ·   ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Franco Springveldt commented  · 

        I've started a module like this a couple of weeks ago: https://github.com/fspringveldt/silverstripe-event-mediator/. There's two ways to create events: 1] using the Injector (which works 100%, but uses an Extension - which we're trying to replace - to supply emit method), and 2] using the AopProxyService (which prevents having to call $this->emit so no Extension required). I'll try and get the proxy method working 100% using the proxy.

      • Marcus Nyeholt commented  · 

        So you're kind of talking about something like

        app.on('afterWrite', 'Page', function($args) { // impl; });

        Seems like the kind of thing people should be familiar with :)

      Feedback and Knowledge Base