public static function fromReflection(\ReflectionClass $ref) { $class = new static(); $class->setName($ref->name)->setAbstract($ref->isAbstract())->setFinal($ref->isFinal())->setConstants($ref->getConstants()); if (null === self::$phpParser) { if (!class_exists('Doctrine\\Common\\Annotations\\PhpParser')) { self::$phpParser = false; } else { self::$phpParser = new PhpParser(); } } if (false !== self::$phpParser) { $class->setUseStatements(self::$phpParser->parseClass($ref)); } if ($docComment = $ref->getDocComment()) { $class->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment)); } foreach ($ref->getMethods() as $method) { $class->setMethod(static::createMethod($method)); } foreach ($ref->getProperties() as $property) { $class->setProperty(static::createProperty($property)); } return $class; }
public static function fromReflection(\ReflectionProperty $ref) { $property = new static(); $property->setName($ref->name)->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE)); if ($docComment = $ref->getDocComment()) { $property->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment)); } $defaultProperties = $ref->getDeclaringClass()->getDefaultProperties(); if (isset($defaultProperties[$ref->name])) { $property->setDefaultValue($defaultProperties[$ref->name]); } return $property; }
public static function fromReflection(\ReflectionMethod $ref) { $method = new static(); $method->setFinal($ref->isFinal())->setAbstract($ref->isAbstract())->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE))->setReferenceReturned($ref->returnsReference())->setName($ref->name); if ($docComment = $ref->getDocComment()) { $method->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment)); } foreach ($ref->getParameters() as $param) { $method->addParameter(static::createParameter($param)); } // FIXME: Extract body? return $method; }
public static function fromReflection(\ReflectionFunction $ref) { $function = new static(); if (false === ($pos = strrpos($ref->name, '\\'))) { $function->setName(substr($ref->name, $pos + 1)); $function->setNamespace(substr($ref->name, $pos)); } else { $function->setName($ref->name); } $function->referenceReturned = $ref->returnsReference(); $function->docblock = ReflectionUtils::getUnindentedDocComment($ref->getDocComment()); foreach ($ref->getParameters() as $refParam) { assert($refParam instanceof \ReflectionParameter); $param = PhpParameter::fromReflection($refParam); $function->addParameter($param); } return $function; }
public function testGetUnindentedDocComment() { $writer = new Writer(); $comment = $writer->writeln('/**')->indent()->writeln(' * Foo.')->write(' */')->getContent(); $this->assertEquals("/**\n * Foo.\n */", ReflectionUtils::getUnindentedDocComment($comment)); }