/** * @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; }
/** * {@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); }
/** * {@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; }
public function testExceptionWhenThereIsNoGeneratorAbleToHandleProvidedOutline() { $msg = 'There is no type builder able to generate "string" type outline'; $this->setExpectedException('Wookieb\\ZorroDataSchema\\Exception\\UnableToGenerateTypeException', $msg); $this->object->generateType(new StringOutline(), $this->getImplementationMock()); }