Пример #1
0
 /**
  * @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;
 }
 /**
  * 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;
 }
 public function testGetLocatedSource()
 {
     $node = new Function_('foo');
     $locatedSource = new LocatedSource('<?php function foo() {}', null);
     $reflector = new FunctionReflector(new StringSourceLocator('<?php'));
     $functionInfo = ReflectionFunction::createFromNode($reflector, $node, $locatedSource);
     $this->assertSame($locatedSource, $functionInfo->getLocatedSource());
 }
 /**
  * Create the parameter from the given spec. Possible $spec parameters are:
  *
  *  - [$instance, 'method']
  *  - ['Foo', 'bar']
  *  - ['foo']
  *  - [function () {}]
  *
  * @param string[]|string|\Closure $spec
  * @param string $parameterName
  * @return ReflectionParameter
  * @throws \Exception
  * @throws \InvalidArgumentException
  */
 public static function createFromSpec($spec, $parameterName)
 {
     if (is_array($spec) && count($spec) === 2) {
         if (is_object($spec[0])) {
             return self::createFromClassInstanceAndMethod($spec[0], $spec[1], $parameterName);
         }
         return self::createFromClassNameAndMethod($spec[0], $spec[1], $parameterName);
     }
     if (is_string($spec)) {
         return ReflectionFunction::createFromName($spec)->getParameter($parameterName);
     }
     if ($spec instanceof \Closure) {
         throw new \Exception('Creating by closure is not supported yet');
     }
     throw new \InvalidArgumentException('Could not create reflection from the spec given');
 }
Пример #5
0
 /**
  * @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;
 }
 public function testStaticCreation()
 {
     require_once __DIR__ . '/../Fixture/Functions.php';
     $reflection = ReflectionFunction::createFromName('BetterReflectionTest\\Fixture\\myFunction');
     $this->assertSame('myFunction', $reflection->getShortName());
 }
 /**
  * @param string $functionName
  * @param string $expectedStringValue
  * @dataProvider functionStringRepresentations
  */
 public function testStringCast($functionName, $expectedStringValue)
 {
     require_once __DIR__ . '/../Fixture/Functions.php';
     $functionInfo = ReflectionFunction::createFromName($functionName);
     $this->assertStringMatchesFormat($expectedStringValue, (string) $functionInfo);
 }
 /**
  * {@inheritDoc}
  */
 public function isVariadic()
 {
     return $this->betterReflectionFunction->isVariadic();
 }