예제 #1
0
 /**
  * fromReflection()
  *
  * @param FileReflection $fileReflection
  * @return FileGenerator
  */
 public static function fromReflection(FileReflection $fileReflection)
 {
     $file = new self();
     $file->setSourceContent($fileReflection->getContents());
     $file->setSourceDirty(false);
     $body = $fileReflection->getContents();
     foreach ($fileReflection->getClasses() as $class) {
         /* @var $class \Zend\Code\Reflection\ReflectionClass */
         $phpClass = ClassGenerator::fromReflection($class);
         $phpClass->setContainingFileGenerator($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(), '/* Zend_CodeGenerator_Php_File-ClassMarker: {?} */');
                 $lineNum = $classEndLine;
             } else {
                 $bodyReturn[] = $bodyLines[$lineNum - 1];
                 // adjust for index -> line conversion
             }
         }
         $body = implode("\n", $bodyReturn);
         unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine);
     }
     $namespace = $fileReflection->getNamespace();
     if ($namespace != '') {
         $file->setNamespace($fileReflection->getNamespace());
     }
     $uses = $fileReflection->getUses();
     if ($uses) {
         $file->setUses($uses);
     }
     if ($fileReflection->getDocComment() != '') {
         /* @var $docblock \DocBlockReflection\Code\Reflection\ReflectionDocblock */
         $docblock = $fileReflection->getDocblock();
         $file->setDocblock(DocblockGenerator::fromReflection($docblock));
         $bodyLines = explode("\n", $body);
         $bodyReturn = array();
         for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) {
             if ($lineNum == $docblock->getStartLine()) {
                 $bodyReturn[] = str_replace('?', $class->getName(), '/* Zend_CodeGenerator_Php_File-DocblockMarker */');
                 $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;
 }
예제 #2
0
 /**
  * @param  FileReflection $fileReflection
  * @return FileGenerator
  */
 public static function fromReflection(FileReflection $fileReflection)
 {
     $file = new static();
     $file->setSourceContent($fileReflection->getContents());
     $file->setSourceDirty(false);
     $uses = $fileReflection->getUses();
     foreach ($fileReflection->getClasses() as $class) {
         $phpClass = ClassGenerator::fromReflection($class);
         $phpClass->setContainingFileGenerator($file);
         foreach ($uses as $fileUse) {
             $phpClass->addUse($fileUse['use'], $fileUse['as']);
         }
         $file->setClass($phpClass);
     }
     $namespace = $fileReflection->getNamespace();
     if ($namespace != '') {
         $file->setNamespace($namespace);
     }
     if ($uses) {
         $file->setUses($uses);
     }
     if ($fileReflection->getDocComment() != '') {
         $docBlock = $fileReflection->getDocBlock();
         $file->setDocBlock(DocBlockGenerator::fromReflection($docBlock));
     }
     return $file;
 }