/** * fromReflection() * * @param Zend_Reflection_File $reflectionFile * @return Zend_CodeGenerator_Php_File */ public static function fromReflection(Zend_Reflection_File $reflectionFile) { $file = new self(); $file->setSourceContent($reflectionFile->getContents()); $file->setSourceDirty(false); $body = $reflectionFile->getContents(); // @todo this whole area needs to be reworked with respect to how body lines are processed foreach ($reflectionFile->getClasses() as $class) { $file->setClass(Zend_CodeGenerator_Php_Class::fromReflection($class)); $classStartLine = $class->getStartLine(true); $classEndLine = $class->getEndLine(); $bodyLines = explode("\n", $body); $bodyReturn = array(); for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) { if ($lineNum == $classStartLine) { $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerClass); //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */'; $lineNum = $classEndLine; } else { $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion } } $body = implode("\n", $bodyReturn); unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); } if ($reflectionFile->getDocComment() != '') { $docblock = $reflectionFile->getDocblock(); $file->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($docblock)); $bodyLines = explode("\n", $body); $bodyReturn = array(); for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) { if ($lineNum == $docblock->getStartLine()) { $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerDocblock); //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */'; $lineNum = $docblock->getEndLine(); } else { $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion } } $body = implode("\n", $bodyReturn); unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); } $file->setBody($body); return $file; }
public function testFileGetDocblockReturnsFileDocblock() { $fileToRequire = dirname(__FILE__) . '/_files/TestSampleClass.php'; require_once $fileToRequire; $reflectionFile = new Zend_Reflection_File($fileToRequire); $this->assertTrue($reflectionFile->getDocblock() instanceof Zend_Reflection_Docblock); }