菜谱项目

IndexedReader.php 3.2KB

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