src/Event/EventTarget.php
/**
     * Registers a callback for a specified event on the current node.
     *
     * @param \Rowbot\DOM\Event\EventListener|callable(\Rowbot\DOM\Event\Event): void|null $callback
     * @param bool|array{capture?: bool, passive?: bool, once?: bool}                      $options
     */
Registers a callback for a specified event on the current node.
Registers a callback for a specified event on the current node .
public function addEventListener(string $type, $callback, $options = false): void
    {
        if ($callback === null) {
            return;
        }
        [$capture, $passive, $once] = $this->flattenMoreOptions($options);
        if (is_object($callback) && $callback instanceof EventListener) {
            $callback = [$callback, 'handleEvent'];
        } elseif (is_callable($callback)) {
            $callback = $callback;
        } else {
            return;
        }
        $listener = new Listener($type, $callback, $capture, $once, $passive);
        $found = false;
        foreach ($this->listeners as $l) {
            if ($l->isEqual($listener)) {
                $found = true;
                break;
            }
        }
        if (!$found) {
            $this->listeners[] = $listener;
        }
    }
public function addEventListener ( string $ type , $ callback , $ options = false ) : void { if ( $ callback === null ) { return ; } [ $ capture , $ passive , $ once ] = $ this -> flattenMoreOptions ( $ options ) ; if ( is_object ( $ callback ) && $ callback instanceof EventListener ) { $ callback = [ $ callback , 'handleEvent' ] ; } elseif ( is_callable ( $ callback ) ) { $ callback = $ callback ; } else { return ; } $ listener = new Listener ( $ type , $ callback , $ capture , $ once , $ passive ) ; $ found = false ; foreach ( $ this -> listeners as $ l ) { if ( $ l -> isEqual ( $ listener ) ) { $ found = true ; break ; } } if ( ! $ found ) { $ this -> listeners [ ] = $ listener ; } }
Registers a callback for a specified event on the current node.
Registers a callback for a specified event on the current node .
// If callback is null, terminate these steps.