public function attach($eventName, callable $handler, $priority = 0)
    {
        if (is_array($eventName)) {
            foreach ($eventName as $name) {
                $this->attach($name, $handler, $priority);
            }
            return;
        }
        if (!is_string($eventName)) {
            throw new InvalidArgumentException(sprintf(
                '%s expects argument 1 to be string; %s given.',
                __METHOD__,
                is_object($eventName) ? get_class($eventName) : gettype($eventName)
            ));
        }

        if (!array_key_exists($eventName, $this->events)) {
            $this->events[$eventName] = new CallbackQueue();
        }

        $this->events[$eventName]->add($handler, $priority);
    }
public function attach($eventName, callable $handler, $priority = 0)
    {
        if (is_array($eventName)) {
            foreach ($eventName as $name) {
                $this->attach($name, $handler, $priority);
            }
            return;
        }
        if (!is_string($eventName)) {
            throw new InvalidArgumentException(sprintf(
                '%s expects argument 1 to be string; %s given.',
                __METHOD__,
                is_object($eventName) ? get_class($eventName) : gettype($eventName)
            ));
        }

        if (!array_key_exists($eventName, $this->events)) {
            $this->events[$eventName] = new CallbackQueue();
        }

        $this->events[$eventName]->add($handler, $priority);
    }
public function attach ( $ eventName , callable $ handler , $ priority = 0 ) { if ( is_array ( $ eventName ) ) { foreach ( $ eventName as $ name ) { $ this -> attach ( $ name , $ handler , $ priority ) ; } return ; } if ( ! is_string ( $ eventName ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects argument 1 to be string; %s given.' , __METHOD__ , is_object ( $ eventName ) ? get_class ( $ eventName ) : gettype ( $ eventName ) ) ) ; } if ( ! array_key_exists ( $ eventName , $ this -> events ) ) { $ this -> events [ $ eventName ] = new CallbackQueue ( ) ; } $ this -> events [ $ eventName ] -> add ( $ handler , $ priority ) ; }
Attach an handler to an event or multiple events.
@param  string|array $eventName
Event name or array of event names
@param  callable $handler
@param  int $priority
@throws \InvalidArgumentException
Attach an handler to an event or multiple events .