private function mapCollectionType($fieldName, Field $field, ClassMetadata $metadata) { $options = $field->getOptions(); $collectionField = $this->fieldLoader->load($options['field_type'], FieldOptions::create($options['field_options'])); // assume that other types are scalars... $this->__invoke($fieldName, $collectionField, $metadata, ['serialize_scalar' => true]); }
public function __construct($class, $name, $type, $role, $group, array $options) { parent::__construct($class, $name); $this->type = $type; $this->role = $role; $this->group = $group; $this->options = FieldOptions::create($options); }
private function createProperty(string $propertyName, string $type, string $group = null, array $options) { $property = $this->prophesize(PropertyMetadata::class); $property->getType()->willReturn($type); $property->getGroup()->willReturn($group); $property->getOptions()->willReturn(FieldOptions::create($options)); $property->getName()->willReturn($propertyName); return $property; }
public function createView(ViewFactory $factory, $data, array $options) : ViewInterface { if (!is_array($data) && !$data instanceof \Traversable) { throw new \InvalidArgumentException(sprintf('Data must be traversable or an array, got: "%s"', is_object($data) ? get_class($data) : gettype($data))); } if (is_array($data)) { $data = new \ArrayIterator($data); } $field = $this->fieldLoader->load($options['field_type'], FieldOptions::create($options['field_options'])); return new CollectionView($factory, $data, $field->getViewType(), $field->getViewOptions()); }
/** * It should cache fields. */ public function testCache() { $this->fieldRegistry->get('foobar')->shouldBeCalledTimes(2)->willReturn($this->field1); $this->fieldRegistry->get('barfoo')->shouldBeCalledTimes(1)->willReturn($this->field1); $field1 = $this->loader->load('foobar', FieldOptions::create([])); $field2 = $this->loader->load('barfoo', FieldOptions::create([])); $field3 = $this->loader->load('foobar', FieldOptions::create([])); $field4 = $this->loader->load('foobar', FieldOptions::create(['shared' => ['fo' => 'ba']])); $this->assertSame($field1, $field3); $this->assertNotSame($field2, $field1); $this->assertNotSame($field4, $field3); }
/** * It should create a collection view from an iterator. * It should create a collection view from an array. * * @dataProvider provideViewIterate */ public function testViewIterate($data) { $fieldType = 'foo'; $viewType = 'view_type'; $viewOptions = ['foo' => 'bar']; $fieldOptions = ['view' => $viewOptions]; $this->fieldLoader->load($fieldType, FieldOptions::create($fieldOptions))->willReturn($this->field->reveal()); $this->field->getViewType()->willReturn($viewType); $this->field->getViewOptions()->willReturn($viewOptions); $view = $this->getType()->createView($this->factory->reveal(), $data, ['field_type' => $fieldType, 'field_options' => $fieldOptions]); $this->assertInstanceOf(CollectionView::class, $view); }
private function doTestMapOptions($type) { $setMethod = 'set' . $type . 'Mapper'; $resolveMethod = 'resolve' . $type . 'Options'; $this->resolver->setDefault('foo', 'bar'); $this->resolver->setDefault('bar', 'foo'); $this->resolver->{$setMethod}(function (array $options, array $shared) { return ['baz' => $shared['bar'], 'ban' => 'bon']; }); $options = $this->resolver->resolve([]); $this->assertEquals(['foo' => 'bar', 'bar' => 'foo'], $options); $this->assertEquals(['baz' => 'foo', 'ban' => 'bon'], $this->resolver->{$resolveMethod}(FieldOptions::create([]))); }
private function mapCollectionType($fieldName, Field $field, ClassMetadata $metadata) { $options = $field->getOptions(); $collectionField = $this->fieldLoader->load($options['field_type'], FieldOptions::create($options['field_options'])); if ($collectionField->getStorageType() === Type\ObjectType::class) { $options = $collectionField->getStorageOptions(); $this->unrestrictChildClass($options['class'], $metadata); $metadata->mapChildren(['fieldName' => $fieldName, 'fetchDepth' => 1, 'filter' => $this->encoder->encode($fieldName) . '-*', 'cascade' => ClassMetadata::CASCADE_ALL, 'nullable' => true]); return; } if ($collectionField->getStorageType() === Type\ReferenceType::class) { $metadata->mapManyToMany(['fieldName' => $fieldName, 'strategy' => 'hard', 'nullable' => true, 'cascade' => ClassMetadata::CASCADE_ALL]); return; } // assume that other types are scalars... $this->__invoke($fieldName, $collectionField, $metadata, ['multivalue' => true]); }
/** * If should create an object view. */ public function testCreateView() { $content = new \stdClass(); $value = 'value'; $this->metadataFactory->getMetadataForClass('stdClass')->willReturn($this->classMetadata->reveal()); $this->classMetadata->getPropertyMetadata()->willReturn([$this->propertyMetadata1->reveal()]); $viewOptions = ['foo' => 'bar']; $options = FieldOptions::create(['view' => $viewOptions]); $this->propertyMetadata1->getType()->willReturn('foobar'); $this->propertyMetadata1->getName()->willReturn('prop1'); $this->propertyMetadata1->getOptions()->willReturn($options); $this->propertyMetadata1->getValue($content)->willReturn($value); $this->factory->create('foobar', $value, $viewOptions)->willReturn($this->childView->reveal()); $this->fieldLoader->load('foobar', $options)->willReturn($this->field->reveal()); $this->field->getViewType()->willReturn('foobar'); $this->field->getViewOptions()->willReturn($viewOptions); $view = $this->getType()->createView($this->factory->reveal(), $content, []); $this->assertInstanceOf(ObjectView::class, $view); $view = $view['prop1']; $this->assertSame($this->childView->reveal(), $view); }
public function configureOptions(FieldOptionsResolver $options) { $options->setRequired(['field_type']); $options->setDefault('field_options', []); $options->setFormMapper(function (array $options, array $shared) { // default to allowing add / delete (contrary to the form types // default behavior). $options = array_merge(['allow_add' => true, 'allow_delete' => true], $options); // resolve the form options for the colletion entry. $field = $this->registry->get($shared['field_type']); $resolver = new FieldOptionsResolver(); $field->configureOptions($resolver); $entryOptions = $resolver->resolveFormOptions(FieldOptions::create($shared['field_options'])); // do not allow entry_type or entry_options to be overridden. $options['entry_type'] = $field->getFormType(); $options['entry_options'] = $entryOptions; return $options; }); $options->setViewMapper(function ($options, $shared) { return array_merge($options, ['field_type' => $shared['field_type'], 'field_options' => $shared['field_options']]); }); }
protected function getField(array $config) { return $this->fieldLoader->load($this->getFieldName(), FieldOptions::create($config)); }
private function createField(array $options) { return new Field($this->innerField->reveal(), FieldOptions::create($options)); }
public function resolveStorageOptions(FieldOptions $options) : array { return $this->resolveOptions($this->storageMapper, $options->getSharedOptions(), $options->getViewOptions()); }