From b6642e2dce173801f302be2360aa87b94209d952 Mon Sep 17 00:00:00 2001 From: romanb Date: Fri, 12 Sep 2008 10:55:06 +0000 Subject: [PATCH] moved event stuff --- lib/Doctrine/{ => Common}/EventManager.php | 6 +-- lib/Doctrine/Common/EventSubscriber.php | 39 +++++++++++++++++++ lib/Doctrine/{ => Common/Events}/Event.php | 4 +- lib/Doctrine/Connection.php | 2 +- lib/Doctrine/ConnectionFactory.php | 4 +- lib/Doctrine/EntityManager.php | 2 +- tests/lib/Doctrine_OrmTestSuite.php | 2 +- .../lib/mocks/Doctrine_EntityManagerMock.php | 4 +- 8 files changed, 51 insertions(+), 12 deletions(-) rename lib/Doctrine/{ => Common}/EventManager.php (95%) create mode 100644 lib/Doctrine/Common/EventSubscriber.php rename lib/Doctrine/{ => Common/Events}/Event.php (95%) diff --git a/lib/Doctrine/EventManager.php b/lib/Doctrine/Common/EventManager.php similarity index 95% rename from lib/Doctrine/EventManager.php rename to lib/Doctrine/Common/EventManager.php index 6c2b3dfb0..b679df1d9 100644 --- a/lib/Doctrine/EventManager.php +++ b/lib/Doctrine/Common/EventManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::Common::Event; +#namespace Doctrine::Common; /** * The EventManager is the central point of Doctrine's event listener system. @@ -30,7 +30,7 @@ * @author Guilherme Blanco * @since 2.0 */ -class Doctrine_EventManager +class Doctrine_Common_EventManager { /** * Map of registered listeners. @@ -107,7 +107,7 @@ class Doctrine_EventManager * * @param Doctrine::Common::Event::EventSubscriber $subscriber The subscriber. */ - public function addEventSubscriber(Doctrine_EventSubscriber $subscriber) + public function addEventSubscriber(Doctrine_Common_EventSubscriber $subscriber) { $this->addEventListener($subscriber->getSubscribedEvents(), $subscriber); } diff --git a/lib/Doctrine/Common/EventSubscriber.php b/lib/Doctrine/Common/EventSubscriber.php new file mode 100644 index 000000000..7333fcaf5 --- /dev/null +++ b/lib/Doctrine/Common/EventSubscriber.php @@ -0,0 +1,39 @@ +. + */ + +#namespace Doctrine::Common; + +/** + * An EventSubscriber knows itself what events it is interested in. + * If an EventSubscriber is added to an EventManager, the manager invokes + * getSubscribedEvents() and registers the subscriber as a listener for all + * returned events. + * + * @author Roman Borschel + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.phpdoctrine.org + * @since 2.0 + * @version $Revision: 4653 $ + */ +interface Doctrine_Common_EventSubscriber +{ + public function getSubscribedEvents(); +} diff --git a/lib/Doctrine/Event.php b/lib/Doctrine/Common/Events/Event.php similarity index 95% rename from lib/Doctrine/Event.php rename to lib/Doctrine/Common/Events/Event.php index 49bea5c6a..37d56a3c3 100644 --- a/lib/Doctrine/Event.php +++ b/lib/Doctrine/Common/Events/Event.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::ORM::Events; +#namespace Doctrine::Common::Events; /** * Doctrine_Event @@ -32,7 +32,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_Event +class Doctrine_Common_Events_Event { /* Event callback constants */ const preDelete = 'preDelete'; diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index a9b9def14..f6d91fe88 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -175,7 +175,7 @@ class Doctrine_Connection $this->_config = new Doctrine_Configuration(); } if ( ! $eventManager) { - $this->_eventManager = new Doctrine_EventManager(); + $this->_eventManager = new Doctrine_Common_EventManager(); } // create platform diff --git a/lib/Doctrine/ConnectionFactory.php b/lib/Doctrine/ConnectionFactory.php index 2c7a06c17..a5c2241e3 100644 --- a/lib/Doctrine/ConnectionFactory.php +++ b/lib/Doctrine/ConnectionFactory.php @@ -59,14 +59,14 @@ class Doctrine_ConnectionFactory * @return Connection */ public function createConnection(array $params, Doctrine_Configuration $config = null, - Doctrine_EventManager $eventManager = null) + Doctrine_Common_EventManager $eventManager = null) { // create default config and event manager, if not set if ( ! $config) { $config = new Doctrine_Configuration(); } if ( ! $eventManager) { - $eventManager = new Doctrine_EventManager(); + $eventManager = new Doctrine_Common_EventManager(); } // check for existing pdo object diff --git a/lib/Doctrine/EntityManager.php b/lib/Doctrine/EntityManager.php index 75f45aa05..9681b505a 100644 --- a/lib/Doctrine/EntityManager.php +++ b/lib/Doctrine/EntityManager.php @@ -149,7 +149,7 @@ class Doctrine_EntityManager * @param string $name */ protected function __construct(Doctrine_Connection $conn, $name, Doctrine_Configuration $config, - Doctrine_EventManager $eventManager) + Doctrine_Common_EventManager $eventManager) { $this->_conn = $conn; $this->_name = $name; diff --git a/tests/lib/Doctrine_OrmTestSuite.php b/tests/lib/Doctrine_OrmTestSuite.php index a2de2a7ee..8dd4694ff 100644 --- a/tests/lib/Doctrine_OrmTestSuite.php +++ b/tests/lib/Doctrine_OrmTestSuite.php @@ -11,7 +11,7 @@ class Doctrine_OrmTestSuite extends Doctrine_TestSuite protected function setUp() { $config = new Doctrine_Configuration(); - $eventManager = new Doctrine_EventManager(); + $eventManager = new Doctrine_Common_EventManager(); $connectionOptions = array( 'driverClass' => 'Doctrine_ConnectionMock', 'user' => 'john', diff --git a/tests/lib/mocks/Doctrine_EntityManagerMock.php b/tests/lib/mocks/Doctrine_EntityManagerMock.php index a02430f59..b5cd28181 100644 --- a/tests/lib/mocks/Doctrine_EntityManagerMock.php +++ b/tests/lib/mocks/Doctrine_EntityManagerMock.php @@ -34,13 +34,13 @@ class Doctrine_EntityManagerMock extends Doctrine_EntityManager * @return unknown */ public static function create($conn, $name, Doctrine_Configuration $config = null, - Doctrine_EventManager $eventManager = null) + Doctrine_Common_EventManager $eventManager = null) { if (is_null($config)) { $config = new Doctrine_Configuration(); } if (is_null($eventManager)) { - $eventManager = new Doctrine_EventManager(); + $eventManager = new Doctrine_Common_EventManager(); } return new Doctrine_EntityManagerMock($conn, $name, $config, $eventManager);