1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Annotations; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Description of AnnotationException |
7
|
|
|
* |
8
|
|
|
* @since 2.0 |
9
|
|
|
* @author Benjamin Eberlei <[email protected]> |
10
|
|
|
* @author Guilherme Blanco <[email protected]> |
11
|
|
|
* @author Jonathan Wage <[email protected]> |
12
|
|
|
* @author Roman Borschel <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class AnnotationException extends \Exception |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Creates a new AnnotationException describing a Syntax error. |
18
|
|
|
* |
19
|
|
|
* @param string $message Exception message |
20
|
|
|
* |
21
|
|
|
* @return AnnotationException |
22
|
|
|
*/ |
23
|
11 |
|
public static function syntaxError($message) |
24
|
|
|
{ |
25
|
11 |
|
return new self('[Syntax Error] ' . $message); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Creates a new AnnotationException describing a Semantical error. |
30
|
|
|
* |
31
|
|
|
* @param string $message Exception message |
32
|
|
|
* |
33
|
|
|
* @return AnnotationException |
34
|
|
|
*/ |
35
|
10 |
|
public static function semanticalError($message) |
36
|
|
|
{ |
37
|
10 |
|
return new self('[Semantical Error] ' . $message); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Creates a new AnnotationException describing an error which occurred during |
42
|
|
|
* the creation of the annotation. |
43
|
|
|
* |
44
|
|
|
* @since 2.2 |
45
|
|
|
* |
46
|
|
|
* @param string $message |
47
|
|
|
* |
48
|
|
|
* @return AnnotationException |
49
|
|
|
*/ |
50
|
3 |
|
public static function creationError($message) |
51
|
|
|
{ |
52
|
3 |
|
return new self('[Creation Error] ' . $message); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Creates a new AnnotationException describing a type error. |
57
|
|
|
* |
58
|
|
|
* @since 1.1 |
59
|
|
|
* |
60
|
|
|
* @param string $message |
61
|
|
|
* |
62
|
|
|
* @return AnnotationException |
63
|
|
|
*/ |
64
|
110 |
|
public static function typeError($message) |
65
|
|
|
{ |
66
|
110 |
|
return new self('[Type Error] ' . $message); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Creates a new AnnotationException describing a constant semantical error. |
71
|
|
|
* |
72
|
|
|
* @since 2.3 |
73
|
|
|
* |
74
|
|
|
* @param string $identifier |
75
|
|
|
* @param string $context |
76
|
|
|
* |
77
|
|
|
* @return AnnotationException |
78
|
|
|
*/ |
79
|
1 |
|
public static function semanticalErrorConstants($identifier, $context = null) |
80
|
|
|
{ |
81
|
1 |
|
return self::semanticalError(sprintf( |
82
|
1 |
|
"Couldn't find constant %s%s.", |
83
|
1 |
|
$identifier, |
84
|
1 |
|
$context ? ', ' . $context : '' |
85
|
|
|
)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Creates a new AnnotationException describing an type error of an attribute. |
90
|
|
|
* |
91
|
|
|
* @since 2.2 |
92
|
|
|
* |
93
|
|
|
* @param string $attributeName |
94
|
|
|
* @param string $annotationName |
95
|
|
|
* @param string $context |
96
|
|
|
* @param string $expected |
97
|
|
|
* |
98
|
|
|
* @return AnnotationException |
99
|
|
|
*/ |
100
|
108 |
|
public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual) |
101
|
|
|
{ |
102
|
108 |
|
return self::typeError(sprintf( |
103
|
108 |
|
'Attribute "%s" of @%s declared on %s expects %s, but got %s.', |
104
|
108 |
|
$attributeName, |
105
|
108 |
|
$annotationName, |
106
|
108 |
|
$context, |
107
|
108 |
|
$expected, |
108
|
108 |
|
is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual) |
109
|
|
|
)); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Creates a new AnnotationException describing an required error of an attribute. |
114
|
|
|
* |
115
|
|
|
* @since 2.2 |
116
|
|
|
* |
117
|
|
|
* @param string $attributeName |
118
|
|
|
* @param string $annotationName |
119
|
|
|
* @param string $context |
120
|
|
|
* @param string $expected |
121
|
|
|
* |
122
|
|
|
* @return AnnotationException |
123
|
|
|
*/ |
124
|
2 |
|
public static function requiredError($attributeName, $annotationName, $context, $expected) |
125
|
|
|
{ |
126
|
2 |
|
return self::typeError(sprintf( |
127
|
2 |
|
'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.', |
128
|
2 |
|
$attributeName, |
129
|
2 |
|
$annotationName, |
130
|
2 |
|
$context, |
131
|
2 |
|
$expected |
132
|
|
|
)); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Creates a new AnnotationException describing a invalid enummerator. |
137
|
|
|
* |
138
|
|
|
* @since 2.4 |
139
|
|
|
* |
140
|
|
|
* @param string $attributeName |
141
|
|
|
* @param string $annotationName |
142
|
|
|
* @param string $context |
143
|
|
|
* @param string $expected |
144
|
|
|
* @param mixed $given |
145
|
|
|
* |
146
|
|
|
* @return AnnotationException |
147
|
|
|
*/ |
148
|
3 |
|
public static function enumeratorError($attributeName, $annotationName, $context, $expected, $given) |
149
|
|
|
{ |
150
|
3 |
|
return new self(sprintf( |
151
|
3 |
|
'[Enum Error] Attribute "%s" of @%s declared on %s accept only %s, but got %s.', |
152
|
3 |
|
$attributeName, |
153
|
3 |
|
$annotationName, |
154
|
3 |
|
$context, |
155
|
3 |
|
$expected, |
156
|
3 |
|
is_object($given) ? get_class($given) : $given |
157
|
|
|
)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return AnnotationException |
162
|
|
|
*/ |
163
|
|
|
public static function optimizerPlusSaveComments() |
164
|
|
|
{ |
165
|
|
|
return new self( |
166
|
|
|
"You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1." |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return AnnotationException |
172
|
|
|
*/ |
173
|
|
|
public static function optimizerPlusLoadComments() |
174
|
|
|
{ |
175
|
|
|
return new self( |
176
|
|
|
"You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1." |
177
|
|
|
); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|