菜谱项目

AnnotationException.php 5.7KB

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