1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/lib/Doctrine/Db/Event.php

99 lines
2.7 KiB
PHP
Raw Normal View History

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
*
* @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
{
2006-11-08 02:12:05 +03:00
const QUERY = 1;
const EXEC = 2;
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;
2006-11-08 02:12:05 +03:00
protected $invoker;
protected $query;
2006-12-29 17:01:31 +03:00
2006-11-08 02:12:05 +03:00
protected $type;
protected $startedMicrotime;
protected $endedMicrotime;
2007-01-10 23:36:29 +03:00
2006-12-29 17:40:47 +03:00
public function __construct($invoker, $type, $query = null)
{
2006-11-08 02:12:05 +03:00
$this->invoker = $invoker;
$this->type = $type;
$this->query = $query;
}
2006-12-29 17:40:47 +03:00
public function getQuery()
{
2006-11-08 02:12:05 +03:00
return $this->query;
}
2006-12-29 17:40:47 +03:00
public function getType()
{
2006-12-29 17:01:31 +03:00
return $this->type;
2006-11-08 02:12:05 +03:00
}
2006-12-29 17:40:47 +03:00
public function start()
{
2006-11-08 02:12:05 +03:00
$this->startedMicrotime = microtime(true);
}
2006-12-29 17:40:47 +03:00
public function hasEnded()
{
2006-11-08 02:12:05 +03:00
return ($this->endedMicrotime != null);
}
2006-12-29 17:40:47 +03:00
public function end()
{
2006-11-08 02:12:05 +03:00
$this->endedMicrotime = microtime(true);
}
2006-12-29 17:40:47 +03:00
public function getInvoker()
{
2006-11-08 02:12:05 +03:00
return $this->invoker;
}
/**
* 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);
}
}