Annotation.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /** @param array<string, mixed> $data Key-value for properties to be defined in this class. */
  17. final public function __construct(array $data)
  18. {
  19. foreach ($data as $key => $value) {
  20. $this->$key = $value;
  21. }
  22. }
  23. /**
  24. * Error handler for unknown property accessor in Annotation class.
  25. *
  26. * @param string $name Unknown property name.
  27. *
  28. * @throws BadMethodCallException
  29. */
  30. public function __get($name)
  31. {
  32. throw new BadMethodCallException(
  33. sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
  34. );
  35. }
  36. /**
  37. * Error handler for unknown property mutator in Annotation class.
  38. *
  39. * @param string $name Unknown property name.
  40. * @param mixed $value Property value.
  41. *
  42. * @throws BadMethodCallException
  43. */
  44. public function __set($name, $value)
  45. {
  46. throw new BadMethodCallException(
  47. sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
  48. );
  49. }
  50. }