/** * Insert a new event type * @param string $name * @param int|float $priority */ private function insert($name, $priority = 0) { if ($priority instanceof Event) { /* assignement in the form: * $proxy->foo = new Event("foo", 123); */ $event = $priority; $priority = $event->getPriority(); /* sanity check */ if ($name !== $event->getName()) { throw new \UnexpectedValueException(sprintf("The event names differ: '%s' <> '%s'", $name, $event->getName())); } } elseif (isset($this->events[$name])) { throw new \UnexpectedValueException(sprintf("The event name '%s' is already in use", $name)); } else { $event = new Event($name); } $bucket = $this->storage->insert($event, $priority); $event->setPriority($bucket->getPriority()); $this->events[$name] = $event; }
/** * Attach an event observer * @param \SplObserver $observer * @param float $priority * @return \hikke\Event */ public function attach(\SplObserver $observer, $priority = 0) { $this->storage->insert($observer, $priority); return $this; }