Пример #1
0
 /**
  * Load discriminator metadata
  *
  * @param ApiObject $object
  * @param ClassMetadata $metadata
  */
 private function loadDiscriminatorMetadata(ApiObject $object, ClassMetadata $metadata)
 {
     if (!$object->discField) {
         return;
     }
     $fieldMeta = null;
     $field = $object->discField;
     if ($metadata instanceof ObjectMetadataInterface) {
         $properties = $metadata->getProperties();
         if (array_key_exists($field, $properties)) {
             $fieldMeta = $properties[$field];
         }
     } elseif ($metadata instanceof ResourceMetadata) {
         $attributes = $metadata->getAttributes();
         if (array_key_exists($field, $attributes)) {
             $fieldMeta = $attributes[$field];
         }
     }
     if (null === $fieldMeta) {
         throw new \InvalidArgumentException("Specified discriminator field not found in object properties");
     } elseif ('scalar' !== $fieldMeta->getDataType() || 'string' !== $fieldMeta->getDataTypeParams()) {
         throw new \InvalidArgumentException("Discriminator field must point to property that contain string value");
     }
     $metadata->setDiscriminatorField($fieldMeta);
     $metadata->setDiscriminatorMap($object->discMap);
 }
Пример #2
0
 /**
  * @test
  */
 public function shouldBeAbleMergeMetadata()
 {
     $metadata = new ClassMetadata('MyClass');
     $metadata->mergeMetadata(new ClassMetadata('AnotherClass'));
     $this->assertSame(1, 1);
 }