Annotation.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Doctrine\Common\Annotations;
  3. use BadMethodCallException;
  4. use function sprintf;
  5. /**
  6. * Annotations class.
  7. */
  8. class Annotation
  9. {
  10. /**
  11. * Value property. Common among all derived classes.
  12. *
  13. * @var mixed
  14. */
  15. public $value;
  16. /**
  17. * @param array<string, mixed> $data Key-value for properties to be defined in this class.
  18. */
  19. final public function __construct(array $data)
  20. {
  21. foreach ($data as $key => $value) {
  22. $this->$key = $value;
  23. }
  24. }
  25. /**
  26. * Error handler for unknown property accessor in Annotation class.
  27. *
  28. * @param string $name Unknown property name.
  29. *
  30. * @throws BadMethodCallException
  31. */
  32. public function __get($name)
  33. {
  34. throw new BadMethodCallException(
  35. sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
  36. );
  37. }
  38. /**
  39. * Error handler for unknown property mutator in Annotation class.
  40. *
  41. * @param string $name Unknown property name.
  42. * @param mixed $value Property value.
  43. *
  44. * @throws BadMethodCallException
  45. */
  46. public function __set($name, $value)
  47. {
  48. throw new BadMethodCallException(
  49. sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
  50. );
  51. }
  52. }