getDeclaringClass() публичный Метод

public getDeclaringClass ( ) : ReflectionClass
Результат ReflectionClass
Пример #1
0
 /**
  * Given a property, attempt to find the type of the property.
  *
  * @param ReflectionProperty $reflectionProperty
  * @return Type[]
  */
 public function __invoke(ReflectionProperty $reflectionProperty)
 {
     $contextFactory = new ContextFactory();
     $context = $contextFactory->createForNamespace($reflectionProperty->getDeclaringClass()->getNamespaceName(), $reflectionProperty->getDeclaringClass()->getLocatedSource()->getSource());
     $docBlock = DocBlockFactory::createInstance()->create($reflectionProperty->getDocComment(), new Context($context->getNamespace(), $context->getNamespaceAliases()));
     /* @var \phpDocumentor\Reflection\DocBlock\Tags\Var_ $varTag */
     $resolvedTypes = [];
     $varTags = $docBlock->getTagsByName('var');
     foreach ($varTags as $varTag) {
         $resolvedTypes = array_merge($resolvedTypes, (new ResolveTypes())->__invoke(explode('|', $varTag->getType()), $context));
     }
     return $resolvedTypes;
 }
Пример #2
0
 /**
  * Given a property, attempt to find the type of the property
  *
  * @param PropertyNode $node
  * @param ReflectionProperty $reflectionProperty
  * @return Type[]
  */
 public function __invoke(PropertyNode $node, ReflectionProperty $reflectionProperty)
 {
     $contextFactory = new ContextFactory();
     $context = $contextFactory->createForNamespace($reflectionProperty->getDeclaringClass()->getNamespaceName(), $reflectionProperty->getDeclaringClass()->getLocatedSource()->getSource());
     /* @var \PhpParser\Comment\Doc $comment */
     if (!$node->hasAttribute('comments')) {
         return [];
     }
     $comment = $node->getAttribute('comments')[0];
     $docBlock = new DocBlock($comment->getReformattedText(), new DocBlock\Context($context->getNamespace(), $context->getNamespaceAliases()));
     /* @var \phpDocumentor\Reflection\DocBlock\Tag\VarTag $varTag */
     $resolvedTypes = [];
     $varTags = $docBlock->getTagsByName('var');
     foreach ($varTags as $varTag) {
         $resolvedTypes = array_merge($resolvedTypes, (new ResolveTypes())->__invoke($varTag->getTypes(), $context));
     }
     return $resolvedTypes;
 }
Пример #3
0
 /**
  * Factory depuis une reflection
  *
  * @param ReflectionProperty $reflection
  * @return static
  */
 public static function fromReflection(ReflectionProperty $reflection)
 {
     // gestion du type
     $type = implode('|', $reflection->getDocBlockTypeStrings());
     // cas de la valeur null
     $value = $reflection->getDefaultValue();
     if (is_null($value)) {
         $value = Maker::NO_VALUE;
         $class = $reflection->getDeclaringClass();
         foreach ($class->getAst()->stmts as $stmt) {
             // si pas un attribut, on zap
             if (!$stmt instanceof \PhpParser\Node\Stmt\Property) {
                 continue;
             }
             foreach ($stmt->props as $prop) {
                 if ($prop instanceof \PhpParser\Node\Stmt\PropertyProperty) {
                     // lecture du fichier
                     $file = file($class->getFileName());
                     if (!empty($line = $file[$prop->getLine() - 1])) {
                         if (strpos($line, '=')) {
                             $value = null;
                         }
                     }
                 }
             }
         }
     }
     // construction
     $property = new static($reflection->getName(), $value, $type);
     // docblock
     $docblock = new \phpDocumentor\Reflection\DocBlock($reflection->getDocComment());
     $property->setSummary($docblock->getShortDescription());
     $property->setDescription($docblock->getLongDescription());
     // gestion des modifiers
     $reflection->isPrivate() ? $property->enablePrivate() : $property->disablePrivate();
     $reflection->isProtected() ? $property->enableProtected() : $property->disabledProtected();
     $reflection->isPublic() ? $property->enablePublic() : $property->disablePublic();
     $reflection->isStatic() ? $property->enableStatic() : $property->disableStatic();
     return $property;
 }
 /**
  * {@inheritDoc}
  */
 public function getDeclaringClass()
 {
     return new ReflectionClass($this->betterReflectionProperty->getDeclaringClass());
 }