/** * Compare the properties of each object and remove/update * the properties and the related methods * * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $oldDomainObject * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $newDomainObject * * return void (all actions are performed on $this->classObject */ protected function updateModelClassProperties(Tx_ExtensionBuilder_Domain_Model_DomainObject $oldDomainObject, Tx_ExtensionBuilder_Domain_Model_DomainObject $newDomainObject) { $newProperties = array(); foreach ($newDomainObject->getProperties() as $property) { $newProperties[$property->getUniqueIdentifier()] = $property; } //t3lib_div::devlog('properties new:','extension_builder',0,$newProperties); // compare all old properties with new ones foreach ($oldDomainObject->getProperties() as $oldProperty) { if (isset($newProperties[$oldProperty->getUniqueIdentifier()])) { $newProperty = $newProperties[$oldProperty->getUniqueIdentifier()]; // relation type changed if ($oldProperty->isAnyToManyRelation() != $newProperty->isAnyToManyRelation()) { t3lib_div::devlog('property type changed:' . $oldProperty->getName() . ' ' . $newProperty->getName(), 'extension_builder', 0, $newProperties); // remove old methods since we won't convert getter and setter methods to add/remove methods if ($oldProperty->isAnyToManyRelation()) { $this->classObject->removeMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($oldProperty->getName()))); $this->classObject->removeMethod('remove' . ucfirst(Tx_ExtensionBuilder_Utility_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(Tx_ExtensionBuilder_Utility_Inflector::singularize($oldProperty->getName()))); } $this->classObject->removeProperty($oldProperty->getName()); t3lib_div::devlog('property type changed => removed old property:' . $oldProperty->getName(), 'extension_builder', 1); } else { $this->updateProperty($oldProperty, $newProperty); $newDomainObject->getPropertyByName($newProperty->getName())->setNew(FALSE); } } else { $this->removePropertyAndRelatedMethods($oldProperty); } } }
/** * Not used right now * TODO: Needs better implementation * @param Tx_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 = $this->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); //t3lib_div::devlog('Methods after sorting', 'extension_builder', 0, array_keys($sortedMethods)); $this->classObject->setProperties($sortedProperties); $this->classObject->setMethods($sortedMethods); }