Ejemplo n.º 1
0
 /**
  * fromReflection()
  *
  * @param \Zend\Reflection\ReflectionFile $reflectionFile
  * @return \Zend\CodeGenerator\Php\PhpFile
  */
 public static function fromReflection(Reflection\ReflectionFile $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) {
         $phpClass = PhpClass::fromReflection($class);
         $phpClass->setPhpFile($file);
         $file->setClass($phpClass);
         $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);
     }
     $namespace = $reflectionFile->getNamespace();
     if ($namespace != '') {
         $file->setNamespace($reflectionFile->getNamespace());
     }
     $uses = $reflectionFile->getUses();
     if ($uses) {
         $file->setUses($uses);
     }
     if ($reflectionFile->getDocComment() != '') {
         $docblock = $reflectionFile->getDocblock();
         $file->setDocblock(PhpDocblock::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;
 }
Ejemplo n.º 2
0
 public function testFileGetDocblockReturnsFileDocblock()
 {
     $fileToReflect = __DIR__ . '/TestAsset/TestSampleClass.php';
     include_once $fileToReflect;
     $reflectionFile = new Reflection\ReflectionFile($fileToReflect);
     $this->assertTrue($reflectionFile->getDocblock() instanceof \Zend\Reflection\ReflectionDocblock);
 }