コード例 #1
0
 /**
  * @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
 /**
  * Updates the resource fields with given data
  *
  * @param array                   $properties
  * @param FieldMetadataCollection $collection
  * @param object                  $resource
  */
 protected function updateEntityFields(array $properties, FieldMetadataCollection $collection, $resource)
 {
     foreach ($properties as $propertyName => $propertyValue) {
         if ($collection->has($propertyName) && is_scalar($propertyValue)) {
             if ($this->propertyAccessor->isWritable($resource, $propertyName)) {
                 $this->propertyAccessor->setValue($resource, $propertyName, $propertyValue);
             }
         }
     }
 }
コード例 #3
0
 /**
  * Checks whether the embeddable field is serializable
  *
  * @param string                  $embeddableName
  * @param FieldMetadataCollection $collection
  *
  * @return bool
  */
 protected function isEmbeddableSerializable($embeddableName, FieldMetadataCollection $collection)
 {
     if ($collection->has($embeddableName)) {
         $embeddable = $collection->get($embeddableName);
         return $embeddable->hasGroup($this->context['group']) || $embeddable->hasDefaultGroup();
     }
     return false;
 }