|
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.6 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Quantum\Model\Exceptions; |
|
16
|
|
|
|
|
17
|
|
|
use Quantum\Exceptions\BaseException; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class ModelException |
|
21
|
|
|
* @package Quantum\Model |
|
22
|
|
|
*/ |
|
23
|
|
|
class ModelException extends BaseException |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $name |
|
27
|
|
|
* @return ModelException |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function notFound(string $name): ModelException |
|
30
|
|
|
{ |
|
31
|
|
|
return new static(t('exception.model_not_found', $name), E_ERROR); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param array $names |
|
36
|
|
|
* @return ModelException |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function notModelInstance(array $names): ModelException |
|
39
|
|
|
{ |
|
40
|
|
|
return new static(t('exception.not_instance_of_model', $names), E_WARNING); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string|null $name |
|
45
|
|
|
* @return ModelException |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function noTableDefined(?string $name): ModelException |
|
48
|
|
|
{ |
|
49
|
|
|
return new static(t('exception.model_without_table_defined', $name), E_WARNING); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $name |
|
54
|
|
|
* @return ModelException |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function undefinedMethod(string $name): ModelException |
|
57
|
|
|
{ |
|
58
|
|
|
return new static(t('exception.undefined_model_method', $name), E_WARNING); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $name |
|
63
|
|
|
* @return ModelException |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function inappropriateProperty(string $name): ModelException |
|
66
|
|
|
{ |
|
67
|
|
|
return new static(t('exception.inappropriate_property', $name), E_WARNING); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $modelName |
|
72
|
|
|
* @param string $tableName |
|
73
|
|
|
* @return ModelException |
|
74
|
|
|
*/ |
|
75
|
|
|
public static function wrongRelation(string $modelName, string $tableName): ModelException |
|
76
|
|
|
{ |
|
77
|
|
|
return new static(t('exception.wrong_relation', [$modelName, $tableName]), E_ERROR); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|