diff --git a/lib/Doctrine/Db.php b/lib/Doctrine/Db.php index 0e671705a..211cc3752 100644 --- a/lib/Doctrine/Db.php +++ b/lib/Doctrine/Db.php @@ -199,6 +199,10 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte if ($this->isConnected) return false; + $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::CONNECT); + + $this->listener->onPreConnect($event); + $this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine_Db_Statement', array($this))); @@ -212,6 +216,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte } $this->isConnected = true; + + $this->listener->onConnect($event); return true; } diff --git a/lib/Doctrine/Db/Event.php b/lib/Doctrine/Db/Event.php index c18a8db1e..bdc964804 100644 --- a/lib/Doctrine/Db/Event.php +++ b/lib/Doctrine/Db/Event.php @@ -38,6 +38,7 @@ class Doctrine_Db_Event const BEGIN = 5; const COMMIT = 6; const ROLLBACK = 7; + const CONNECT = 8; protected $invoker; protected $query; @@ -54,8 +55,6 @@ class Doctrine_Db_Event $this->invoker = $invoker; $this->type = $type; $this->query = $query; - - } public function getQuery() { diff --git a/lib/Doctrine/Db/EventListener.php b/lib/Doctrine/Db/EventListener.php index a340919a6..4456a6a53 100644 --- a/lib/Doctrine/Db/EventListener.php +++ b/lib/Doctrine/Db/EventListener.php @@ -31,6 +31,11 @@ */ class Doctrine_Db_EventListener implements Doctrine_Db_EventListener_Interface { + public function onPreConnect(Doctrine_Db_Event $event) + { } + public function onConnect(Doctrine_Db_Event $event) + { } + public function onPreQuery(Doctrine_Db_Event $event) { } public function onQuery(Doctrine_Db_Event $event) diff --git a/lib/Doctrine/Db/EventListener/Chain.php b/lib/Doctrine/Db/EventListener/Chain.php index 896614e44..11c0ae7e0 100644 --- a/lib/Doctrine/Db/EventListener/Chain.php +++ b/lib/Doctrine/Db/EventListener/Chain.php @@ -67,6 +67,18 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin $this->listeners[$name] = $listener; } + public function onPreConnect(Doctrine_Db_Event $event) + { + foreach ($this->listeners as $listener) { + $listener->onPreConnect($event); + } + } + public function onConnect(Doctrine_Db_Event $event) + { + foreach ($this->listeners as $listener) { + $listener->onConnect($event); + } + } public function onQuery(Doctrine_Db_Event $event) { foreach ($this->listeners as $listener) { diff --git a/lib/Doctrine/Db/EventListener/Interface.php b/lib/Doctrine/Db/EventListener/Interface.php index cf4062c0b..98cc5c1e7 100644 --- a/lib/Doctrine/Db/EventListener/Interface.php +++ b/lib/Doctrine/Db/EventListener/Interface.php @@ -26,6 +26,9 @@ * @package Doctrine */ interface Doctrine_Db_EventListener_Interface { + public function onPreConnect(Doctrine_Db_Event $event); + public function onConnect(Doctrine_Db_Event $event); + public function onPreQuery(Doctrine_Db_Event $event); public function onQuery(Doctrine_Db_Event $event);