IndexedReader.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. use Doctrine\Common\Annotations\Reader;
  21. /**
  22. * Allows the reader to be used in-place of Doctrine's reader.
  23. *
  24. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  25. */
  26. class IndexedReader implements Reader
  27. {
  28. /**
  29. * @var Reader
  30. */
  31. private $delegate;
  32. /**
  33. * Constructor
  34. *
  35. * @param Reader $reader
  36. */
  37. public function __construct(Reader $reader)
  38. {
  39. $this->delegate = $reader;
  40. }
  41. /**
  42. * Get Annotations for class
  43. *
  44. * @param \ReflectionClass $class
  45. * @return array
  46. */
  47. public function getClassAnnotations(\ReflectionClass $class)
  48. {
  49. $annotations = array();
  50. foreach ($this->delegate->getClassAnnotations($class) as $annot) {
  51. $annotations[get_class($annot)] = $annot;
  52. }
  53. return $annotations;
  54. }
  55. /**
  56. * Get selected annotation for class
  57. *
  58. * @param \ReflectionClass $class
  59. * @param string $annotation
  60. * @return mixed
  61. */
  62. public function getClassAnnotation(\ReflectionClass $class, $annotation)
  63. {
  64. return $this->delegate->getClassAnnotation($class, $annotation);
  65. }
  66. /**
  67. * Get Annotations for method
  68. *
  69. * @param \ReflectionMethod $method
  70. * @return array
  71. */
  72. public function getMethodAnnotations(\ReflectionMethod $method)
  73. {
  74. $annotations = array();
  75. foreach ($this->delegate->getMethodAnnotations($method) as $annot) {
  76. $annotations[get_class($annot)] = $annot;
  77. }
  78. return $annotations;
  79. }
  80. /**
  81. * Get selected annotation for method
  82. *
  83. * @param \ReflectionMethod $method
  84. * @param string $annotation
  85. * @return mixed
  86. */
  87. public function getMethodAnnotation(\ReflectionMethod $method, $annotation)
  88. {
  89. return $this->delegate->getMethodAnnotation($method, $annotation);
  90. }
  91. /**
  92. * Get annotations for property
  93. *
  94. * @param \ReflectionProperty $property
  95. * @return array
  96. */
  97. public function getPropertyAnnotations(\ReflectionProperty $property)
  98. {
  99. $annotations = array();
  100. foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
  101. $annotations[get_class($annot)] = $annot;
  102. }
  103. return $annotations;
  104. }
  105. /**
  106. * Get selected annotation for property
  107. *
  108. * @param \ReflectionProperty $property
  109. * @param string $annotation
  110. * @return mixed
  111. */
  112. public function getPropertyAnnotation(\ReflectionProperty $property, $annotation)
  113. {
  114. return $this->delegate->getPropertyAnnotation($property, $annotation);
  115. }
  116. /**
  117. * Proxy all methods to the delegate.
  118. *
  119. * @param string $method
  120. * @param array $args
  121. * @return mixed
  122. */
  123. public function __call($method, $args)
  124. {
  125. return call_user_func_array(array($this->delegate, $method), $args);
  126. }
  127. }