/** * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @throws \InvalidArgumentException */ public function prepareLabelArrayForContextHelp($domainObject) { $labelArray = array(); foreach ($domainObject->getProperties() as $property) { $labelArray[$property->getFieldName() . '.description'] = htmlspecialchars($property->getDescription()); } return $labelArray; }
/** * Not used right now * TODO: Needs better implementation * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @return void */ public function sortMethods($domainObject) { $objectProperties = $domainObject->getProperties(); $sortedProperties = array(); $propertyRelatedMethods = array(); $customMethods = array(); // sort all properties and methods according to domainObject sort order foreach ($objectProperties as $objectProperty) { if ($this->classObject->propertyExists($objectProperty->getName())) { $sortedProperties[$objectProperty->getName()] = $this->classObject->getProperty($objectProperty->getName()); $methodPrefixes = array('get', 'set', 'add', 'remove', 'is'); foreach ($methodPrefixes as $methodPrefix) { $methodName = self::getMethodName($objectProperty, $methodPrefix); if ($this->classObject->methodExists($methodName)) { $propertyRelatedMethods[$methodName] = $this->classObject->getMethod($methodName); } } } } // add the properties that were not in the domainObject $classProperties = $this->classObject->getProperties(); $sortedPropertyNames = array_keys($sortedProperties); foreach ($classProperties as $classProperty) { if (!in_array($classProperty->getName(), $sortedProperties)) { $sortedProperties[$classProperty->getName()] = $classProperty; } } // add custom methods that were manually added to the class $classMethods = $this->classObject->getMethods(); $propertyRelatedMethodNames = array_keys($propertyRelatedMethods); foreach ($classMethods as $classMethod) { if (!in_array($classMethod->getName(), $propertyRelatedMethodNames)) { $customMethods[$classMethod->getName()] = $classMethod; } } $sortedMethods = array_merge($customMethods, $propertyRelatedMethods); $this->classObject->setProperties($sortedProperties); $this->classObject->setMethods($sortedMethods); }
/** * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @return void * @throws ExtensionException */ private function validateProperties($domainObject) { $propertyNames = array(); foreach ($domainObject->getProperties() as $property) { // Check if property name is given if (!$property->getName()) { $this->validationResult['errors'][] = new ExtensionException('A property of ' . $domainObject->getName() . ' has no name', self::ERROR_PROPERTY_NO_NAME); } $propertyName = $property->getName(); /** * Character test * Allowed characters are: a-z (lowercase), A-Z (uppercase) and 0-9 */ if (!preg_match('/^[a-zA-Z0-9]*$/', $propertyName)) { $this->validationResult['errors'][] = new ExtensionException('Illegal property name "' . $propertyName . '" of ' . $domainObject->getName() . '.' . LF . 'Please use lowerCamelCase, no spaces or underscores.', self::ERROR_PROPERTY_ILLEGAL_CHARACTER); } $firstChar = $propertyName[0]; if (strtoupper($firstChar) == $firstChar) { $this->validationResult['errors'][] = new ExtensionException('Illegal first character of property name "' . $property->getName() . '" of domain object "' . $domainObject->getName() . '".' . LF . 'Please use lowerCamelCase.', self::ERROR_PROPERTY_UPPER_FIRST_CHARACTER); } if (\EBT\ExtensionBuilder\Service\ValidationService::isReservedTYPO3Word($propertyName)) { $this->validationResult['warnings'][] = new ExtensionException('The name of property "' . $propertyName . '" in Model "' . $domainObject->getName() . '" will result in a TYPO3 specific column name.' . LF . ' This might result in unexpected behaviour. If you didn\'t choose that name by purpose' . LF . ' it is recommended to use another name', self::ERROR_PROPERTY_RESERVED_WORD); } if (\EBT\ExtensionBuilder\Service\ValidationService::isReservedMYSQLWord($propertyName)) { $this->validationResult['warnings'][] = new ExtensionException('Property "' . $propertyName . '" in Model "' . $domainObject->getName() . '".', self::ERROR_PROPERTY_RESERVED_SQL_WORD); } // Check for duplicate property names if (in_array($propertyName, $propertyNames)) { $this->validationResult['errors'][] = new ExtensionException('Property "' . $property->getName() . '" of ' . $domainObject->getName() . ' exists twice.', self::ERROR_PROPERTY_DUPLICATE); } $propertyNames[] = $propertyName; if ($property instanceof \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\AbstractRelation) { if (!$property->getForeignModel() && $property->getForeignClassName()) { if (!class_exists($property->getForeignClassName())) { $this->validationResult['errors'][] = new ExtensionException('Related class not loadable: "' . $property->getForeignClassName() . '" configured in relation "' . $property->getName() . '".', self::ERROR_MAPPING_NO_FOREIGNCLASS); } } if ($property->getForeignModel() && $property->getForeignModel()->getFullQualifiedClassName() != $property->getForeignClassName()) { $this->validationResult['errors'][] = new ExtensionException('Relation "' . $property->getName() . '" in model "' . $domainObject->getName() . '" has a external class relation and a wire to ' . $property->getForeignModel()->getName(), self::ERROR_MAPPING_WIRE_AND_FOREIGNCLASS); } } } }
/** * Compare the properties of each object and remove/update * the properties and the related methods * * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $oldDomainObject * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $newDomainObject * * return void (all actions are performed on $this->classObject */ protected function updateModelClassProperties(Model\DomainObject $oldDomainObject, Model\DomainObject $newDomainObject) { $newProperties = array(); foreach ($newDomainObject->getProperties() as $property) { $newProperties[$property->getUniqueIdentifier()] = $property; } // compare all old properties with new ones foreach ($oldDomainObject->getProperties() as $oldProperty) { /* @var Model\DomainObject\AbstractProperty $oldProperty * @var Model\DomainObject\AbstractProperty $newProperty */ if (isset($newProperties[$oldProperty->getUniqueIdentifier()])) { $newProperty = $newProperties[$oldProperty->getUniqueIdentifier()]; // relation type changed if ($oldProperty->isAnyToManyRelation() != $newProperty->isAnyToManyRelation()) { // remove old methods since we won't convert getter and setter methods //to add/remove methods if ($oldProperty->isAnyToManyRelation()) { $this->classObject->removeMethod('add' . ucfirst(Inflector::singularize($oldProperty->getName()))); $this->classObject->removeMethod('remove' . ucfirst(Inflector::singularize($oldProperty->getName()))); } $this->classObject->removeMethod('get' . ucfirst($oldProperty->getName())); $this->classObject->removeMethod('set' . ucfirst($oldProperty->getName())); if ($oldProperty->isBoolean()) { $this->classObject->removeMethod('is' . ucfirst(Inflector::singularize($oldProperty->getName()))); } $this->classObject->removeProperty($oldProperty->getName()); $this->log('property type changed => removed old property:' . $oldProperty->getName(), 1); } else { $this->updateProperty($oldProperty, $newProperty); $newDomainObject->getPropertyByName($newProperty->getName())->setNew(false); } } else { $this->removePropertyAndRelatedMethods($oldProperty); } } }