From f7ede572e00369f895caf2d88fb3076711bb7199 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 12 Dec 2011 16:46:53 +0100 Subject: [PATCH] DDC-1415 - Remove EntityEventDelegatee, the API sucks and we need another approach. --- .../ORM/Event/EntityEventDelegator.php | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 lib/Doctrine/ORM/Event/EntityEventDelegator.php diff --git a/lib/Doctrine/ORM/Event/EntityEventDelegator.php b/lib/Doctrine/ORM/Event/EntityEventDelegator.php deleted file mode 100644 index 247c08239..000000000 --- a/lib/Doctrine/ORM/Event/EntityEventDelegator.php +++ /dev/null @@ -1,122 +0,0 @@ -. -*/ - -namespace Doctrine\ORM\Event; - -use Doctrine\Common\EventSubscriber; -use LogicException; - -/** - * Delegate events only for certain entities they are registered for. - * - * @link www.doctrine-project.org - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @since 2.2 - */ -class EntityEventDelegator implements EventSubscriber -{ - /** - * Keeps track of all the event listeners. - * - * @var array - */ - private $listeners = array(); - - /** - * If frozen no new event listeners can be added. - * - * @var bool - */ - private $frozen = false; - - /** - * Adds an event listener that listens on the specified events. - * - * @param string|array $events The event(s) to listen on. - * @param string|array $entities The entities to trigger this listener for - * @param object $listener The listener object. - */ - public function addEventListener($events, $entities, $listener) - { - if ($this->frozen) { - throw new LogicException( - "Cannot add event listeners after EntityEventDelegator::getSubscribedEvents() " . - "is called once. This happens when you register the delegator with the event manager." - ); - } - - // Picks the hash code related to that listener - $hash = spl_object_hash($listener); - $entities = array_flip((array) $entities); - - foreach ((array) $events as $event) { - // Overrides listener if a previous one was associated already - // Prevents duplicate listeners on same event (same instance only) - $this->listeners[$event][$hash] = array( - 'listener' => $listener, - 'entities' => $entities - ); - } - } - - /** - * Adds an EventSubscriber. The subscriber is asked for all the events he is - * interested in and added as a listener for these events. - * - * @param \Doctrine\Common\EventSubscriber $subscriber The subscriber. - * @param array $entities - */ - public function addEventSubscriber(EventSubscriber $subscriber, $entities) - { - $this->addEventListener($subscriber->getSubscribedEvents(), $entities, $subscriber); - } - - /** - * Returns an array of events this subscriber wants to listen to. - * - * @return array - */ - public function getSubscribedEvents() - { - $this->frozen = true; - - return array_keys($this->listeners); - } - - /** - * Delegate the event to an appropriate listener - * - * @param string $eventName - * @param array $args - * @return void - */ - public function __call($eventName, $args) - { - $event = $args[0]; - - foreach ($this->listeners[$eventName] AS $listenerData) { - $class = get_class($event->getEntity()); - - if ( ! isset($listenerData['entities'][$class])) continue; - - $listenerData['listener']->$eventName($event); - } - } -}