Packages

  • dibi
    • drivers
    • nette
    • reflection
  • None
  • PHP

Classes

  • dibi
  • DibiConnection
  • DibiDataSource
  • DibiDateTime
  • DibiEvent
  • DibiFileLogger
  • DibiFirePhpLogger
  • DibiFluent
  • DibiObject
  • DibiResult
  • DibiResultIterator
  • DibiRow
  • DibiTranslator

Interfaces

  • IDataSource
  • IDibiDriver
  • IDibiReflector
  • IDibiResultDriver

Exceptions

  • DibiDriverException
  • DibiException
  • DibiNotImplementedException
  • DibiNotSupportedException
  • DibiPcreException
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the "dibi" - smart database abstraction layer.
  5:  *
  6:  * Copyright (c) 2005 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: 
 13: 
 14: /**
 15:  * Profiler & logger event.
 16:  *
 17:  * @author     David Grudl
 18:  * @package    dibi
 19:  */
 20: class DibiEvent
 21: {
 22:     /** event type */
 23:     const CONNECT = 1,
 24:         SELECT = 4,
 25:         INSERT = 8,
 26:         DELETE = 16,
 27:         UPDATE = 32,
 28:         QUERY = 60, // SELECT | INSERT | DELETE | UPDATE
 29:         BEGIN = 64,
 30:         COMMIT = 128,
 31:         ROLLBACK = 256,
 32:         TRANSACTION = 448, // BEGIN | COMMIT | ROLLBACK
 33:         ALL = 1023;
 34: 
 35:     /** @var DibiConnection */
 36:     public $connection;
 37: 
 38:     /** @var int */
 39:     public $type;
 40: 
 41:     /** @var string */
 42:     public $sql;
 43: 
 44:     /** @var DibiResult|DibiDriverException|NULL */
 45:     public $result;
 46: 
 47:     /** @var float */
 48:     public $time;
 49: 
 50:     /** @var int */
 51:     public $count;
 52: 
 53:     /** @var array */
 54:     public $source;
 55: 
 56: 
 57: 
 58:     public function __construct(DibiConnection $connection, $type, $sql = NULL)
 59:     {
 60:         $this->connection = $connection;
 61:         $this->type = $type;
 62:         $this->sql = trim($sql);
 63:         $this->time = -microtime(TRUE);
 64: 
 65:         if ($type === self::QUERY && preg_match('#(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
 66:             static $types = array(
 67:                 'SELECT' => self::SELECT, 'UPDATE' => self::UPDATE,
 68:                 'INSERT' => self::INSERT, 'DELETE' => self::DELETE,
 69:             );
 70:             $this->type = $types[strtoupper($matches[1])];
 71:         }
 72: 
 73:         $rc = new ReflectionClass('dibi');
 74:         $dibiDir = dirname($rc->getFileName()) . DIRECTORY_SEPARATOR;
 75:         foreach (debug_backtrace(FALSE) as $row) {
 76:             if (isset($row['file']) && is_file($row['file']) && strpos($row['file'], $dibiDir) !== 0) {
 77:                 $this->source = array($row['file'], (int) $row['line']);
 78:                 break;
 79:             }
 80:         }
 81: 
 82:         dibi::$elapsedTime = FALSE;
 83:     }
 84: 
 85: 
 86: 
 87:     public function done($result = NULL)
 88:     {
 89:         $this->result = $result;
 90:         try {
 91:             $this->count = $result instanceof DibiResult ? count($result) : NULL;
 92:         } catch (DibiException $e) {
 93:             $this->count = NULL;
 94:         }
 95: 
 96:         $this->time += microtime(TRUE);
 97:         dibi::$elapsedTime = $this->time;
 98:         dibi::$totalTime += $this->time;
 99:         return $this;
100:     }
101: 
102: }
103: 
dibi API documentation API documentation generated by ApiGen 2.3.0