Jelajahi Sumber

switched metadata to public properties

Johannes Schmitt 14 tahun lalu
induk
melakukan
69d8f62fcb

+ 2 - 12
Metadata/ClassHierarchyMetadata.php

@@ -20,21 +20,11 @@ namespace JMS\SerializerBundle\Metadata;
 
 class ClassHierarchyMetadata
 {
-    private $classes = array();
+    public $classes = array();
 
     public function addClass(ClassMetadata $class)
     {
-        $this->classes[$class->getName()] = $class;
-    }
-
-    public function getClasses()
-    {
-        return $this->classes;
-    }
-
-    public function getOutsideClass()
-    {
-        return end($this->classes);
+        $this->classes[$class->name] = $class;
     }
 
     public function getLastModified()

+ 5 - 30
Metadata/ClassMetadata.php

@@ -20,10 +20,10 @@ namespace JMS\SerializerBundle\Metadata;
 
 class ClassMetadata implements \Serializable
 {
-    private $name;
-    private $reflection;
-    private $properties = array();
-    private $exclusionPolicy = 'NONE';
+    public $name;
+    public $reflection;
+    public $properties = array();
+    public $exclusionPolicy = 'NONE';
 
     public function __construct($name)
     {
@@ -31,34 +31,9 @@ class ClassMetadata implements \Serializable
         $this->reflection = new \ReflectionClass($name);
     }
 
-    public function getName()
-    {
-        return $this->name;
-    }
-
-    public function getReflection()
-    {
-        return $this->reflection;
-    }
-
-    public function getProperties()
-    {
-        return $this->properties;
-    }
-
     public function addPropertyMetadata(PropertyMetadata $metadata)
     {
-        $this->properties[$metadata->getName()] = $metadata;
-    }
-
-    public function getExclusionPolicy()
-    {
-        return $this->exclusionPolicy;
-    }
-
-    public function setExclusionPolicy($policy)
-    {
-        $this->exclusionPolicy = $policy;
+        $this->properties[$metadata->name] = $metadata;
     }
 
     public function serialize()

+ 7 - 7
Metadata/Driver/AnnotationDriver.php

@@ -43,7 +43,7 @@ class AnnotationDriver implements DriverInterface
         $classMetadata = new ClassMetadata($name = $class->getName());
         foreach ($this->reader->getClassAnnotations($class) as $annot) {
             if ($annot instanceof ExclusionPolicy) {
-                $classMetadata->setExclusionPolicy($annot->getStrategy());
+                $classMetadata->exclusionPolicy = $annot->getStrategy();
             }
         }
 
@@ -55,17 +55,17 @@ class AnnotationDriver implements DriverInterface
             $propertyMetadata = new PropertyMetadata($name, $property->getName());
             foreach ($this->reader->getPropertyAnnotations($property) as $annot) {
                 if ($annot instanceof Since) {
-                    $propertyMetadata->setSinceVersion($annot->getVersion());
+                    $propertyMetadata->sinceVersion = $annot->getVersion();
                 } else if ($annot instanceof Until) {
-                    $propertyMetadata->setUntilVersion($annot->getVersion());
+                    $propertyMetadata->untilVersion = $annot->getVersion();
                 } else if ($annot instanceof SerializedName) {
-                    $propertyMetadata->setSerializedName($annot->getName());
+                    $propertyMetadata->serializedName = $annot->getName();
                 } else if ($annot instanceof Expose) {
-                    $propertyMetadata->setExposed(true);
+                    $propertyMetadata->exposed = true;
                 } else if ($annot instanceof Exclude) {
-                    $propertyMetadata->setExcluded(true);
+                    $propertyMetadata->excluded = true;
                 } else if ($annot instanceof Type) {
-                    $propertyMetadata->setType($annot->getName());
+                    $propertyMetadata->type = $annot->getName();
                 }
             }
             $classMetadata->addPropertyMetadata($propertyMetadata);

+ 9 - 84
Metadata/PropertyMetadata.php

@@ -20,15 +20,15 @@ namespace JMS\SerializerBundle\Metadata;
 
 class PropertyMetadata implements \Serializable
 {
-    private $class;
-    private $name;
-    private $reflection;
-    private $sinceVersion;
-    private $untilVersion;
-    private $serializedName;
-    private $exposed;
-    private $excluded;
-    private $type;
+    public $class;
+    public $name;
+    public $reflection;
+    public $sinceVersion;
+    public $untilVersion;
+    public $serializedName;
+    public $exposed;
+    public $excluded;
+    public $type;
 
     public function __construct($class, $name)
     {
@@ -41,81 +41,6 @@ class PropertyMetadata implements \Serializable
         $this->reflection->setAccessible(true);
     }
 
-    public function getClass()
-    {
-        return $this->class;
-    }
-
-    public function getName()
-    {
-        return $this->name;
-    }
-
-    public function getReflection()
-    {
-        return $this->reflection;
-    }
-
-    public function setSinceVersion($version)
-    {
-        $this->sinceVersion = $version;
-    }
-
-    public function getSinceVersion()
-    {
-        return $this->sinceVersion;
-    }
-
-    public function setUntilVersion($version)
-    {
-        $this->untilVersion = $version;
-    }
-
-    public function getUntilVersion()
-    {
-        return $this->untilVersion;
-    }
-
-    public function setSerializedName($name)
-    {
-        $this->serializedName = $name;
-    }
-
-    public function getSerializedName()
-    {
-        return $this->serializedName;
-    }
-
-    public function setExposed($bool)
-    {
-        $this->exposed = (Boolean) $bool;
-    }
-
-    public function isExposed()
-    {
-        return $this->exposed;
-    }
-
-    public function setExcluded($bool)
-    {
-        $this->excluded = (Boolean) $bool;
-    }
-
-    public function isExcluded()
-    {
-        return $this->excluded;
-    }
-
-    public function setType($type)
-    {
-        $this->type = $type;
-    }
-
-    public function getType()
-    {
-        return $this->type;
-    }
-
     public function serialize()
     {
         return serialize(array(

+ 1 - 1
Serializer/Exclusion/AllExclusionStrategy.php

@@ -32,6 +32,6 @@ class AllExclusionStrategy implements ExclusionStrategyInterface
      */
     public function shouldSkipProperty(PropertyMetadata $property)
     {
-        return !$property->isExposed();
+        return !$property->exposed;
     }
 }

+ 1 - 1
Serializer/Exclusion/NoneExclusionStrategy.php

@@ -32,6 +32,6 @@ class NoneExclusionStrategy implements ExclusionStrategyInterface
      */
     public function shouldSkipProperty(PropertyMetadata $property)
     {
-        return $property->isExcluded();
+        return $property->excluded;
     }
 }

+ 2 - 2
Serializer/Exclusion/VersionExclusionStrategy.php

@@ -34,11 +34,11 @@ class VersionExclusionStrategy implements ExclusionStrategyInterface
      */
     public function shouldSkipProperty(PropertyMetadata $property)
     {
-        if ((null !== $version = $property->getSinceVersion()) && version_compare($this->version, $version, '<')) {
+        if ((null !== $version = $property->sinceVersion) && version_compare($this->version, $version, '<')) {
             return true;
         }
 
-        if ((null !== $version = $property->getUntilVersion()) && version_compare($this->version, $version, '>')) {
+        if ((null !== $version = $property->untilVersion) && version_compare($this->version, $version, '>')) {
             return true;
         }
 

+ 1 - 1
Serializer/Naming/CamelCaseNamingStrategy.php

@@ -43,7 +43,7 @@ class CamelCaseNamingStrategy implements PropertyNamingStrategyInterface
     {
         $separator = &$this->separator;
 
-        $name = preg_replace('/[A-Z]/', $separator.'\\0', $property->getName());
+        $name = preg_replace('/[A-Z]/', $separator.'\\0', $property->name);
 
         if ($this->lowerCase) {
             return strtolower($name);

+ 1 - 1
Serializer/Naming/SerializedNameAnnotationStrategy.php

@@ -40,7 +40,7 @@ class SerializedNameAnnotationStrategy implements PropertyNamingStrategyInterfac
      */
     public function translateName(PropertyMetadata $property)
     {
-        if (null !== $name = $property->getSerializedName()) {
+        if (null !== $name = $property->serializedName) {
             return $name;
         }
 

+ 11 - 11
Serializer/Normalizer/PropertyBasedNormalizer.php

@@ -64,14 +64,14 @@ class PropertyBasedNormalizer extends SerializerAwareNormalizer
         $normalized = array();
         $metadata = $this->metadataFactory->getMetadataForClass(get_class($object));
 
-        foreach ($metadata->getClasses() as $classMetadata) {
-            $exclusionStrategy = $this->exclusionStrategyFactory->getStrategy($classMetadata->getExclusionPolicy());
-            foreach ($classMetadata->getProperties() as $propertyMetadata) {
+        foreach ($metadata->classes as $classMetadata) {
+            $exclusionStrategy = $this->exclusionStrategyFactory->getStrategy($classMetadata->exclusionPolicy);
+            foreach ($classMetadata->properties as $propertyMetadata) {
                 if ($exclusionStrategy->shouldSkipProperty($propertyMetadata)) {
                     continue;
                 }
 
-                $value = $this->serializer->normalize($propertyMetadata->getReflection()->getValue($object), $format);
+                $value = $this->serializer->normalize($propertyMetadata->reflection->getValue($object), $format);
 
                 // skip null-value properties
                 if (null === $value) {
@@ -95,12 +95,12 @@ class PropertyBasedNormalizer extends SerializerAwareNormalizer
         }
 
         $metadata = $this->metadataFactory->getMetadataForClass($type);
-        $object = $this->instanceCreator->createInstance($metadata->getOutsideClass()->getReflection());
+        $object = $this->instanceCreator->createInstance(end($metadata->classes)->reflection);
 
-        foreach ($metadata->getClasses() as $classMetadata) {
-            $exclusionStrategy = $this->exclusionStrategyFactory->getStrategy($classMetadata->getExclusionPolicy());
+        foreach ($metadata->classes as $classMetadata) {
+            $exclusionStrategy = $this->exclusionStrategyFactory->getStrategy($classMetadata->exclusionPolicy);
 
-            foreach ($classMetadata->getProperties() as $propertyMetadata) {
+            foreach ($classMetadata->properties as $propertyMetadata) {
                 if ($exclusionStrategy->shouldSkipProperty($propertyMetadata)) {
                     continue;
                 }
@@ -110,12 +110,12 @@ class PropertyBasedNormalizer extends SerializerAwareNormalizer
                     continue;
                 }
 
-                if (null === $type = $propertyMetadata->getType()) {
-                    throw new RuntimeException(sprintf('You must define the type for %s::$%s.', $propertyMetadata->getClass(), $propertyMetadata->getName()));
+                if (null === $type = $propertyMetadata->type) {
+                    throw new RuntimeException(sprintf('You must define the type for %s::$%s.', $propertyMetadata->class, $propertyMetadata->name));
                 }
 
                 $value = $this->serializer->denormalize($data[$serializedName], $type, $format);
-                $propertyMetadata->getReflection()->setValue($object, $value);
+                $propertyMetadata->reflection->setValue($object, $value);
             }
         }
 

+ 1 - 1
phpunit.xml.dist

@@ -20,7 +20,7 @@
     
     <groups>
         <exclude>
-            <group>performance</group>
+	    <group>performance</group>
         </exclude>
     </groups>
 </phpunit>