2017 © Pedro Peláez
 

silverstripe-module silverstripe-event-mediator

A Silverstripe event emitter based on the mediator pattern

image

fspringveldt/silverstripe-event-mediator

A Silverstripe event emitter based on the mediator pattern

  • Monday, January 9, 2017
  • by fspringveldt
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SilverStripe Event Mediator

A SilverStripe event emitter based on the mediator pattern, which can be applied to run a bit of code before or after any class method (i.e. triggered) using Silverstripe's Aspects, (*1)

Requirements

"silverstripe/framework": "3.*"
"composer"

Installation

To install, run below from root of SilverStripe installation:, (*2)

> composer require fspringveldt/silverstripe-event-mediator

http://your-site-url?flush=1 once composer is complete the flush the manifest., (*3)

Configuration 1 - Extension based (default)

Installing the module adds the eventMediator\EventExtension to DataObject. Let's say after each call to $A->foo() you'd like to fire off a call to $B->bar(), the following added to your composer.yml sets up the events:, (*4)

Injector:
  eventMediator\EventMediator':
    properties:
      events:
        foo:
          triggerBar:
            class: B
            method: bar

then in $A->foo() do the following:, (*5)

class A{
    function foo(){
        //foo funciton body

        $this->emit(__FUNCTION__);
    }
}

Configuration 2 - Aspect using AopProxyService

Let's say after each call to $A->foo() you'd like to fire off a call to $B->bar(), the following in your composer.yml should do the trick:, (*6)

Injector:
  'eventMediator\EventMediator':
    properties:
      events:
        foo:
          triggerBar:
            class: B
            method: bar
  ProxiedA:
    class: A
  A:
    class: AopProxyService
    properties:
      proxied: %$ProxiedA
      afterCall:
        foo:
          - %$eventMediator\EventMediator'

All parameters from $A->foo() are sent through $B->foo() for your perusal., (*7)

The Versions

09/01 2017

dev-master

9999999-dev

A Silverstripe event emitter based on the mediator pattern

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Franco Springveldt

events silverstripe event mediator aspects