createFromName() public static method

Create a ReflectionClass by name, using default reflectors etc.
public static createFromName ( string $className ) : ReflectionClass
$className string
return ReflectionClass
 /**
  * Create a reflection of a class's property by it's name
  *
  * @param string $className
  * @param string $propertyName
  * @return ReflectionMethod
  */
 public static function createFromName($className, $propertyName)
 {
     return ReflectionClass::createFromName($className)->getProperty($propertyName);
 }
Exemplo n.º 2
0
<?php

// Load an autoloadable class
require_once __DIR__ . '/../../vendor/autoload.php';
use BetterReflection\Reflection\ReflectionClass;
$reflection = ReflectionClass::createFromName(ReflectionClass::class);
echo $reflection->getName() . "\n";
// ReflectionClass
echo ($reflection->isInternal() === true ? 'internal' : 'not internal') . "\n";
// not internal
Exemplo n.º 3
0
 public function testStaticCreation()
 {
     $reflection = ReflectionClass::createFromName('BetterReflectionTest\\Fixture\\ExampleClass');
     $this->assertSame('ExampleClass', $reflection->getShortName());
 }
Exemplo n.º 4
0
<?php

// Load a standard (internal) class
require_once __DIR__ . '/../../vendor/autoload.php';
use BetterReflection\Reflection\ReflectionClass;
$reflection = ReflectionClass::createFromName('stdClass');
var_dump($reflection->getName());
// stdClass
var_dump($reflection->isInternal());
// true
 /**
  * Create a reflection of a parameter using a class name
  *
  * @param string $className
  * @param string $methodName
  * @param string $parameterName
  * @return ReflectionParameter
  */
 public static function createFromClassNameAndMethod($className, $methodName, $parameterName)
 {
     return ReflectionClass::createFromName($className)->getMethod($methodName)->getParameter($parameterName);
 }
Exemplo n.º 6
0
 /**
  * Factory depuis une class existante
  *
  * @param $class
  */
 public static function load($class)
 {
     $instance = new static();
     $instance->setClass(ReflectionClass::createFromName($class));
     return $instance;
 }
Exemplo n.º 7
0
 public function testGetParentClassThrowsExceptionWithNoParent()
 {
     $reflection = ReflectionClass::createFromName('BetterReflectionTest\\Fixture\\ExampleClass');
     $this->assertNull($reflection->getParentClass());
 }
Exemplo n.º 8
0
 public function testClassToString()
 {
     $reflection = ReflectionClass::createFromName('BetterReflectionTest\\Fixture\\ExampleClass');
     $this->assertStringMatchesFormat(file_get_contents(__DIR__ . '/../Fixture/ExampleClassExport.txt'), $reflection->__toString());
 }
 /**
  * Create a reflection of a method by it's name using a named class
  *
  * @param string $className
  * @param string $methodName
  * @return ReflectionMethod
  */
 public static function createFromName($className, $methodName)
 {
     return ReflectionClass::createFromName($className)->getMethod($methodName);
 }