1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.6.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Exceptions; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class DatabaseException |
19
|
|
|
* @package Quantum\Exceptions |
20
|
|
|
*/ |
21
|
|
|
class DatabaseException extends \Exception |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Incorrect config message |
25
|
|
|
*/ |
26
|
|
|
const INCORRECT_CONFIG = 'The structure of config is not correct'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Config file not found message |
30
|
|
|
*/ |
31
|
|
|
const CONFIG_NOT_PROVIDED = 'Configuration does not provided'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* ORM class not defined message |
35
|
|
|
*/ |
36
|
|
|
const ORM_CLASS_NOT_DEFINED = 'Missing ORM definition in config file'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Orm class not found message |
40
|
|
|
*/ |
41
|
|
|
const ORM_CLASS_NOT_FOUND = 'ORM `{%1}` class not found'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Method not supported message |
45
|
|
|
*/ |
46
|
|
|
const NOT_SUPPORTED_METHOD = 'The method `{%1}` is not supported for ORM `{%2}`'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Method not supported message |
50
|
|
|
*/ |
51
|
|
|
const NOT_SUPPORTED_OPERATOR = 'The operator `{%1}` is not supported'; |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return \Quantum\Exceptions\DatabaseException |
56
|
|
|
*/ |
57
|
|
|
public static function missingConfig(): DatabaseException |
58
|
|
|
{ |
59
|
|
|
return new static(self::CONFIG_NOT_PROVIDED, E_ERROR); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return \Quantum\Exceptions\DatabaseException |
64
|
|
|
*/ |
65
|
|
|
public static function incorrectConfig(): DatabaseException |
66
|
|
|
{ |
67
|
|
|
return new static(self::INCORRECT_CONFIG, E_ERROR); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return \Quantum\Exceptions\DatabaseException |
72
|
|
|
*/ |
73
|
|
|
public static function ormClassNotDefined(): DatabaseException |
74
|
|
|
{ |
75
|
|
|
return new static(self::ORM_CLASS_NOT_DEFINED, E_ERROR); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $name |
80
|
|
|
* @return \Quantum\Exceptions\DatabaseException |
81
|
|
|
*/ |
82
|
|
|
public static function ormClassNotFound(string $name): DatabaseException |
83
|
|
|
{ |
84
|
|
|
return new static(_message(self::ORM_CLASS_NOT_FOUND, $name), E_ERROR); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $methodName |
89
|
|
|
* @param string $ormName |
90
|
|
|
* @return \Quantum\Exceptions\DatabaseException |
91
|
|
|
*/ |
92
|
|
|
public static function methodNotSupported(string $methodName, string $ormName): DatabaseException |
93
|
|
|
{ |
94
|
|
|
return new static(_message(self::NOT_SUPPORTED_METHOD, [$methodName, $ormName]), E_WARNING); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $operator |
99
|
|
|
* @return \Quantum\Exceptions\DatabaseException |
100
|
|
|
*/ |
101
|
|
|
public static function operatorNotSupported(string $operator): DatabaseException |
102
|
|
|
{ |
103
|
|
|
return new static(_message(self::NOT_SUPPORTED_OPERATOR, [$operator]), E_WARNING); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|