Ejemplo n.º 1
0
 /**
  * Returns class' code inside namespace
  *
  * @param ClassReflection $class
  */
 private function dumpClass(ClassReflection $class)
 {
     if (array_search($class->getName(), $this->cachedClasses) !== false) {
         return;
     }
     if ($class->isInternal()) {
         return;
     }
     if ($class->getParentClass()) {
         $this->dumpClass($class->getParentClass());
     }
     foreach ($class->getInterfaces() as $interface) {
         $this->dumpClass($interface);
     }
     if ($class->getTraits()) {
         foreach ($class->getTraits() as $trait) {
             $this->dumpClass($trait);
         }
     }
     $classContents = $class->getContents(false);
     $classFileDir = dirname($class->getFileName());
     $classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
     $uses = implode("\n", $this->codeGenerator->getUseLines($class));
     $this->cache[] = "namespace " . $class->getNamespaceName() . " {\n" . ($uses ? $uses . "\n" : '') . $this->codeGenerator->getDeclarationLine($class) . "\n" . $classContents . "\n}\n";
     $this->cachedClasses[] = $class->getName();
 }
Ejemplo n.º 2
0
 /**
  * @param $class
  * @param $expectedLines
  * @dataProvider provideDataForGetUseLines
  */
 public function testGetUseLines($class, $expectedLines)
 {
     $generator = new CodeGenerator();
     $lines = $generator->getUseLines(new ClassReflection($class));
     $this->assertEquals($expectedLines, $lines);
 }