Drupal investigation

ClassMetadata.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Mapping;
  11. /**
  12. * {@inheritdoc}
  13. *
  14. * @author Kévin Dunglas <dunglas@gmail.com>
  15. */
  16. class ClassMetadata implements ClassMetadataInterface
  17. {
  18. /**
  19. * @var string
  20. *
  21. * @internal This property is public in order to reduce the size of the
  22. * class' serialized representation. Do not access it. Use
  23. * {@link getName()} instead.
  24. */
  25. public $name;
  26. /**
  27. * @var AttributeMetadataInterface[]
  28. *
  29. * @internal This property is public in order to reduce the size of the
  30. * class' serialized representation. Do not access it. Use
  31. * {@link getAttributesMetadata()} instead.
  32. */
  33. public $attributesMetadata = array();
  34. /**
  35. * @var \ReflectionClass
  36. */
  37. private $reflClass;
  38. /**
  39. * Constructs a metadata for the given class.
  40. *
  41. * @param string $class
  42. */
  43. public function __construct($class)
  44. {
  45. $this->name = $class;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function getName()
  51. {
  52. return $this->name;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function addAttributeMetadata(AttributeMetadataInterface $attributeMetadata)
  58. {
  59. $this->attributesMetadata[$attributeMetadata->getName()] = $attributeMetadata;
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function getAttributesMetadata()
  65. {
  66. return $this->attributesMetadata;
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function merge(ClassMetadataInterface $classMetadata)
  72. {
  73. foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) {
  74. if (isset($this->attributesMetadata[$attributeMetadata->getName()])) {
  75. $this->attributesMetadata[$attributeMetadata->getName()]->merge($attributeMetadata);
  76. } else {
  77. $this->addAttributeMetadata($attributeMetadata);
  78. }
  79. }
  80. }
  81. /**
  82. * {@inheritdoc}
  83. */
  84. public function getReflectionClass()
  85. {
  86. if (!$this->reflClass) {
  87. $this->reflClass = new \ReflectionClass($this->getName());
  88. }
  89. return $this->reflClass;
  90. }
  91. /**
  92. * Returns the names of the properties that should be serialized.
  93. *
  94. * @return string[]
  95. */
  96. public function __sleep()
  97. {
  98. return array(
  99. 'name',
  100. 'attributesMetadata',
  101. );
  102. }
  103. }