/** * builds a classSchema from a className, you have to require_once before importing the class * @param string $className * @return Tx_ExtensionBuilder_Domain_Model_Class_Class */ public function parse($className) { $this->starttime = microtime(TRUE); if (!class_exists($className)) { throw new Exception('Class not exists: ' . $className); } $this->initClassObject($className); $file = $this->classReflection->getFileName(); $fileHandler = fopen($file, 'r'); if (!$fileHandler) { throw new Exception('Could not open file: ' . $file); } $this->lineCount = 1; while (!feof($fileHandler)) { $this->currentLine = fgets($fileHandler); $trimmedLine = trim($this->currentLine); // save all comment found before the class start line if ($this->lineCount == $this->classReflection->getStartLine()) { $this->onClassDefinitionFound(); $this->lastMatchedLineNumber = $this->lineCount; } if (!empty($trimmedLine) && !$this->inMethodBody) { // if not in a comment we look for methods, properties or constants if (!$this->isSingleLineComment() && !$this->isMultiLineComment() && !empty($trimmedLine)) { // process methods if (preg_match_all($this->methodRegex, $trimmedLine, $methodMatches)) { $this->onMethodFound($methodMatches); } else { // a semicolon was found (but not in single or double quotes!) if ($this->inMultiLineProperty && preg_match('/(;)(?=(?:[^"\']|["|\'][^"\']*")*$)/', $trimmedLine)) { // the end line of a multi line property $this->onMultiLinePropertyEnd(); } // process constants if (preg_match_all($this->constantRegex, $trimmedLine, $constantMatches)) { $this->addConstant($constantMatches); $this->lastMatchedLineNumber = $this->lineCount; } // process properties if (preg_match_all($this->propertyRegex, $trimmedLine, $propertyMatches)) { $this->addProperty($propertyMatches); $this->lastMatchedLineNumber = $this->lineCount; } elseif (preg_match_all($this->multiLinePropertyRegex, $trimmedLine, $propertyMatches)) { // a multiline property is a property that has a multiline devault value (like an array for example) $this->inMultiLineProperty = TRUE; $this->multiLinePropertyMatches = $propertyMatches; $this->multiLinePropertyMatches['startLine'] = $this->lineCount; $this->lastMatchedLineNumber = $this->lineCount; } } } // end of not in comment } // end of not empty and not in method body if ($this->inMethodBody && $this->lineCount == $this->currentMethod['reflection']->getEndline()) { // endline of a method $this->onMethodEnd($trimmedLine); } // if no matches of the various regex are found, the line might be added // later (onMethodEnd or on Multiline property end) $this->lines[$this->lineCount] = $this->currentLine; $this->lineCount++; } // end while feof if ($this->lineCount > $this->classReflection->getEndLine()) { $appendedBlock = $this->concatLinesFromArray($this->lines, $this->classReflection->getEndLine()); $appendedBlock = str_replace('?>', '', $appendedBlock); $this->classObject->setAppendedBlock($appendedBlock); } // debug output if ($this->debugMode) { $this->debugInfo(); } // some checks again the reflection class if (count($this->classObject->getMethods()) != count($this->classReflection->getNotInheritedMethods())) { throw new Exception('Class ' . $className . ' could not be parsed properly. Method count does not equal reflection method count'); } if (count($this->classObject->getProperties()) != count($this->classReflection->getNotInheritedProperties())) { throw new Exception('Class ' . $className . ' could not be parsed properly. Property count does not equal reflection property count'); } return $this->classObject; }