ClassMetadata.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace JMS\SerializerBundle\Metadata;
  3. class ClassMetadata implements \Serializable
  4. {
  5. private $name;
  6. private $reflection;
  7. private $properties = array();
  8. private $exclusionPolicy = 'NONE';
  9. public function __construct($name)
  10. {
  11. $this->name = $name;
  12. $this->reflection = new \ReflectionClass($name);
  13. }
  14. public function getName()
  15. {
  16. return $this->name;
  17. }
  18. public function getReflection()
  19. {
  20. return $this->reflection;
  21. }
  22. public function getProperties()
  23. {
  24. return $this->properties;
  25. }
  26. public function addPropertyMetadata(PropertyMetadata $metadata)
  27. {
  28. $this->properties[$metadata->getName()] = $metadata;
  29. }
  30. public function getExclusionPolicy()
  31. {
  32. return $this->exclusionPolicy;
  33. }
  34. public function setExclusionPolicy($policy)
  35. {
  36. $this->exclusionPolicy = $policy;
  37. }
  38. public function serialize()
  39. {
  40. return serialize(array(
  41. $this->name,
  42. $this->properties,
  43. $this->exclusionPolicy,
  44. ));
  45. }
  46. public function unserialize($str)
  47. {
  48. list(
  49. $this->name,
  50. $this->properties,
  51. $this->exclusionPolicy
  52. ) = unserialize($str);
  53. $this->reflection = new \ReflectionClass($this->name);
  54. }
  55. }