예제 #1
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;
 }
예제 #2
0
 public function testFileGetDocBlockReturnsFileDocBlock()
 {
     $fileToReflect = __DIR__ . '/TestAsset/TestSampleClass7.php';
     include_once $fileToReflect;
     $reflectionFile = new FileReflection($fileToReflect);
     $reflectionDocBlock = $reflectionFile->getDocBlock();
     $this->assertTrue($reflectionDocBlock instanceof \Zend\Code\Reflection\DocBlockReflection);
     $authorTag = $reflectionDocBlock->getTag('author');
     $this->assertEquals('Jeremiah Small', $authorTag->getAuthorName());
     $this->assertEquals('*****@*****.**', $authorTag->getAuthorEmail());
 }
예제 #3
0
 /**
  * @param  FileReflection $fileReflection
  * @return FileGenerator
  */
 public static function fromReflection(FileReflection $fileReflection)
 {
     $file = new static();
     $file->setSourceContent($fileReflection->getContents());
     $file->setSourceDirty(false);
     $body = $fileReflection->getContents();
     foreach ($fileReflection->getClasses() as $class) {
         $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, $count = count($bodyLines); $lineNum <= $count; $lineNum++) {
             if ($lineNum == $classStartLine) {
                 $bodyReturn[] = str_replace('?', $class->getName(), '/* Zend_Code_Generator_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($namespace);
     }
     $uses = $fileReflection->getUses();
     if ($uses) {
         $file->setUses($uses);
     }
     if ($fileReflection->getDocComment() != '') {
         $docBlock = $fileReflection->getDocBlock();
         $file->setDocBlock(DocBlockGenerator::fromReflection($docBlock));
         $bodyLines = explode("\n", $body);
         $bodyReturn = array();
         for ($lineNum = 1, $count = count($bodyLines); $lineNum <= $count; $lineNum++) {
             if ($lineNum == $docBlock->getStartLine()) {
                 $bodyReturn[] = str_replace('?', $class->getName(), '/* Zend_Code_Generator_FileGenerator-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;
 }
예제 #4
0
 public function testFileGetDocBlockReturnsFileDocBlock()
 {
     $fileToReflect = __DIR__ . '/TestAsset/TestSampleClass7.php';
     include_once $fileToReflect;
     $reflectionFile = new FileReflection($fileToReflect);
     $this->assertTrue($reflectionFile->getDocBlock() instanceof \Zend\Code\Reflection\DocBlockReflection);
     $this->assertEquals('Jeremiah Small <*****@*****.**>', $reflectionFile->getDocBlock()->getTag('author')->getContent());
 }