/**
  * @param OptionsResolver $resolver
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setRequired(['fields', 'associations', 'callbacks']);
     $fieldsNormalizer = function (Options $options, $fields) {
         $collection = new Collection\FieldMetadataCollection();
         $factory = new FieldMetadataFactory();
         foreach ($fields as $fieldName => $parameters) {
             $fieldMetadata = $factory->create($fieldName, $parameters);
             $collection->add($fieldMetadata);
         }
         return $collection;
     };
     $associationsNormalizer = function (Options $options, $associations) {
         $collection = new Collection\AssociationMetadataCollection();
         $factory = new AssociationMetadataFactory();
         foreach ($associations as $associationName => $parameters) {
             $associationMetadata = $factory->create($associationName, $parameters);
             $collection->add($associationMetadata);
         }
         return $collection;
     };
     $resolver->setNormalizer('fields', $fieldsNormalizer);
     $resolver->setNormalizer('associations', $associationsNormalizer);
     $resolver->setDefaults(['fields' => new Collection\FieldMetadataCollection(), 'associations' => new Collection\AssociationMetadataCollection(), 'callbacks' => []]);
     $resolver->setAllowedTypes('fields', ['array', Collection\FieldMetadataCollection::class]);
     $resolver->setAllowedTypes('associations', ['array', Collection\AssociationMetadataCollection::class]);
     $resolver->setAllowedTypes('callbacks', 'array');
 }
예제 #2
0
 /**
  * Loop through all passed properties and update the associations
  *
  * @param array                         $properties
  * @param AssociationMetadataCollection $collection
  * @param object                        $resource
  */
 protected function updateEntityAssociations(array $properties, AssociationMetadataCollection $collection, $resource)
 {
     $entityMetadata = $this->getEntityMetadata($resource);
     foreach ($properties as $propertyName => $propertyValue) {
         if ($collection->has($propertyName)) {
             $this->updateEntityAssociation($propertyName, $propertyValue, $resource, $entityMetadata);
         }
     }
 }
예제 #3
0
 /**
  * Checks whether the association is serializable
  *
  * @param string                        $associationName
  * @param AssociationMetadataCollection $collection
  *
  * @return bool
  */
 protected function isAssociationSerializable($associationName, AssociationMetadataCollection $collection)
 {
     if ($collection->has($associationName)) {
         $association = $collection->get($associationName);
         return $association->hasGroup($this->context['group']) || $association->hasDefaultGroup();
     }
     return false;
 }