LazyLoadableObjectClassMetadata.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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\Tests\Common\Proxy;
  20. use ReflectionClass;
  21. use Doctrine\Common\Persistence\Mapping\ClassMetadata;
  22. /**
  23. * Class metadata test asset for @see LazyLoadableObject
  24. *
  25. * @author Marco Pivetta <ocramius@gmail.com>
  26. * @since 2.4
  27. */
  28. class LazyLoadableObjectClassMetadata implements ClassMetadata
  29. {
  30. /**
  31. * @var ReflectionClass
  32. */
  33. protected $reflectionClass;
  34. /**
  35. * @var array
  36. */
  37. protected $identifier = array(
  38. 'publicIdentifierField' => true,
  39. 'protectedIdentifierField' => true,
  40. );
  41. /**
  42. * @var array
  43. */
  44. protected $fields = array(
  45. 'publicIdentifierField' => true,
  46. 'protectedIdentifierField' => true,
  47. 'publicPersistentField' => true,
  48. 'protectedPersistentField' => true,
  49. );
  50. /**
  51. * @var array
  52. */
  53. protected $associations = array(
  54. 'publicAssociation' => true,
  55. 'protectedAssociation' => true,
  56. );
  57. /**
  58. * {@inheritDoc}
  59. */
  60. public function getName()
  61. {
  62. return $this->getReflectionClass()->getName();
  63. }
  64. /**
  65. * {@inheritDoc}
  66. */
  67. public function getIdentifier()
  68. {
  69. return array_keys($this->identifier);
  70. }
  71. /**
  72. * {@inheritDoc}
  73. */
  74. public function getReflectionClass()
  75. {
  76. if (null === $this->reflectionClass) {
  77. $this->reflectionClass = new \ReflectionClass(__NAMESPACE__ . '\LazyLoadableObject');
  78. }
  79. return $this->reflectionClass;
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. public function isIdentifier($fieldName)
  85. {
  86. return isset($this->identifier[$fieldName]);
  87. }
  88. /**
  89. * {@inheritDoc}
  90. */
  91. public function hasField($fieldName)
  92. {
  93. return isset($this->fields[$fieldName]);
  94. }
  95. /**
  96. * {@inheritDoc}
  97. */
  98. public function hasAssociation($fieldName)
  99. {
  100. return isset($this->associations[$fieldName]);
  101. }
  102. /**
  103. * {@inheritDoc}
  104. */
  105. public function isSingleValuedAssociation($fieldName)
  106. {
  107. throw new \BadMethodCallException('not implemented');
  108. }
  109. /**
  110. * {@inheritDoc}
  111. */
  112. public function isCollectionValuedAssociation($fieldName)
  113. {
  114. throw new \BadMethodCallException('not implemented');
  115. }
  116. /**
  117. * {@inheritDoc}
  118. */
  119. public function getFieldNames()
  120. {
  121. return array_keys($this->fields);
  122. }
  123. /**
  124. * {@inheritDoc}
  125. */
  126. public function getIdentifierFieldNames()
  127. {
  128. return $this->getIdentifier();
  129. }
  130. /**
  131. * {@inheritDoc}
  132. */
  133. public function getAssociationNames()
  134. {
  135. return array_keys($this->associations);
  136. }
  137. /**
  138. * {@inheritDoc}
  139. */
  140. public function getTypeOfField($fieldName)
  141. {
  142. return 'string';
  143. }
  144. /**
  145. * {@inheritDoc}
  146. */
  147. public function getAssociationTargetClass($assocName)
  148. {
  149. throw new \BadMethodCallException('not implemented');
  150. }
  151. /**
  152. * {@inheritDoc}
  153. */
  154. public function isAssociationInverseSide($assocName)
  155. {
  156. throw new \BadMethodCallException('not implemented');
  157. }
  158. /**
  159. * {@inheritDoc}
  160. */
  161. public function getAssociationMappedByTargetField($assocName)
  162. {
  163. throw new \BadMethodCallException('not implemented');
  164. }
  165. /**
  166. * {@inheritDoc}
  167. */
  168. public function getIdentifierValues($object)
  169. {
  170. throw new \BadMethodCallException('not implemented');
  171. }
  172. }