Create from a Class Node.
public static createFromNode ( BetterReflection\Reflector\Reflector $reflector, |
||
$reflector | BetterReflection\Reflector\Reflector | |
$node | ||
$locatedSource | BetterReflection\SourceLocator\Located\LocatedSource | |
$namespace | optional - if omitted, we assume it is global namespaced class | |
리턴 |
/** * Take an AST node in some located source (potentially in a namespace) and * convert it to a Reflection * * @param Reflector $reflector * @param Node $node * @param LocatedSource $locatedSource * @param Node\Stmt\Namespace_|null $namespace * @return Reflection|null */ public function __invoke(Reflector $reflector, Node $node, LocatedSource $locatedSource, Node\Stmt\Namespace_ $namespace = null) { if ($node instanceof Node\Stmt\ClassLike) { return ReflectionClass::createFromNode($reflector, $node, $locatedSource, $namespace); } if ($node instanceof Node\FunctionLike) { return ReflectionFunction::createFromNode($reflector, $node, $locatedSource, $namespace); } return null; }
/** * @param Node $node * @param LocatedSource $locatedSource * @param Node\Stmt\Namespace_|null $namespace * @return Reflection|null */ private function reflectNode(Node $node, LocatedSource $locatedSource, Node\Stmt\Namespace_ $namespace = null) { if ($node instanceof Node\Stmt\ClassLike) { return ReflectionClass::createFromNode(new ClassReflector($this->sourceLocator), $node, $locatedSource, $namespace); } if ($node instanceof Node\Stmt\Function_) { return ReflectionFunction::createFromNode(new FunctionReflector($this->sourceLocator), $node, $locatedSource, $namespace); } return null; }
/** * @param Node $node * @param LocatedSource $locatedSource * @param Node\Stmt\Namespace_|null $namespace * @return Reflection|null */ private function reflectNode(Node $node, LocatedSource $locatedSource, Node\Stmt\Namespace_ $namespace = null) { if ($node instanceof Node\Stmt\Class_) { return ReflectionClass::createFromNode($node, $locatedSource, $namespace); } if ($node instanceof Node\Stmt\Function_) { return ReflectionFunction::createFromNode($node, $locatedSource, $namespace); } return null; }
public function testFetchingFqsenThrowsExceptionWithNonObjectName() { $sourceLocator = new StringSourceLocator('<?php class Foo {}'); $reflector = new ClassReflector($sourceLocator); $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)); $locatedSource = $sourceLocator->__invoke($identifier); $node = new Class_('Foo'); $reflection = ReflectionClass::createFromNode($reflector, $node, $locatedSource); $reflectionClassReflection = new \ReflectionClass(ReflectionClass::class); $reflectionClassMethodReflection = $reflectionClassReflection->getMethod('getFqsenFromNamedNode'); $reflectionClassMethodReflection->setAccessible(true); $nameNode = new Name(['int']); $this->setExpectedException(\Exception::class, 'Unable to determine FQSEN for named node'); $reflectionClassMethodReflection->invoke($reflection, $nameNode); }