示例#1
0
 public function generateCode($source, $target, $constructor = false)
 {
     $classAnalyzer = new ClassAnalyzer();
     $classAnalyzer->setFile($source);
     $parent = Object::make($classAnalyzer->getClassName());
     $targetClassName = $this->getClassName($target);
     $file = File::make($target);
     $object = Object::make($targetClassName);
     $object->extend($parent);
     $file->addFullyQualifiedName(new FullyQualifiedName($classAnalyzer->getFullClassName()));
     if ($constructor) {
         $constructor = $classAnalyzer->getConstructor();
         $method = Method::make('__construct');
         foreach ($constructor as $parameter) {
             $type = $parameter[0];
             if ($type === null) {
                 $type = 'null';
             }
             $method->addArgument(new Argument($type, $parameter[1]));
             $method->setBody('parent::__construct()');
         }
         $object->addMethod($method);
     }
     $file->setStructure($object);
     $prettyPrinter = Build::prettyPrinter();
     $generatedCode = $prettyPrinter->generateCode($file);
     return $generatedCode;
 }
示例#2
0
 function testGetFullClassName()
 {
     $analyzer = new ClassAnalyzer();
     $analyzer->setCode($this->getCodeExampleOne());
     $this->assertEquals('Acme\\Demo\\Foo', $analyzer->getFullClassName());
 }