fromReflection() public static method

Creates a PHP trait from reflection
Deprecation: Use fromFile() instead
public static fromReflection ( ReflectionClass $ref ) : PhpTrait
$ref ReflectionClass
return PhpTrait
Exemplo n.º 1
0
 /**
  * Creates a PHP class from reflection
  * 
  * @param \ReflectionClass $ref
  * @return PhpClass
  */
 public static function fromReflection(\ReflectionClass $ref)
 {
     $class = new static();
     $class->setQualifiedName($ref->name)->setAbstract($ref->isAbstract())->setFinal($ref->isFinal())->setUseStatements(ReflectionUtils::getUseStatements($ref));
     if ($ref->getDocComment()) {
         $docblock = new Docblock($ref);
         $class->setDocblock($docblock);
         $class->setDescription($docblock->getShortDescription());
         $class->setLongDescription($docblock->getLongDescription());
     }
     // methods
     foreach ($ref->getMethods() as $method) {
         $class->setMethod(static::createMethod($method));
     }
     // properties
     foreach ($ref->getProperties() as $property) {
         $class->setProperty(static::createProperty($property));
     }
     // traits
     foreach ($ref->getTraits() as $trait) {
         $class->addTrait(PhpTrait::fromReflection($trait));
     }
     // constants
     // TODO: https://github.com/gossi/php-code-generator/issues/19
     $class->setConstants($ref->getConstants());
     return $class;
 }
Exemplo n.º 2
0
 public function testFromReflection()
 {
     $trait = new PhpTrait('DummyTrait');
     $trait->setNamespace('gossi\\codegen\\tests\\fixture');
     $trait->setDescription('Dummy docblock');
     $trait->setMethod(PhpMethod::create('foo')->setVisibility('public'));
     $trait->setProperty(PhpProperty::create('iAmHidden')->setVisibility('private'));
     // @TODO: this alias is only a workaround
     $trait->addUseStatement('gossi\\codegen\\tests\\fixture\\VeryDummyTrait');
     $trait->addTrait('VeryDummyTrait');
     $trait->generateDocblock();
     $this->assertEquals($trait, PhpTrait::fromReflection(new \ReflectionClass('gossi\\codegen\\tests\\fixture\\DummyTrait')));
 }
Exemplo n.º 3
0
 public static function fromReflection(\ReflectionClass $ref)
 {
     $trait = new static();
     $trait->setQualifiedName($ref->name);
     $trait->setUseStatements(ReflectionUtils::getUseStatements($ref));
     $docblock = new Docblock($ref);
     $trait->setDocblock($docblock);
     $trait->setDescription($docblock->getShortDescription());
     $trait->setLongDescription($docblock->getLongDescription());
     // traits
     foreach ($ref->getTraits() as $reflectionTrait) {
         $trait->addTrait(PhpTrait::fromReflection($reflectionTrait));
     }
     // properties
     foreach ($ref->getProperties() as $property) {
         $trait->setProperty(static::createProperty($property));
     }
     // methods
     foreach ($ref->getMethods() as $method) {
         $trait->setMethod(static::createMethod($method));
     }
     return $trait;
 }
Exemplo n.º 4
0
 public function testFromReflection()
 {
     $expected = Fixtures::createDummyTrait();
     $actual = PhpTrait::fromReflection(new \ReflectionClass('gossi\\codegen\\tests\\fixtures\\DummyTrait'));
     $this->assertEquals($expected, $actual);
 }