/** * @param PropertyOutline $property * @param ClassTypeImplementation $classOptions * @param ImplementationInterface $implementation * * @return PropertyDefinition */ protected function createPropertyDefinition(PropertyOutline $property, ClassTypeImplementation $classOptions, ImplementationInterface $implementation) { $propertyType = $this->schemaLinker->generateType($property->getType(), $implementation); $propertyDefinition = new PropertyDefinition($property->getName(), $propertyType); $propertyImplementation = $classOptions->getImplementationForProperty($property->getName()); $targetPropertyName = $propertyImplementation->getTargetPropertyName(); if ($targetPropertyName) { $propertyDefinition->setTargetPropertyName($targetPropertyName); } // nullable $propertyDefinition->setIsNullable($property->isNullable()); // default value if ($property->hasDefaultValue()) { $propertyDefinition->setDefaultValue($property->getDefaultValue()); } // setters and getters $setter = $propertyImplementation->getSetter(); if ($setter) { $propertyDefinition->setSetterName($setter); } $getter = $propertyImplementation->getGetter(); if ($getter) { $propertyDefinition->setGetterName($getter); } return $propertyDefinition; }
protected function setUp() { $this->schemaLinker = new SchemaLinker(); $this->schemaLinker->setSchema(new BasicSchema()); $this->object = new ChoiceTypeBuilder(); $this->object->setSchemaLinker($this->schemaLinker); $this->schemaLinker->registerTypeBuilder($this->object); }
public function testConvert() { $implementation = $this->getImplementationMock(); $elementsTypeOutline = new BooleanOutline(); $this->schemaLinker->expects($this->once())->method('generateType')->with($this->equalTo($elementsTypeOutline), $this->equalTo($implementation))->will($this->returnValue(new BooleanType())); $typeOutline = new CollectionOutline('collection<boolean>', $elementsTypeOutline); $this->assertTrue($this->object->isAbleToGenerate($typeOutline)); $this->assertInstanceOf('Wookieb\\ZorroDataSchema\\Schema\\Type\\CollectionType', $this->object->generate($typeOutline, $implementation)); }
/** * {@inheritDoc} */ public function generate(TypeOutlineInterface $typeOutline, ImplementationInterface $implementation) { if (!$this->isAbleToGenerate($typeOutline)) { throw new UnableToGenerateTypeException('Invalid type outline', $typeOutline); } /* @var \Wookieb\ZorroDataSchema\SchemaOutline\TypeOutline\CollectionOutline $typeOutline */ $collectionElementsType = $this->schemaLinker->generateType($typeOutline->getElementsType(), $implementation); return new CollectionType($typeOutline->getName(), $collectionElementsType); }
/** * {@inheritDoc} */ public function generate(TypeOutlineInterface $typeOutline, ImplementationInterface $implementation) { if (!$this->isAbleToGenerate($typeOutline)) { throw new UnableToGenerateTypeException('Invalid type outline', $typeOutline); } /** @var MapOutline $typeOutline */ $keyType = $this->linker->generateType($typeOutline->getKeyTypeOutline(), $implementation); $valueType = $this->linker->generateType($typeOutline->getValueTypeOutline(), $implementation); return new MapType($keyType, $valueType); }
protected function setUp() { $this->schema = new Schema(); $this->schema->registerType('string', new StringType()); $this->schemaLinker = new SchemaLinker(); $this->schemaLinker->setSchema($this->schema); $this->classMap = new ClassMap(); $this->implementation = new Implementation($this->classMap); $this->object = new ClassTypeBuilder(); $this->object->setSchemaLinker($this->schemaLinker); $this->schemaLinker->registerTypeBuilder($this->object); }
/** * {@inheritDoc} */ public function generate(TypeOutlineInterface $typeOutline, ImplementationInterface $implementation) { if (!$this->isAbleToGenerate($typeOutline)) { throw new UnableToGenerateTypeException('Invalid type outline', $typeOutline); } /** @var ChoiceTypeOutline $typeOutline */ $outlines = $typeOutline->getTypeOutlines(); if (count($outlines) < 2) { throw new UnableToGenerateTypeException('Choice type must use at least 2 types', $typeOutline); } $type = new ChoiceType(); foreach ($outlines as $typeOutline) { $type->addType($typeOutline->getName(), $this->linker->generateType($typeOutline, $implementation)); } return $type; }
private function prepareLinker($useMockGenerator = true) { $outline = new SchemaOutline(); $outline->addTypeOutline(new StringOutline())->addTypeOutline(new BooleanOutline()); $implementation = new Implementation(); $this->object->registerTypeBuilder(new BasicTypesBuilder()); if ($useMockGenerator) { $mockTypeBuilder = $this->getMockForAbstractClass('Wookieb\\ZorroDataSchema\\Schema\\Builder\\TypeBuilders\\TypeBuilderInterface'); $mockTypeBuilder->expects($this->atLeastOnce())->method('isAbleToGenerate')->will($this->returnCallback(function ($value) { return $value instanceof BooleanOutline; })); $mockTypeBuilder->expects($this->once())->method('generate')->with($this->equalTo(new BooleanOutline()), $this->equalTo($implementation))->will($this->returnValue(new FloatType())); $this->object->registerTypeBuilder($mockTypeBuilder, 100); } return array($outline, $implementation); }