protected function getListenerInfo(CallbackHandler $listener, $identifier = '*') { $info = array('class' => 'Unknown class', 'method' => 'Unknown method', 'identifier' => $identifier); $priority = $listener->getMetadatum('priority'); if (null === $priority) { $priority = 1; } elseif (is_array($priority)) { $priority = array_shift($priority); } $info['priority'] = $priority; $callback = $listener->getCallback(); if (is_array($callback)) { $info['class'] = is_object($callback[0]) ? get_class($callback[0]) : $callback[0]; $info['method'] = $callback[1]; } elseif ($callback instanceof \Closure) { $closureRef = new \ReflectionFunction($callback); if (method_exists($closureRef, 'getClosureThis')) { $info['class'] = get_class($closureRef->getClosureThis()); } else { $info['class'] = $closureRef->getName(); } $info['method'] = 'CLOSURE'; } elseif (is_object($callback)) { $info['class'] = get_class($callback); $info['method'] = 'INVOKABLE'; } return $info; }
public function testCallbackShouldStoreMetadata() { $handler = new CallbackHandler('rand', array('event' => 'foo')); $this->assertEquals('foo', $handler->getMetadatum('event')); $this->assertEquals(array('event' => 'foo'), $handler->getMetadata()); }
/** * Unsubscribe a listener from an event * * @param CallbackHandler $listener * @return bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found */ public function detach(CallbackHandler $listener) { $event = $listener->getMetadatum('event'); if (!$event || empty($this->events[$event])) { return false; } $return = $this->events[$event]->remove($listener); if (!$return) { return false; } if (!count($this->events[$event])) { unset($this->events[$event]); } return true; }