/** * {@inheritDoc} * * @throws \RuntimeException if the listener method is not callable */ public function addListener($eventName, $listener, $priority = 0) { if (!is_callable($listener)) { throw new \RuntimeException(sprintf('The given callback (%s) for event "%s" is not callable.', $this->getListenerAsString($listener), $eventName)); } $this->priorities[$eventName . '_' . $this->getListenerAsString($listener)] = $priority; parent::addListener($eventName, $listener, $priority); }
/** * {@inheritDoc} * * @throws \RuntimeException if the listener method is not callable */ public function addListener($eventNames, $listener, $priority = 0) { if (!$listener instanceof \Closure) { foreach ((array) $eventNames as $method) { if (!is_callable(array($listener, $method))) { $msg = sprintf('The event method "%s()" is not callable on the class "%s".', $method, get_class($listener)); if (null !== $this->logger) { $this->logger->err($msg); } throw new \RuntimeException($msg); } } } parent::addListener($eventNames, $listener, $priority); }
/** * {@inheritDoc} * * @throws \RuntimeException if the listener method is not callable */ public function addListener($eventName, $listener, $priority = 0) { if (!is_callable($listener)) { if (is_string($listener)) { $typeDefinition = '[string] ' . $listener; } elseif (is_array($listener)) { $typeDefinition = '[array] ' . (is_object($listener[0]) ? get_class($listener[0]) : $listener[0]) . '::' . $listener[1]; } elseif (is_object($listener)) { $typeDefinition = '[object] ' . get_class($listener); } else { $typeDefinition = '[?] ' . var_export($listener, true); } throw new \RuntimeException(sprintf('The given callback (%s) for event "%s" is not callable.', $typeDefinition, $eventName)); } parent::addListener($eventName, $listener, $priority); }