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:  * dibi common exception.
 16:  *
 17:  * @author     David Grudl
 18:  * @package    dibi
 19:  */
 20: class DibiException extends Exception
 21: {
 22:     /** @var string */
 23:     private $sql;
 24: 
 25: 
 26:     /**
 27:      * Construct a dibi exception.
 28:      * @param  string  Message describing the exception
 29:      * @param  int     Some code
 30:      * @param  string SQL command
 31:      */
 32:     public function __construct($message = NULL, $code = 0, $sql = NULL)
 33:     {
 34:         parent::__construct($message, (int) $code);
 35:         $this->sql = $sql;
 36:     }
 37: 
 38: 
 39: 
 40:     /**
 41:      * @return string  The SQL passed to the constructor
 42:      */
 43:     final public function getSql()
 44:     {
 45:         return $this->sql;
 46:     }
 47: 
 48: 
 49: 
 50:     /**
 51:      * @return string  string represenation of exception with SQL command
 52:      */
 53:     public function __toString()
 54:     {
 55:         return parent::__toString() . ($this->sql ? "\nSQL: " . $this->sql : '');
 56:     }
 57: 
 58: }
 59: 
 60: 
 61: 
 62: 
 63: /**
 64:  * database server exception.
 65:  *
 66:  * @author     David Grudl
 67:  * @package    dibi
 68:  */
 69: class DibiDriverException extends DibiException
 70: {
 71: 
 72:     /********************* error catching ****************d*g**/
 73: 
 74: 
 75: 
 76:     /** @var string */
 77:     private static $errorMsg;
 78: 
 79: 
 80: 
 81:     /**
 82:      * Starts catching potential errors/warnings.
 83:      * @return void
 84:      */
 85:     public static function tryError()
 86:     {
 87:         set_error_handler(array(__CLASS__, '_errorHandler'), E_ALL);
 88:         self::$errorMsg = NULL;
 89:     }
 90: 
 91: 
 92: 
 93:     /**
 94:      * Returns catched error/warning message.
 95:      * @param  string  catched message
 96:      * @return bool
 97:      */
 98:     public static function catchError(& $message)
 99:     {
100:         restore_error_handler();
101:         $message = self::$errorMsg;
102:         self::$errorMsg = NULL;
103:         return $message !== NULL;
104:     }
105: 
106: 
107: 
108:     /**
109:      * Internal error handler. Do not call directly.
110:      * @internal
111:      */
112:     public static function _errorHandler($code, $message)
113:     {
114:         restore_error_handler();
115: 
116:         if (ini_get('html_errors')) {
117:             $message = strip_tags($message);
118:             $message = html_entity_decode($message);
119:         }
120: 
121:         self::$errorMsg = $message;
122:     }
123: 
124: }
125: 
126: 
127: 
128: 
129: /**
130:  * PCRE exception.
131:  *
132:  * @author     David Grudl
133:  * @package    dibi
134:  */
135: class DibiPcreException extends Exception {
136: 
137:     public function __construct($message = '%msg.')
138:     {
139:         static $messages = array(
140:             PREG_INTERNAL_ERROR => 'Internal error',
141:             PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted',
142:             PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted',
143:             PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data',
144:             5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
145:         );
146:         $code = preg_last_error();
147:         parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code);
148:     }
149: }
150: 
151: 
152: 
153: /**
154:  * @package    dibi
155:  */
156: class DibiNotImplementedException extends DibiException
157: {}
158: 
159: 
160: 
161: /**
162:  * @package    dibi
163:  */
164: class DibiNotSupportedException extends DibiException
165: {}
166: 
dibi API documentation API documentation generated by ApiGen 2.3.0