public function addSubscriber(SubscriberInterface $instance) {

		// make sure that an already registered object is removed before re-registering
		
		$this->removeSubscriber($instance);

		// register object hash

		$this->registeredHashes[] = spl_object_hash($instance);

		// parameters contain at least a method name; additionally a priority can be added
		
		foreach($instance::getEventsToSubscribe() as $eventName => $parameters) {

			$parameters	= (array) $parameters;
			$methodName	= array_shift($parameters); 

			if(count($parameters)) {
				$priority = (int) $parameters[0];
			}
			else {
				$priority = 0;
			}

			if(!isset($this->registry[$eventName]) || !isset($this->registry[$eventName][$priority])) {
				$this->registry[$eventName][$priority] = [];
			}

			$this->registry[$eventName][$priority][] = [$instance, $methodName];

			// force re-sort upon next dispatch

			unset ($this->sortedRegistry[$eventName]);

		}
		
	}
public function addSubscriber(SubscriberInterface $instance) {

		// make sure that an already registered object is removed before re-registering
		
		$this->removeSubscriber($instance);

		// register object hash

		$this->registeredHashes[] = spl_object_hash($instance);

		// parameters contain at least a method name; additionally a priority can be added
		
		foreach($instance::getEventsToSubscribe() as $eventName => $parameters) {

			$parameters	= (array) $parameters;
			$methodName	= array_shift($parameters); 

			if(count($parameters)) {
				$priority = (int) $parameters[0];
			}
			else {
				$priority = 0;
			}

			if(!isset($this->registry[$eventName]) || !isset($this->registry[$eventName][$priority])) {
				$this->registry[$eventName][$priority] = [];
			}

			$this->registry[$eventName][$priority][] = [$instance, $methodName];

			// force re-sort upon next dispatch

			unset ($this->sortedRegistry[$eventName]);

		}
		
	}
public function addSubscriber ( SubscriberInterface $ instance ) { // make sure that an already registered object is removed before re-registering $ this -> removeSubscriber ( $ instance ) ; // register object hash $ this -> registeredHashes [ ] = spl_object_hash ( $ instance ) ; // parameters contain at least a method name; additionally a priority can be added foreach ( $ instance :: getEventsToSubscribe ( ) as $ eventName => $ parameters ) { $ parameters = ( array ) $ parameters ; $ methodName = array_shift ( $ parameters ) ; if ( count ( $ parameters ) ) { $ priority = ( int ) $ parameters [ 0 ] ; } else { $ priority = 0 ; } if ( ! isset ( $ this -> registry [ $ eventName ] ) || ! isset ( $ this -> registry [ $ eventName ] [ $ priority ] ) ) { $ this -> registry [ $ eventName ] [ $ priority ] = [ ] ; } $ this -> registry [ $ eventName ] [ $ priority ] [ ] = [ $ instance , $ methodName ] ; // force re-sort upon next dispatch unset ( $ this -> sortedRegistry [ $ eventName ] ) ; } }
register a subscriber for event types provided by subscriber

@param SubscriberInterface $instance
register a subscriber for event types provided by subscriber