public function subscribe($handler, $priority = Event::DEFAULT_CALLBACKS_PRIORITY)
    {
        $_priority = \is_int($priority) ? $priority : self::DEFAULT_CALLBACKS_PRIORITY;
        if (!($_priority >= self::DEFAULT_CALLBACKS_MAX_PRIORITY && $_priority <= self::DEFAULT_CALLBACKS_MIN_PRIORITY)) {
            $_priority = self::DEFAULT_CALLBACKS_PRIORITY;
        }
        if (\array_key_exists($_priority, $this->callbacks)) {
            foreach ($this->callbacks[$_priority] as $callback) {
                if ($callback == $handler) {
                    return $this;
                }
            }
        } else {
            $this->callbacks[$_priority] = [];
        }

        if (\is_string($handler) || \is_callable($handler) || $handler instanceof \Closure) {
            $this->callbacks[$_priority][] = $handler;
        } else if (\is_array($handler)) {
            if (\count($handler) == 2) {
                if ((\is_string($handler[0])         // static call, ['Page',  'handleClick'] --> Page::handleClick()
                        || \is_object($handler[0]))  // method call, [$object, 'handleClick'] --> $object->handleClick()
                        && (\is_string($handler[1]))
                ) {
                    $this->callbacks[$_priority][] = $handler;
                } else { // error, unknown $handler type...
                    throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
                }
            } else { // error, unknown $handler type...
                throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
            }
        } else { // error, unknown $handler type...
            throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
        }

        return $this;
    }
public function subscribe($handler, $priority = Event::DEFAULT_CALLBACKS_PRIORITY)
    {
        $_priority = \is_int($priority) ? $priority : self::DEFAULT_CALLBACKS_PRIORITY;
        if (!($_priority >= self::DEFAULT_CALLBACKS_MAX_PRIORITY && $_priority <= self::DEFAULT_CALLBACKS_MIN_PRIORITY)) {
            $_priority = self::DEFAULT_CALLBACKS_PRIORITY;
        }
        if (\array_key_exists($_priority, $this->callbacks)) {
            foreach ($this->callbacks[$_priority] as $callback) {
                if ($callback == $handler) {
                    return $this;
                }
            }
        } else {
            $this->callbacks[$_priority] = [];
        }

        if (\is_string($handler) || \is_callable($handler) || $handler instanceof \Closure) {
            $this->callbacks[$_priority][] = $handler;
        } else if (\is_array($handler)) {
            if (\count($handler) == 2) {
                if ((\is_string($handler[0])         // static call, ['Page',  'handleClick'] --> Page::handleClick()
                        || \is_object($handler[0]))  // method call, [$object, 'handleClick'] --> $object->handleClick()
                        && (\is_string($handler[1]))
                ) {
                    $this->callbacks[$_priority][] = $handler;
                } else { // error, unknown $handler type...
                    throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
                }
            } else { // error, unknown $handler type...
                throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
            }
        } else { // error, unknown $handler type...
            throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
        }

        return $this;
    }
public function subscribe ( $ handler , $ priority = Event :: DEFAULT_CALLBACKS_PRIORITY ) { $ _priority = \ is_int ( $ priority ) ? $ priority : self :: DEFAULT_CALLBACKS_PRIORITY ; if ( ! ( $ _priority >= self :: DEFAULT_CALLBACKS_MAX_PRIORITY && $ _priority <= self :: DEFAULT_CALLBACKS_MIN_PRIORITY ) ) { $ _priority = self :: DEFAULT_CALLBACKS_PRIORITY ; } if ( \ array_key_exists ( $ _priority , $ this -> callbacks ) ) { foreach ( $ this -> callbacks [ $ _priority ] as $ callback ) { if ( $ callback == $ handler ) { return $ this ; } } } else { $ this -> callbacks [ $ _priority ] = [ ] ; } if ( \ is_string ( $ handler ) || \ is_callable ( $ handler ) || $ handler instanceof \ Closure ) { $ this -> callbacks [ $ _priority ] [ ] = $ handler ; } else if ( \ is_array ( $ handler ) ) { if ( \ count ( $ handler ) == 2 ) { if ( ( \ is_string ( $ handler [ 0 ] ) // static call, ['Page',  'handleClick'] --> Page::handleClick()
 || \ is_object ( $ handler [ 0 ] ) ) // method call, [$object, 'handleClick'] --> $object->handleClick()
 && ( \ is_string ( $ handler [ 1 ] ) ) ) { $ this -> callbacks [ $ _priority ] [ ] = $ handler ; } else { // error, unknown $handler type...
 throw new UnknownEventHandlerTypeException ( "Unknown Event handler type." ) ; } } else { // error, unknown $handler type...
 throw new UnknownEventHandlerTypeException ( "Unknown Event handler type." ) ; } } else { // error, unknown $handler type...
 throw new UnknownEventHandlerTypeException ( "Unknown Event handler type." ) ; } return $ this ; }
Subscribe to this event.

The event handler must be a valid PHP callback. The following are
some examples:

~~~
function ($event) { ... } // anonymous function
[$object, 'handleClick']  // $object->handleClick()
['Page', 'handleClick']   // Page::handleClick()
'handleClick'             // global function handleClick()
~~~

The event handler must be defined with the following signature,

~~~
function ($event)
~~~

where `$event` is an [[Event]] object which includes parameters associated with the event.

@param callable|\Closure|array|string $handler the event handler
@param int $priority
@return EventInterface
@see publish()
@see unsubscribe()
Subscribe to this event .