|
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.8.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Quantum\Exceptions; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class ModelException |
|
19
|
|
|
* @package Quantum\Exceptions |
|
20
|
|
|
*/ |
|
21
|
|
|
class ModelException extends \Exception |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Model not found message |
|
26
|
|
|
*/ |
|
27
|
|
|
const MODEL_NOT_FOUND = 'Model `{%1}` not found'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Model not instance of QtModel |
|
31
|
|
|
*/ |
|
32
|
|
|
const NOT_INSTANCE_OF_MODEL = 'Model `{%1}` is not instance of `{%2}`'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Model does not have table property defined |
|
36
|
|
|
*/ |
|
37
|
|
|
const MODEL_WITHOUT_TABLE_DEFINED = 'Model `{%1}` does not have $table property defined'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Undefined model method |
|
41
|
|
|
*/ |
|
42
|
|
|
const UNDEFINED_MODEL_METHOD = 'Model method `{%1}` is not defined'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Inappropriate property message |
|
46
|
|
|
*/ |
|
47
|
|
|
const INAPPROPRIATE_PROPERTY = 'Inappropriate property `{%1}` for fillable object'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Wrong relation message |
|
51
|
|
|
*/ |
|
52
|
|
|
const WRON_RELATION = 'The model `{%1}` does not define relation wtih `{%2}`'; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $name |
|
56
|
|
|
* @return \Quantum\Exceptions\ModelException |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function notFound(string $name): ModelException |
|
59
|
|
|
{ |
|
60
|
|
|
return new static(_message(self::MODEL_NOT_FOUND, $name), E_ERROR); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array $names |
|
65
|
|
|
* @return \Quantum\Exceptions\ModelException |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function notModelInstance(array $names): ModelException |
|
68
|
|
|
{ |
|
69
|
|
|
return new static(_message(self::NOT_INSTANCE_OF_MODEL, $names), E_WARNING); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string|null $name |
|
74
|
|
|
* @return \Quantum\Exceptions\ModelException |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function noTableDefined(?string $name): ModelException |
|
77
|
|
|
{ |
|
78
|
|
|
return new static(_message(self::MODEL_WITHOUT_TABLE_DEFINED, $name), E_WARNING); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param string $name |
|
83
|
|
|
* @return \Quantum\Exceptions\ModelException |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function undefinedMethod(string $name): ModelException |
|
86
|
|
|
{ |
|
87
|
|
|
return new static(_message(self::UNDEFINED_MODEL_METHOD, $name), E_WARNING); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string $name |
|
92
|
|
|
* @return \Quantum\Exceptions\ModelException |
|
93
|
|
|
*/ |
|
94
|
|
|
public static function inappropriateProperty(string $name): ModelException |
|
95
|
|
|
{ |
|
96
|
|
|
return new static(_message(self::INAPPROPRIATE_PROPERTY, $name), E_WARNING); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $name |
|
101
|
|
|
* @return \Quantum\Exceptions\ModelException |
|
102
|
|
|
*/ |
|
103
|
|
|
public static function wrongRelation(string $modelName, string $tableName): ModelException |
|
104
|
|
|
{ |
|
105
|
|
|
return new static(_message(self::WRON_RELATION, [$modelName, $tableName]), E_ERROR); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|