Annotation.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * @throws BadMethodCallException
  27. */
  28. public function __get(string $name)
  29. {
  30. throw new BadMethodCallException(
  31. sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
  32. );
  33. }
  34. /**
  35. * Error handler for unknown property mutator in Annotation class.
  36. *
  37. * @param mixed $value Property value.
  38. *
  39. * @throws BadMethodCallException
  40. */
  41. public function __set(string $name, $value)
  42. {
  43. throw new BadMethodCallException(
  44. sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
  45. );
  46. }
  47. }