Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@0
|
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Chris@0
|
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Chris@0
|
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Chris@0
|
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
Chris@0
|
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
Chris@0
|
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
Chris@0
|
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
Chris@0
|
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
Chris@0
|
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
Chris@0
|
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
Chris@0
|
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Chris@0
|
14 *
|
Chris@0
|
15 * This software consists of voluntary contributions made by many individuals
|
Chris@0
|
16 * and is licensed under the MIT license. For more information, see
|
Chris@0
|
17 * <http://www.doctrine-project.org>.
|
Chris@0
|
18 */
|
Chris@0
|
19
|
Chris@0
|
20 namespace Doctrine\Common\Annotations;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Description of AnnotationException
|
Chris@0
|
24 *
|
Chris@0
|
25 * @since 2.0
|
Chris@0
|
26 * @author Benjamin Eberlei <kontakt@beberlei.de>
|
Chris@0
|
27 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
Chris@0
|
28 * @author Jonathan Wage <jonwage@gmail.com>
|
Chris@0
|
29 * @author Roman Borschel <roman@code-factory.org>
|
Chris@0
|
30 */
|
Chris@0
|
31 class AnnotationException extends \Exception
|
Chris@0
|
32 {
|
Chris@0
|
33 /**
|
Chris@0
|
34 * Creates a new AnnotationException describing a Syntax error.
|
Chris@0
|
35 *
|
Chris@0
|
36 * @param string $message Exception message
|
Chris@0
|
37 *
|
Chris@0
|
38 * @return AnnotationException
|
Chris@0
|
39 */
|
Chris@0
|
40 public static function syntaxError($message)
|
Chris@0
|
41 {
|
Chris@0
|
42 return new self('[Syntax Error] ' . $message);
|
Chris@0
|
43 }
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Creates a new AnnotationException describing a Semantical error.
|
Chris@0
|
47 *
|
Chris@0
|
48 * @param string $message Exception message
|
Chris@0
|
49 *
|
Chris@0
|
50 * @return AnnotationException
|
Chris@0
|
51 */
|
Chris@0
|
52 public static function semanticalError($message)
|
Chris@0
|
53 {
|
Chris@0
|
54 return new self('[Semantical Error] ' . $message);
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * Creates a new AnnotationException describing an error which occurred during
|
Chris@0
|
59 * the creation of the annotation.
|
Chris@0
|
60 *
|
Chris@0
|
61 * @since 2.2
|
Chris@0
|
62 *
|
Chris@0
|
63 * @param string $message
|
Chris@0
|
64 *
|
Chris@0
|
65 * @return AnnotationException
|
Chris@0
|
66 */
|
Chris@0
|
67 public static function creationError($message)
|
Chris@0
|
68 {
|
Chris@0
|
69 return new self('[Creation Error] ' . $message);
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 /**
|
Chris@0
|
73 * Creates a new AnnotationException describing a type error.
|
Chris@0
|
74 *
|
Chris@0
|
75 * @since 1.1
|
Chris@0
|
76 *
|
Chris@0
|
77 * @param string $message
|
Chris@0
|
78 *
|
Chris@0
|
79 * @return AnnotationException
|
Chris@0
|
80 */
|
Chris@0
|
81 public static function typeError($message)
|
Chris@0
|
82 {
|
Chris@0
|
83 return new self('[Type Error] ' . $message);
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 /**
|
Chris@0
|
87 * Creates a new AnnotationException describing a constant semantical error.
|
Chris@0
|
88 *
|
Chris@0
|
89 * @since 2.3
|
Chris@0
|
90 *
|
Chris@0
|
91 * @param string $identifier
|
Chris@0
|
92 * @param string $context
|
Chris@0
|
93 *
|
Chris@0
|
94 * @return AnnotationException
|
Chris@0
|
95 */
|
Chris@0
|
96 public static function semanticalErrorConstants($identifier, $context = null)
|
Chris@0
|
97 {
|
Chris@0
|
98 return self::semanticalError(sprintf(
|
Chris@0
|
99 "Couldn't find constant %s%s.",
|
Chris@0
|
100 $identifier,
|
Chris@0
|
101 $context ? ', ' . $context : ''
|
Chris@0
|
102 ));
|
Chris@0
|
103 }
|
Chris@0
|
104
|
Chris@0
|
105 /**
|
Chris@0
|
106 * Creates a new AnnotationException describing an type error of an attribute.
|
Chris@0
|
107 *
|
Chris@0
|
108 * @since 2.2
|
Chris@0
|
109 *
|
Chris@0
|
110 * @param string $attributeName
|
Chris@0
|
111 * @param string $annotationName
|
Chris@0
|
112 * @param string $context
|
Chris@0
|
113 * @param string $expected
|
Chris@0
|
114 * @param mixed $actual
|
Chris@0
|
115 *
|
Chris@0
|
116 * @return AnnotationException
|
Chris@0
|
117 */
|
Chris@0
|
118 public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual)
|
Chris@0
|
119 {
|
Chris@0
|
120 return self::typeError(sprintf(
|
Chris@0
|
121 'Attribute "%s" of @%s declared on %s expects %s, but got %s.',
|
Chris@0
|
122 $attributeName,
|
Chris@0
|
123 $annotationName,
|
Chris@0
|
124 $context,
|
Chris@0
|
125 $expected,
|
Chris@0
|
126 is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual)
|
Chris@0
|
127 ));
|
Chris@0
|
128 }
|
Chris@0
|
129
|
Chris@0
|
130 /**
|
Chris@0
|
131 * Creates a new AnnotationException describing an required error of an attribute.
|
Chris@0
|
132 *
|
Chris@0
|
133 * @since 2.2
|
Chris@0
|
134 *
|
Chris@0
|
135 * @param string $attributeName
|
Chris@0
|
136 * @param string $annotationName
|
Chris@0
|
137 * @param string $context
|
Chris@0
|
138 * @param string $expected
|
Chris@0
|
139 *
|
Chris@0
|
140 * @return AnnotationException
|
Chris@0
|
141 */
|
Chris@0
|
142 public static function requiredError($attributeName, $annotationName, $context, $expected)
|
Chris@0
|
143 {
|
Chris@0
|
144 return self::typeError(sprintf(
|
Chris@0
|
145 'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.',
|
Chris@0
|
146 $attributeName,
|
Chris@0
|
147 $annotationName,
|
Chris@0
|
148 $context,
|
Chris@0
|
149 $expected
|
Chris@0
|
150 ));
|
Chris@0
|
151 }
|
Chris@0
|
152
|
Chris@0
|
153 /**
|
Chris@0
|
154 * Creates a new AnnotationException describing a invalid enummerator.
|
Chris@0
|
155 *
|
Chris@0
|
156 * @since 2.4
|
Chris@0
|
157 *
|
Chris@0
|
158 * @param string $attributeName
|
Chris@0
|
159 * @param string $annotationName
|
Chris@0
|
160 * @param string $context
|
Chris@0
|
161 * @param array $available
|
Chris@0
|
162 * @param mixed $given
|
Chris@0
|
163 *
|
Chris@0
|
164 * @return AnnotationException
|
Chris@0
|
165 */
|
Chris@0
|
166 public static function enumeratorError($attributeName, $annotationName, $context, $available, $given)
|
Chris@0
|
167 {
|
Chris@0
|
168 return new self(sprintf(
|
Chris@0
|
169 '[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.',
|
Chris@0
|
170 $attributeName,
|
Chris@0
|
171 $annotationName,
|
Chris@0
|
172 $context,
|
Chris@0
|
173 implode(', ', $available),
|
Chris@0
|
174 is_object($given) ? get_class($given) : $given
|
Chris@0
|
175 ));
|
Chris@0
|
176 }
|
Chris@0
|
177
|
Chris@0
|
178 /**
|
Chris@0
|
179 * @return AnnotationException
|
Chris@0
|
180 */
|
Chris@0
|
181 public static function optimizerPlusSaveComments()
|
Chris@0
|
182 {
|
Chris@0
|
183 return new self(
|
Chris@0
|
184 "You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1."
|
Chris@0
|
185 );
|
Chris@0
|
186 }
|
Chris@0
|
187
|
Chris@0
|
188 /**
|
Chris@0
|
189 * @return AnnotationException
|
Chris@0
|
190 */
|
Chris@0
|
191 public static function optimizerPlusLoadComments()
|
Chris@0
|
192 {
|
Chris@0
|
193 return new self(
|
Chris@0
|
194 "You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1."
|
Chris@0
|
195 );
|
Chris@0
|
196 }
|
Chris@0
|
197 }
|