1 |
<?php
|
2 |
/*
|
3 |
* $Id: Exception.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $
|
4 |
*
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16 |
*
|
17 |
* This software consists of voluntary contributions made by many individuals
|
18 |
* and is licensed under the LGPL. For more information, see
|
19 |
* <http://www.phpdoctrine.com>.
|
20 |
*/
|
21 |
|
22 |
/**
|
23 |
* Doctrine_Exception
|
24 |
*
|
25 |
* @package Doctrine
|
26 |
* @subpackage Exception
|
27 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
28 |
* @link www.phpdoctrine.com
|
29 |
* @since 1.0
|
30 |
* @version $Revision: 2963 $
|
31 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
32 |
*/
|
33 |
class Doctrine_Exception extends Exception
|
34 |
{
|
35 |
/**
|
36 |
* @var array $_errorMessages an array of error messages
|
37 |
*/
|
38 |
protected static $_errorMessages = array(
|
39 |
Doctrine::ERR => 'unknown error',
|
40 |
Doctrine::ERR_ALREADY_EXISTS => 'already exists',
|
41 |
Doctrine::ERR_CANNOT_CREATE => 'can not create',
|
42 |
Doctrine::ERR_CANNOT_ALTER => 'can not alter',
|
43 |
Doctrine::ERR_CANNOT_REPLACE => 'can not replace',
|
44 |
Doctrine::ERR_CANNOT_DELETE => 'can not delete',
|
45 |
Doctrine::ERR_CANNOT_DROP => 'can not drop',
|
46 |
Doctrine::ERR_CONSTRAINT => 'constraint violation',
|
47 |
Doctrine::ERR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
|
48 |
Doctrine::ERR_DIVZERO => 'division by zero',
|
49 |
Doctrine::ERR_INVALID => 'invalid',
|
50 |
Doctrine::ERR_INVALID_DATE => 'invalid date or time',
|
51 |
Doctrine::ERR_INVALID_NUMBER => 'invalid number',
|
52 |
Doctrine::ERR_MISMATCH => 'mismatch',
|
53 |
Doctrine::ERR_NODBSELECTED => 'no database selected',
|
54 |
Doctrine::ERR_NOSUCHFIELD => 'no such field',
|
55 |
Doctrine::ERR_NOSUCHTABLE => 'no such table',
|
56 |
Doctrine::ERR_NOT_CAPABLE => 'Doctrine backend not capable',
|
57 |
Doctrine::ERR_NOT_FOUND => 'not found',
|
58 |
Doctrine::ERR_NOT_LOCKED => 'not locked',
|
59 |
Doctrine::ERR_SYNTAX => 'syntax error',
|
60 |
Doctrine::ERR_UNSUPPORTED => 'not supported',
|
61 |
Doctrine::ERR_VALUE_COUNT_ON_ROW => 'value count on row',
|
62 |
Doctrine::ERR_INVALID_DSN => 'invalid DSN',
|
63 |
Doctrine::ERR_CONNECT_FAILED => 'connect failed',
|
64 |
Doctrine::ERR_NEED_MORE_DATA => 'insufficient data supplied',
|
65 |
Doctrine::ERR_EXTENSION_NOT_FOUND=> 'extension not found',
|
66 |
Doctrine::ERR_NOSUCHDB => 'no such database',
|
67 |
Doctrine::ERR_ACCESS_VIOLATION => 'insufficient permissions',
|
68 |
Doctrine::ERR_LOADMODULE => 'error while including on demand module',
|
69 |
Doctrine::ERR_TRUNCATED => 'truncated',
|
70 |
Doctrine::ERR_DEADLOCK => 'deadlock detected',
|
71 |
);
|
72 |
|
73 |
/**
|
74 |
* Return a textual error message for a Doctrine error code
|
75 |
*
|
76 |
* @param int|array integer error code,
|
77 |
* null to get the current error code-message map,
|
78 |
* or an array with a new error code-message map
|
79 |
*
|
80 |
* @return string error message
|
81 |
*/
|
82 |
public function errorMessage($value = null)
|
83 |
{
|
84 |
if (is_null($value)) {
|
85 |
return self::$_errorMessages;
|
86 |
}
|
87 |
|
88 |
return isset(self::$_errorMessages[$value]) ?
|
89 |
self::$_errorMessages[$value] : self::$_errorMessages[Doctrine::ERR];
|
90 |
}
|
91 |
|
92 |
}
|