3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\Common\Annotations;
23 * Description of AnnotationException
26 * @author Benjamin Eberlei <kontakt@beberlei.de>
27 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
28 * @author Jonathan Wage <jonwage@gmail.com>
29 * @author Roman Borschel <roman@code-factory.org>
31 class AnnotationException extends \Exception
34 * Creates a new AnnotationException describing a Syntax error.
36 * @param string $message Exception message
38 * @return AnnotationException
40 public static function syntaxError($message)
42 return new self('[Syntax Error] ' . $message);
46 * Creates a new AnnotationException describing a Semantical error.
48 * @param string $message Exception message
50 * @return AnnotationException
52 public static function semanticalError($message)
54 return new self('[Semantical Error] ' . $message);
58 * Creates a new AnnotationException describing an error which occurred during
59 * the creation of the annotation.
63 * @param string $message
65 * @return AnnotationException
67 public static function creationError($message)
69 return new self('[Creation Error] ' . $message);
73 * Creates a new AnnotationException describing a type error.
77 * @param string $message
79 * @return AnnotationException
81 public static function typeError($message)
83 return new self('[Type Error] ' . $message);
87 * Creates a new AnnotationException describing a constant semantical error.
91 * @param string $identifier
92 * @param string $context
94 * @return AnnotationException
96 public static function semanticalErrorConstants($identifier, $context = null)
98 return self::semanticalError(sprintf(
99 "Couldn't find constant %s%s.",
101 $context ? ', ' . $context : ''
106 * Creates a new AnnotationException describing an type error of an attribute.
110 * @param string $attributeName
111 * @param string $annotationName
112 * @param string $context
113 * @param string $expected
114 * @param mixed $actual
116 * @return AnnotationException
118 public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual)
120 return self::typeError(sprintf(
121 'Attribute "%s" of @%s declared on %s expects %s, but got %s.',
126 is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual)
131 * Creates a new AnnotationException describing an required error of an attribute.
135 * @param string $attributeName
136 * @param string $annotationName
137 * @param string $context
138 * @param string $expected
140 * @return AnnotationException
142 public static function requiredError($attributeName, $annotationName, $context, $expected)
144 return self::typeError(sprintf(
145 'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.',
154 * Creates a new AnnotationException describing a invalid enummerator.
158 * @param string $attributeName
159 * @param string $annotationName
160 * @param string $context
161 * @param array $available
162 * @param mixed $given
164 * @return AnnotationException
166 public static function enumeratorError($attributeName, $annotationName, $context, $available, $given)
168 return new self(sprintf(
169 '[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.',
173 implode(', ', $available),
174 is_object($given) ? get_class($given) : $given
179 * @return AnnotationException
181 public static function optimizerPlusSaveComments()
184 "You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1."
189 * @return AnnotationException
191 public static function optimizerPlusLoadComments()
194 "You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1."