/** * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $domainProperty * @return void */ protected function addClassProperty($domainProperty) { // TODO the following part still needs some enhancement: // what should be obligatory in existing properties and methods $propertyName = $domainProperty->getName(); // add the property to class Object (or update an existing class Object property) if ($this->classObject->propertyExists($propertyName)) { $classProperty = $this->classObject->getProperty($propertyName); if ($this->settings['setDefaultValuesForClassProperties'] !== false) { $classProperty->setDefault($domainProperty->getDefaultValue()); } } else { $classProperty = clone $this->templateClassObject->getProperty('property'); $classProperty->setName($propertyName); $classProperty->setTag('var', $domainProperty->getTypeForComment()); if ($domainProperty->getDescription()) { $classProperty->setDescription($domainProperty->getDescription()); } else { $classProperty->setDescription(str_replace('property', $propertyName, $classProperty->getDescription())); } if ($domainProperty->getHasDefaultValue() && $this->settings['setDefaultValuesForClassProperties'] !== false) { $classProperty->setDefault($domainProperty->getDefaultValue()); } if ($domainProperty->isZeroToManyRelation()) { $classProperty->setTag('cascade', 'remove'); } } if ($domainProperty->getRequired()) { if (!$classProperty->isTaggedWith('validate')) { $validateTag = explode(' ', trim($domainProperty->getValidateAnnotation())); $classProperty->setTag('validate', $validateTag[1]); } } if ($domainProperty->isRelation()) { /** @var $domainProperty \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\AbstractRelation */ if ($domainProperty->getLazyLoading()) { if (!$classProperty->isTaggedWith('lazy')) { $classProperty->setTag('lazy', ''); } } } $this->classObject->setProperty($classProperty); }
/** * Rename a property and update comment (var tag and description) * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $oldProperty * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $newProperty * * @return void */ protected function updateProperty($oldProperty, $newProperty) { $classProperty = $this->classObject->getProperty($oldProperty->getName()); if ($classProperty) { $classProperty->setName($newProperty->getName()); $classProperty->setTag('var', $newProperty->getTypeForComment()); $newDescription = $newProperty->getDescription(); if (empty($newDescription) || $newDescription == $newProperty->getName()) { $newDescription = str_replace($oldProperty->getName(), $newProperty->getName(), $classProperty->getDescription()); } $classProperty->setDescription($newDescription); $this->classObject->removeProperty($oldProperty->getName()); $this->classObject->setProperty($classProperty); if ($this->relatedMethodsNeedUpdate($oldProperty, $newProperty)) { $this->updatePropertyRelatedMethods($oldProperty, $newProperty); } } }