private function buildListener($name, $data, &$listeners)
    {
        static $defaults = ['priority' => 0, 'once' => false];

        // If a callable is provided, normalize it to the array format.
        if (is_callable($data)) {
            $data = ['fn' => $data];
        }

        // Prepare the listener and add it to the array, recursively.
        if (isset($data['fn'])) {
            $data['name'] = $name;
            $listeners[] = $data + $defaults;
        } elseif (is_array($data)) {
            foreach ($data as $listenerData) {
                $this->buildListener($name, $listenerData, $listeners);
            }
        } else {
            throw new \InvalidArgumentException('Each event listener must be a '
                . 'callable or an associative array containing a "fn" key.');
        }
    }
private function buildListener($name, $data, &$listeners)
    {
        static $defaults = ['priority' => 0, 'once' => false];

        // If a callable is provided, normalize it to the array format.
        if (is_callable($data)) {
            $data = ['fn' => $data];
        }

        // Prepare the listener and add it to the array, recursively.
        if (isset($data['fn'])) {
            $data['name'] = $name;
            $listeners[] = $data + $defaults;
        } elseif (is_array($data)) {
            foreach ($data as $listenerData) {
                $this->buildListener($name, $listenerData, $listeners);
            }
        } else {
            throw new \InvalidArgumentException('Each event listener must be a '
                . 'callable or an associative array containing a "fn" key.');
        }
    }
private function buildListener ( $ name , $ data , & $ listeners ) { static $ defaults = [ 'priority' => 0 , 'once' => false ] ; // If a callable is provided, normalize it to the array format. if ( is_callable ( $ data ) ) { $ data = [ 'fn' => $ data ] ; } // Prepare the listener and add it to the array, recursively. if ( isset ( $ data [ 'fn' ] ) ) { $ data [ 'name' ] = $ name ; $ listeners [ ] = $ data + $ defaults ; } elseif ( is_array ( $ data ) ) { foreach ( $ data as $ listenerData ) { $ this -> buildListener ( $ name , $ listenerData , $ listeners ) ; } } else { throw new \ InvalidArgumentException ( 'Each event listener must be a ' . 'callable or an associative array containing a "fn" key.' ) ; } }
Creates a complete event listener definition from the provided array of
listener data. Also works recursively if more than one listeners are
contained in the provided array.

@param string         $name      Name of the event the listener is for.
@param array|callable $data      Event listener data to prepare.
@param array          $listeners Array of listeners, passed by reference.

@throws \InvalidArgumentException if the event data is malformed.
Creates a complete event listener definition from the provided array of listener data . Also works recursively if more than one listeners are contained in the provided array .