IndexedReader.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Doctrine\Common\Annotations;
  3. use ReflectionClass;
  4. use ReflectionMethod;
  5. use ReflectionProperty;
  6. use function call_user_func_array;
  7. use function get_class;
  8. /**
  9. * Allows the reader to be used in-place of Doctrine's reader.
  10. */
  11. class IndexedReader implements Reader
  12. {
  13. /** @var Reader */
  14. private $delegate;
  15. public function __construct(Reader $reader)
  16. {
  17. $this->delegate = $reader;
  18. }
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function getClassAnnotations(ReflectionClass $class)
  23. {
  24. $annotations = [];
  25. foreach ($this->delegate->getClassAnnotations($class) as $annot) {
  26. $annotations[get_class($annot)] = $annot;
  27. }
  28. return $annotations;
  29. }
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function getClassAnnotation(ReflectionClass $class, $annotation)
  34. {
  35. return $this->delegate->getClassAnnotation($class, $annotation);
  36. }
  37. /**
  38. * {@inheritDoc}
  39. */
  40. public function getMethodAnnotations(ReflectionMethod $method)
  41. {
  42. $annotations = [];
  43. foreach ($this->delegate->getMethodAnnotations($method) as $annot) {
  44. $annotations[get_class($annot)] = $annot;
  45. }
  46. return $annotations;
  47. }
  48. /**
  49. * {@inheritDoc}
  50. */
  51. public function getMethodAnnotation(ReflectionMethod $method, $annotation)
  52. {
  53. return $this->delegate->getMethodAnnotation($method, $annotation);
  54. }
  55. /**
  56. * {@inheritDoc}
  57. */
  58. public function getPropertyAnnotations(ReflectionProperty $property)
  59. {
  60. $annotations = [];
  61. foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
  62. $annotations[get_class($annot)] = $annot;
  63. }
  64. return $annotations;
  65. }
  66. /**
  67. * {@inheritDoc}
  68. */
  69. public function getPropertyAnnotation(ReflectionProperty $property, $annotation)
  70. {
  71. return $this->delegate->getPropertyAnnotation($property, $annotation);
  72. }
  73. /**
  74. * Proxies all methods to the delegate.
  75. *
  76. * @param string $method
  77. * @param mixed[] $args
  78. *
  79. * @return mixed
  80. */
  81. public function __call($method, $args)
  82. {
  83. return call_user_func_array([$this->delegate, $method], $args);
  84. }
  85. }