/** * Adds one (or multiple) properties found in a source code line to the classObject * * @param array $propertyMatches as returned from preg_match_all */ protected function addProperty(array $propertyMatches, $startLine = NULL) { $properties = array_combine($propertyMatches['name'], $propertyMatches['value']); $isFirstProperty = TRUE; foreach ($properties as $propertyName => $propertyValue) { try { // the property has to exist in the classReflection $reflectionProperty = $this->classReflection->getProperty($propertyName); if ($reflectionProperty) { $classProperty = new Tx_ExtensionBuilder_Domain_Model_Class_Property($propertyName); $classProperty->mapToReflectionProperty($reflectionProperty); // get the default value from regex matches if (!empty($propertyValue)) { if (strlen($classProperty->getVarType()) < 1) { // try to detect the varType from default value if (strpos($propertyValue, 'array') > -1) { $varType = 'array'; } else { eval('$varType = gettype(' . $propertyValue . ');'); } if (!empty($varType) && $varType != 'NULL') { $classProperty->setVarType($varType); } } $classProperty->setValue(trim($propertyValue)); $classProperty->setDefault(TRUE); } if ($isFirstProperty) { // only the first property will get the preceding block assigned $precedingBlock = $this->concatLinesFromArray($this->lines, $this->lastMatchedLineNumber, $startLine, FALSE); $classProperty->setPrecedingBlock($precedingBlock); $isFirstProperty = FALSE; } $this->classObject->addProperty($classProperty); $this->lastMatchedLineNumber = $this->lineCount; } else { throw new Tx_ExtensionBuilder_Exception_ParseError(' Property ' . $propertyName . ' does not exist. Parsed from line ' . $this->lineCount . 'in ' . $this->classReflection->getFileName()); } } catch (ReflectionException $e) { // ReflectionClass throws an exception if a property was not found t3lib_div::devlog('Exception in line : ' . $e->getMessage() . 'Property ' . $propertyName . ' found in line ' . $this->lineCount, 'extension_builder'); } } }
/** * 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); }