Exemple #1
0
 /**
  * Parse JSON API resource metadata
  *
  * @param ApiResource $resource
  * @param \ReflectionClass $class
  * @return ResourceMetadata
  */
 private function loadResourceMetadata(ApiResource $resource, \ReflectionClass $class)
 {
     $metadata = new ResourceMetadata($class->name);
     $metadata->setName($resource->name);
     $properties = $class->getProperties();
     foreach ($properties as $property) {
         if ($property->getDeclaringClass()->name !== $class->name) {
             continue;
         }
         foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
             if ($annotation instanceof Attribute) {
                 $metadata->addAttribute($this->loadPropertyMetadata($annotation, $property));
             } elseif ($annotation instanceof Relationship) {
                 $metadata->addRelationship($this->loadPropertyMetadata($annotation, $property));
             } elseif ($annotation instanceof Id) {
                 $metadata->setIdMetadata($this->loadPropertyMetadata($annotation, $property));
             }
         }
     }
     $this->loadDiscriminatorMetadata($resource, $metadata);
     return $metadata;
 }
 /**
  * @test
  * @expectedException \RuntimeException
  */
 public function shouldThrowOnInvalidMetadataDuringMerge()
 {
     $resMetadata = new ResourceMetadata('MyResource');
     $objMetadata = new ObjectMetadata('MyObject');
     $resMetadata->mergeMetadata($objMetadata);
 }