Commit 88bf7c17 authored by zYne's avatar zYne

new events onConnect and onPreConnect

parent 3c0192db
...@@ -199,6 +199,10 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -199,6 +199,10 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
if ($this->isConnected) if ($this->isConnected)
return false; 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 = 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_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine_Db_Statement', array($this))); $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 ...@@ -212,6 +216,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
} }
$this->isConnected = true; $this->isConnected = true;
$this->listener->onConnect($event);
return true; return true;
} }
......
...@@ -38,6 +38,7 @@ class Doctrine_Db_Event ...@@ -38,6 +38,7 @@ class Doctrine_Db_Event
const BEGIN = 5; const BEGIN = 5;
const COMMIT = 6; const COMMIT = 6;
const ROLLBACK = 7; const ROLLBACK = 7;
const CONNECT = 8;
protected $invoker; protected $invoker;
protected $query; protected $query;
...@@ -54,8 +55,6 @@ class Doctrine_Db_Event ...@@ -54,8 +55,6 @@ class Doctrine_Db_Event
$this->invoker = $invoker; $this->invoker = $invoker;
$this->type = $type; $this->type = $type;
$this->query = $query; $this->query = $query;
} }
public function getQuery() public function getQuery()
{ {
......
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
*/ */
class Doctrine_Db_EventListener implements Doctrine_Db_EventListener_Interface 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 onPreQuery(Doctrine_Db_Event $event)
{ } { }
public function onQuery(Doctrine_Db_Event $event) public function onQuery(Doctrine_Db_Event $event)
......
...@@ -67,6 +67,18 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin ...@@ -67,6 +67,18 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
$this->listeners[$name] = $listener; $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) public function onQuery(Doctrine_Db_Event $event)
{ {
foreach ($this->listeners as $listener) { foreach ($this->listeners as $listener) {
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
* @package Doctrine * @package Doctrine
*/ */
interface Doctrine_Db_EventListener_Interface { 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 onPreQuery(Doctrine_Db_Event $event);
public function onQuery(Doctrine_Db_Event $event); public function onQuery(Doctrine_Db_Event $event);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment