2006-11-08 02:12:05 +03:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.com>.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Doctrine_Db_Event
|
|
|
|
*
|
2006-11-24 01:54:10 +03:00
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
|
* @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$
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
class Doctrine_Db_Event
|
|
|
|
{
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* EVENT CODE CONSTANTS
|
|
|
|
*/
|
2006-11-08 02:12:05 +03:00
|
|
|
const QUERY = 1;
|
|
|
|
const EXEC = 2;
|
2006-11-24 01:54:10 +03:00
|
|
|
const EXECUTE = 3;
|
|
|
|
const PREPARE = 4;
|
|
|
|
const BEGIN = 5;
|
|
|
|
const COMMIT = 6;
|
|
|
|
const ROLLBACK = 7;
|
2007-01-16 22:16:04 +03:00
|
|
|
const CONNECT = 8;
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* @var Doctrine_Db $invoker the handler which invoked this event
|
|
|
|
*/
|
2006-11-08 02:12:05 +03:00
|
|
|
protected $invoker;
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* @var string $query the sql query associated with this event (if any)
|
|
|
|
*/
|
2006-11-08 02:12:05 +03:00
|
|
|
protected $query;
|
2007-01-27 15:40:51 +03:00
|
|
|
/**
|
|
|
|
* @var string $params the parameters associated with the query (if any)
|
|
|
|
*/
|
|
|
|
protected $params;
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2006-11-08 02:12:05 +03:00
|
|
|
protected $startedMicrotime;
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* @var integer $endedMicrotime the time point in which this event was ended
|
|
|
|
*/
|
2006-11-08 02:12:05 +03:00
|
|
|
protected $endedMicrotime;
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2007-01-27 15:40:51 +03:00
|
|
|
public function __construct($invoker, $code, $query = null, $params = array())
|
2006-12-29 17:40:47 +03:00
|
|
|
{
|
2006-11-08 02:12:05 +03:00
|
|
|
$this->invoker = $invoker;
|
2007-01-19 21:26:51 +03:00
|
|
|
$this->code = $code;
|
2007-01-27 15:40:51 +03:00
|
|
|
$this->query = $query;
|
|
|
|
$this->params = $params;
|
2006-11-08 02:12:05 +03:00
|
|
|
}
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* getQuery
|
|
|
|
*
|
|
|
|
* @return string returns the query associated with this event (if any)
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public function getQuery()
|
|
|
|
{
|
2006-11-08 02:12:05 +03:00
|
|
|
return $this->query;
|
|
|
|
}
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* getName
|
|
|
|
* returns the name of this event
|
|
|
|
*
|
|
|
|
* @return string the name of this event
|
|
|
|
*/
|
|
|
|
public function getName()
|
2006-12-29 17:40:47 +03:00
|
|
|
{
|
2007-01-19 21:26:51 +03:00
|
|
|
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';
|
|
|
|
}
|
2006-11-08 02:12:05 +03:00
|
|
|
}
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public function start()
|
|
|
|
{
|
2006-11-08 02:12:05 +03:00
|
|
|
$this->startedMicrotime = microtime(true);
|
|
|
|
}
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* hasEnded
|
|
|
|
* whether or not this event has ended
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public function hasEnded()
|
|
|
|
{
|
2006-11-08 02:12:05 +03:00
|
|
|
return ($this->endedMicrotime != null);
|
|
|
|
}
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* end
|
|
|
|
* ends the internal timer of this event
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public function end()
|
|
|
|
{
|
2006-11-08 02:12:05 +03:00
|
|
|
$this->endedMicrotime = microtime(true);
|
|
|
|
}
|
2007-01-19 21:26:51 +03:00
|
|
|
/**
|
|
|
|
* getInvoker
|
|
|
|
* returns the handler that invoked this event
|
|
|
|
*
|
|
|
|
* @return Doctrine_Db the handler that invoked this event
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public function getInvoker()
|
|
|
|
{
|
2006-11-08 02:12:05 +03:00
|
|
|
return $this->invoker;
|
|
|
|
}
|
2007-01-27 15:40:51 +03:00
|
|
|
/**
|
|
|
|
* getParams
|
|
|
|
* returns the parameters of the query
|
|
|
|
*
|
|
|
|
* @return array parameters of the query
|
|
|
|
*/
|
|
|
|
public function getParams()
|
|
|
|
{
|
|
|
|
return $this->params;
|
|
|
|
}
|
2006-11-08 02:12:05 +03:00
|
|
|
/**
|
2006-11-24 01:54:10 +03:00
|
|
|
* Get the elapsed time (in microseconds) that the event ran. If the event has
|
2006-11-08 02:12:05 +03:00
|
|
|
* not yet ended, return false.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public function getElapsedSecs()
|
|
|
|
{
|
2006-12-29 17:01:31 +03:00
|
|
|
if (is_null($this->endedMicrotime)) {
|
2006-11-08 02:12:05 +03:00
|
|
|
return false;
|
2006-12-29 17:01:31 +03:00
|
|
|
}
|
2006-11-08 02:12:05 +03:00
|
|
|
return ($this->endedMicrotime - $this->startedMicrotime);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|