src/Event/Emitter.php
public function on($name, $callback) 
    {

        if(!is_a($callback, '\Moxy\Event\ListenerInterface')) {
            if(!is_callable($callback)) {
                throw new \Exception('Event callback must be a callable');
            }
            // Co-erce the callback into an event listener
            // This allows you to pass either a pure callable or
            // your own listener class
            $callback = new \Moxy\Event\Listener($callback);
        }

        // Set up the Event Dispatcher
        if(!array_key_exists($name, self::$_events)) {
            self::$_events[$name] = new \Moxy\Event\Dispatcher($name);
        }

        self::$_events[$name]->addListener($callback);

    }
public function on($name, $callback) 
    {

        if(!is_a($callback, '\Moxy\Event\ListenerInterface')) {
            if(!is_callable($callback)) {
                throw new \Exception('Event callback must be a callable');
            }
            // Co-erce the callback into an event listener
            // This allows you to pass either a pure callable or
            // your own listener class
            $callback = new \Moxy\Event\Listener($callback);
        }

        // Set up the Event Dispatcher
        if(!array_key_exists($name, self::$_events)) {
            self::$_events[$name] = new \Moxy\Event\Dispatcher($name);
        }

        self::$_events[$name]->addListener($callback);

    }
public function on ( $ name , $ callback ) { if ( ! is_a ( $ callback , '\Moxy\Event\ListenerInterface' ) ) { if ( ! is_callable ( $ callback ) ) { throw new \ Exception ( 'Event callback must be a callable' ) ; } // Co-erce the callback into an event listener // This allows you to pass either a pure callable or // your own listener class $ callback = new \ Moxy \ Event \ Listener ( $ callback ) ; } // Set up the Event Dispatcher if ( ! array_key_exists ( $ name , self :: $ _events ) ) { self :: $ _events [ $ name ] = new \ Moxy \ Event \ Dispatcher ( $ name ) ; } self :: $ _events [ $ name ] -> addListener ( $ callback ) ; }
Listen for an Event

Binds callback to a named event. You can pass either
a pure PHP callable or a class that implements
\Moxy\Event\ListenerInterface

@author Tom Morton
@param string $name Name of the event
@param callabel $callback Callable to run on triggering of event
@throws \Exception When callback is not callable
Listen for an Event