From 68b3a6a9665955ca3c7890390f50d9adeb6f19b3 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 19 Jun 2007 23:34:30 +0000 Subject: [PATCH] new classes Doctrine_Event, Doctrine_Connection_Profiler_Exception and Doctrine_Util --- .../Connection/Profiler/Exception.php | 35 ++++ lib/Doctrine/Event.php | 194 ++++++++++++++++++ lib/Doctrine/Util.php | 36 ++++ 3 files changed, 265 insertions(+) create mode 100644 lib/Doctrine/Connection/Profiler/Exception.php create mode 100644 lib/Doctrine/Event.php create mode 100644 lib/Doctrine/Util.php diff --git a/lib/Doctrine/Connection/Profiler/Exception.php b/lib/Doctrine/Connection/Profiler/Exception.php new file mode 100644 index 000000000..873814ab0 --- /dev/null +++ b/lib/Doctrine/Connection/Profiler/Exception.php @@ -0,0 +1,35 @@ +. + */ +Doctrine::autoload('Doctrine_Connection_Profiler_Exception'); +/** + * Doctrine_Connection_Profiler_Exception + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision: 1345 $ + * @author Konsta Vesterinen + */ +class Doctrine_Connection_Profiler_Exception extends Doctrine_Exception +{ +} diff --git a/lib/Doctrine/Event.php b/lib/Doctrine/Event.php new file mode 100644 index 000000000..7443c0992 --- /dev/null +++ b/lib/Doctrine/Event.php @@ -0,0 +1,194 @@ +. + */ +/** + * Doctrine_Event + * + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Event +{ + /** + * EVENT CODE CONSTANTS + */ + const QUERY = 1; + const EXEC = 2; + const EXECUTE = 3; + const PREPARE = 4; + const BEGIN = 5; + const COMMIT = 6; + const ROLLBACK = 7; + const CONNECT = 8; + const FETCH = 9; + const FETCHALL = 10; + /** + * @var Doctrine_Db $invoker the handler which invoked this event + */ + protected $invoker; + /** + * @var string $query the sql query associated with this event (if any) + */ + protected $query; + /** + * @var string $params the parameters associated with the query (if any) + */ + protected $params; + /** + * @see Doctrine_Db_Event constants + * @var integer $code the event code + */ + protected $code; + /** + * @var integer $startedMicrotime the time point in which this event was started + */ + protected $startedMicrotime; + /** + * @var integer $endedMicrotime the time point in which this event was ended + */ + protected $endedMicrotime; + /** + * constructor + * + * @param Doctrine_Db $invoker the handler which invoked this event + * @param integer $code the event code + * @param string $query the sql query associated with this event (if any) + */ + public function __construct($invoker, $code, $query = null, $params = array()) + { + $this->invoker = $invoker; + $this->code = $code; + $this->query = $query; + $this->params = $params; + } + /** + * getQuery + * + * @return string returns the query associated with this event (if any) + */ + public function getQuery() + { + return $this->query; + } + /** + * getName + * returns the name of this event + * + * @return string the name of this event + */ + public function getName() + { + switch ($this->code) { + case self::QUERY: + return 'query'; + case self::EXEC: + return 'exec'; + case self::EXECUTE: + return 'execute'; + case self::PREPARE: + return 'prepare'; + case self::BEGIN: + return 'begin'; + case self::COMMIT: + return 'commit'; + case self::ROLLBACK: + return 'rollback'; + case self::CONNECT: + return 'connect'; + } + } + /** + * getCode + * + * @return integer returns the code associated with this event + */ + public function getCode() + { + return $this->code; + } + /** + * start + * starts the internal timer of this event + * + * @return void + */ + public function start() + { + $this->startedMicrotime = microtime(true); + } + /** + * hasEnded + * whether or not this event has ended + * + * @return boolean + */ + public function hasEnded() + { + return ($this->endedMicrotime != null); + } + /** + * end + * ends the internal timer of this event + * + * @return void + */ + public function end() + { + $this->endedMicrotime = microtime(true); + } + /** + * getInvoker + * returns the handler that invoked this event + * + * @return Doctrine_Db the handler that invoked this event + */ + public function getInvoker() + { + return $this->invoker; + } + /** + * getParams + * returns the parameters of the query + * + * @return array parameters of the query + */ + public function getParams() + { + return $this->params; + } + /** + * Get the elapsed time (in microseconds) that the event ran. If the event has + * not yet ended, return false. + * + * @return mixed + */ + public function getElapsedSecs() + { + if (is_null($this->endedMicrotime)) { + return false; + } + return ($this->endedMicrotime - $this->startedMicrotime); + } +} diff --git a/lib/Doctrine/Util.php b/lib/Doctrine/Util.php new file mode 100644 index 000000000..d2c374cbc --- /dev/null +++ b/lib/Doctrine/Util.php @@ -0,0 +1,36 @@ +. + */ +Doctrine::autoload('Doctrine_Connection_Module'); +/** + * Doctrine_Util + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + * @author Konsta Vesterinen + */ +class Doctrine_Util extends Doctrine_Connection_Module +{ + +}