src/FuzeWorks/Events.php
public static function addListener($callback, $eventName, $priority = EventPriority::NORMAL)
    {
        // Perform multiple checks
        if (EventPriority::getPriority($priority) == false) {
            throw new EventException('Can not add listener: Unknown priority '.$priority, 1);
        }

        if (!is_callable($callback))
        {
            throw new EventException("Can not add listener: Callback is not callable", 1);
        }

        if (empty($eventName))
        {
            throw new EventException("Can not add listener: No eventname provided", 1);
        }

        if (!isset(self::$listeners[$eventName])) {
            self::$listeners[$eventName] = array();
        }

        if (!isset(self::$listeners[$eventName][$priority])) {
            self::$listeners[$eventName][$priority] = array();
        }

        if (func_num_args() > 3) {
            $args = array_slice(func_get_args(), 3);
        }
        else
        {
            $args = array();
        }

        self::$listeners[$eventName][$priority][] = array($callback, $args);
    }
public static function addListener($callback, $eventName, $priority = EventPriority::NORMAL)
    {
        // Perform multiple checks
        if (EventPriority::getPriority($priority) == false) {
            throw new EventException('Can not add listener: Unknown priority '.$priority, 1);
        }

        if (!is_callable($callback))
        {
            throw new EventException("Can not add listener: Callback is not callable", 1);
        }

        if (empty($eventName))
        {
            throw new EventException("Can not add listener: No eventname provided", 1);
        }

        if (!isset(self::$listeners[$eventName])) {
            self::$listeners[$eventName] = array();
        }

        if (!isset(self::$listeners[$eventName][$priority])) {
            self::$listeners[$eventName][$priority] = array();
        }

        if (func_num_args() > 3) {
            $args = array_slice(func_get_args(), 3);
        }
        else
        {
            $args = array();
        }

        self::$listeners[$eventName][$priority][] = array($callback, $args);
    }
public static function addListener ( $ callback , $ eventName , $ priority = EventPriority :: NORMAL ) { // Perform multiple checks if ( EventPriority :: getPriority ( $ priority ) == false ) { throw new EventException ( 'Can not add listener: Unknown priority ' . $ priority , 1 ) ; } if ( ! is_callable ( $ callback ) ) { throw new EventException ( "Can not add listener: Callback is not callable" , 1 ) ; } if ( empty ( $ eventName ) ) { throw new EventException ( "Can not add listener: No eventname provided" , 1 ) ; } if ( ! isset ( self :: $ listeners [ $ eventName ] ) ) { self :: $ listeners [ $ eventName ] = array ( ) ; } if ( ! isset ( self :: $ listeners [ $ eventName ] [ $ priority ] ) ) { self :: $ listeners [ $ eventName ] [ $ priority ] = array ( ) ; } if ( func_num_args ( ) > 3 ) { $ args = array_slice ( func_get_args ( ) , 3 ) ; } else { $ args = array ( ) ; } self :: $ listeners [ $ eventName ] [ $ priority ] [ ] = array ( $ callback , $ args ) ; }
Adds a function as listener.

@param   mixed   $callback           The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net}
@param   string  $eventName          The name of the event
@param   int     $priority           The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest)
@param   mixed   $parameters,...     Parameters for the listener

@see EventPriority

@throws EventException
Adds a function as listener .