Chris@0: . Chris@0: */ Chris@0: Chris@0: namespace Doctrine\Common\Annotations; Chris@0: Chris@0: /** Chris@0: * Description of AnnotationException Chris@0: * Chris@0: * @since 2.0 Chris@0: * @author Benjamin Eberlei Chris@0: * @author Guilherme Blanco Chris@0: * @author Jonathan Wage Chris@0: * @author Roman Borschel Chris@0: */ Chris@0: class AnnotationException extends \Exception Chris@0: { Chris@0: /** Chris@0: * Creates a new AnnotationException describing a Syntax error. Chris@0: * Chris@0: * @param string $message Exception message Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function syntaxError($message) Chris@0: { Chris@0: return new self('[Syntax Error] ' . $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a new AnnotationException describing a Semantical error. Chris@0: * Chris@0: * @param string $message Exception message Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function semanticalError($message) Chris@0: { Chris@0: return new self('[Semantical Error] ' . $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a new AnnotationException describing an error which occurred during Chris@0: * the creation of the annotation. Chris@0: * Chris@0: * @since 2.2 Chris@0: * Chris@0: * @param string $message Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function creationError($message) Chris@0: { Chris@0: return new self('[Creation Error] ' . $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a new AnnotationException describing a type error. Chris@0: * Chris@0: * @since 1.1 Chris@0: * Chris@0: * @param string $message Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function typeError($message) Chris@0: { Chris@0: return new self('[Type Error] ' . $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a new AnnotationException describing a constant semantical error. Chris@0: * Chris@0: * @since 2.3 Chris@0: * Chris@0: * @param string $identifier Chris@0: * @param string $context Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function semanticalErrorConstants($identifier, $context = null) Chris@0: { Chris@0: return self::semanticalError(sprintf( Chris@0: "Couldn't find constant %s%s.", Chris@0: $identifier, Chris@0: $context ? ', ' . $context : '' Chris@0: )); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a new AnnotationException describing an type error of an attribute. Chris@0: * Chris@0: * @since 2.2 Chris@0: * Chris@0: * @param string $attributeName Chris@0: * @param string $annotationName Chris@0: * @param string $context Chris@0: * @param string $expected Chris@0: * @param mixed $actual Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual) Chris@0: { Chris@0: return self::typeError(sprintf( Chris@0: 'Attribute "%s" of @%s declared on %s expects %s, but got %s.', Chris@0: $attributeName, Chris@0: $annotationName, Chris@0: $context, Chris@0: $expected, Chris@0: is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual) Chris@0: )); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a new AnnotationException describing an required error of an attribute. Chris@0: * Chris@0: * @since 2.2 Chris@0: * Chris@0: * @param string $attributeName Chris@0: * @param string $annotationName Chris@0: * @param string $context Chris@0: * @param string $expected Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function requiredError($attributeName, $annotationName, $context, $expected) Chris@0: { Chris@0: return self::typeError(sprintf( Chris@0: 'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.', Chris@0: $attributeName, Chris@0: $annotationName, Chris@0: $context, Chris@0: $expected Chris@0: )); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a new AnnotationException describing a invalid enummerator. Chris@0: * Chris@0: * @since 2.4 Chris@0: * Chris@0: * @param string $attributeName Chris@0: * @param string $annotationName Chris@0: * @param string $context Chris@0: * @param array $available Chris@0: * @param mixed $given Chris@0: * Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function enumeratorError($attributeName, $annotationName, $context, $available, $given) Chris@0: { Chris@0: return new self(sprintf( Chris@0: '[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.', Chris@0: $attributeName, Chris@0: $annotationName, Chris@0: $context, Chris@0: implode(', ', $available), Chris@0: is_object($given) ? get_class($given) : $given Chris@0: )); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function optimizerPlusSaveComments() Chris@0: { Chris@0: return new self( Chris@0: "You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1." Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return AnnotationException Chris@0: */ Chris@0: public static function optimizerPlusLoadComments() Chris@0: { Chris@0: return new self( Chris@0: "You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1." Chris@0: ); Chris@0: } Chris@0: }