|
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.9.9 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Quantum\Model\Exceptions; |
|
16
|
|
|
|
|
17
|
|
|
use Quantum\Model\Enums\ExceptionMessages; |
|
18
|
|
|
use Quantum\App\Exceptions\BaseException; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class ModelException |
|
22
|
|
|
* @package Quantum\Model |
|
23
|
|
|
*/ |
|
24
|
|
|
class ModelException extends BaseException |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $name |
|
29
|
|
|
* @return ModelException |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function inappropriateProperty(string $name): ModelException |
|
32
|
|
|
{ |
|
33
|
|
|
return new static( |
|
34
|
|
|
_message(ExceptionMessages::INAPPROPRIATE_MODEL_PROPERTY, $name), |
|
35
|
|
|
E_WARNING |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $modelName |
|
41
|
|
|
* @param string $tableName |
|
42
|
|
|
* @return ModelException |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function wrongRelation(string $modelName, string $tableName): ModelException |
|
45
|
|
|
{ |
|
46
|
|
|
return new static( |
|
47
|
|
|
_message(ExceptionMessages::WRONG_RELATION, [$modelName, $tableName]), |
|
48
|
|
|
E_ERROR |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $modelName |
|
54
|
|
|
* @param string $relatedModelName |
|
55
|
|
|
* @return ModelException |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function relationTypeMissing(string $modelName, string $relatedModelName): ModelException |
|
58
|
|
|
{ |
|
59
|
|
|
return new static( |
|
60
|
|
|
_message(ExceptionMessages::RELATION_TYPE_MISSING, [$modelName, $relatedModelName]), |
|
61
|
|
|
E_ERROR |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $modelName |
|
67
|
|
|
* @param string $relatedModelName |
|
68
|
|
|
* @return ModelException |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function missingRelationKeys(string $modelName, string $relatedModelName): ModelException |
|
71
|
|
|
{ |
|
72
|
|
|
return new static( |
|
73
|
|
|
_message(ExceptionMessages::MISSING_RELATION_KEYS, [$modelName, $relatedModelName]), |
|
74
|
|
|
E_ERROR |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $modelName |
|
80
|
|
|
* @param string $foreignKey |
|
81
|
|
|
* @return ModelException |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function missingForeignKeyValue(string $modelName, string $foreignKey): ModelException |
|
84
|
|
|
{ |
|
85
|
|
|
return new static( |
|
86
|
|
|
_message(ExceptionMessages::MISSING_FOREIGN_KEY, [$foreignKey, $modelName]), |
|
87
|
|
|
E_ERROR |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param string $relationType |
|
93
|
|
|
* @return ModelException |
|
94
|
|
|
*/ |
|
95
|
|
|
public static function unsupportedRelationType(string $relationType): ModelException |
|
96
|
|
|
{ |
|
97
|
|
|
return new static( |
|
98
|
|
|
_message(ExceptionMessages::UNSUPPORTED_RELATION, [$relationType]), |
|
99
|
|
|
E_ERROR |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
} |