PropertyMetadata.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /*
  3. * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace JMS\SerializerBundle\Metadata;
  18. class PropertyMetadata implements \Serializable
  19. {
  20. private $class;
  21. private $name;
  22. private $reflection;
  23. private $sinceVersion;
  24. private $untilVersion;
  25. private $serializedName;
  26. private $exposed;
  27. private $excluded;
  28. private $type;
  29. public function __construct($class, $name)
  30. {
  31. $this->class = $class;
  32. $this->name = $name;
  33. $this->exposed = false;
  34. $this->excluded = false;
  35. $this->reflection = new \ReflectionProperty($class, $name);
  36. $this->reflection->setAccessible(true);
  37. }
  38. public function getClass()
  39. {
  40. return $this->class;
  41. }
  42. public function getName()
  43. {
  44. return $this->name;
  45. }
  46. public function getReflection()
  47. {
  48. return $this->reflection;
  49. }
  50. public function setSinceVersion($version)
  51. {
  52. $this->sinceVersion = $version;
  53. }
  54. public function getSinceVersion()
  55. {
  56. return $this->sinceVersion;
  57. }
  58. public function setUntilVersion($version)
  59. {
  60. $this->untilVersion = $version;
  61. }
  62. public function getUntilVersion()
  63. {
  64. return $this->untilVersion;
  65. }
  66. public function setSerializedName($name)
  67. {
  68. $this->serializedName = $name;
  69. }
  70. public function getSerializedName()
  71. {
  72. return $this->serializedName;
  73. }
  74. public function setExposed($bool)
  75. {
  76. $this->exposed = (Boolean) $bool;
  77. }
  78. public function isExposed()
  79. {
  80. return $this->exposed;
  81. }
  82. public function setExcluded($bool)
  83. {
  84. $this->excluded = (Boolean) $bool;
  85. }
  86. public function isExcluded()
  87. {
  88. return $this->excluded;
  89. }
  90. public function setType($type)
  91. {
  92. $this->type = $type;
  93. }
  94. public function getType()
  95. {
  96. return $this->type;
  97. }
  98. public function serialize()
  99. {
  100. return serialize(array(
  101. $this->class,
  102. $this->name,
  103. $this->sinceVersion,
  104. $this->untilVersion,
  105. $this->serializedName,
  106. $this->exposed,
  107. $this->excluded,
  108. $this->type,
  109. ));
  110. }
  111. public function unserialize($str)
  112. {
  113. list(
  114. $this->class,
  115. $this->name,
  116. $this->sinceVersion,
  117. $this->untilVersion,
  118. $this->serializedName,
  119. $this->exposed,
  120. $this->excluded,
  121. $this->type
  122. ) = unserialize($str);
  123. $this->reflection = new \ReflectionProperty($this->class, $this->name);
  124. $this->reflection->setAccessible(true);
  125. }
  126. }