/** * {@inheritDoc} */ public function getListenersForClass($instance) { // ignore classes which don't implement the subscriber if (!$instance instanceof EventSubscriber) { return array(); } // grab all the entries returned by getEventListeners() and parse them $listeners = array(); foreach ($instance->getEventListeners() as $i => $item) { // check the definition is in a valid format if (!is_array($item)) { throw Exception::invalidListenerDefinition(get_class($instance)); } // check all data is present if (!isset($item['event'])) { throw Exception::incompleteListenerDefinition(get_class($instance), 'missing event field'); } if (!isset($item['method'])) { throw Exception::incompleteListenerDefinition(get_class($instance), 'missing method field'); } // get the information $listener = array('event' => $item['event'], 'namespace' => null, 'method' => $item['method']); if (isset($item['namespace'])) { $listener['namespace'] = $item['namespace']; } $listeners[] = $listener; } return $listeners; }
/** * {@inheritDoc} */ public function getListenersForClass($instance) { $className = get_class($instance); $listeners = array(); // do some reflection to get the methods $reflClass = new \ReflectionClass($className); $reflMethods = $reflClass->getMethods(\ReflectionMethod::IS_PUBLIC); // process each method's annotations foreach ($reflMethods as $reflMethod) { $annotations = $this->reader->getMethodAnnotations($reflMethod); foreach ($annotations as $annotation) { // get the listeners if (get_class($annotation) == self::ANNOTATION_LISTENER) { if (empty($annotation->event)) { throw Exception::incompleteListenerDefinition(get_class($instance), 'missing event field'); } $listeners[] = array('event' => $annotation->event, 'namespace' => $annotation->namespace, 'method' => $reflMethod->getName()); } } } return $listeners; }