| 1 |
<?php |
| 2 |
|
| 3 |
namespace FL\Assistant\System\Container; |
| 4 |
|
| 5 |
class StandardReflector implements Reflector { |
| 6 |
|
| 7 |
public function getClass( $class ) { |
| 8 |
return new \ReflectionClass( $class ); |
| 9 |
} |
| 10 |
|
| 11 |
public function getCtor( $class ) { |
| 12 |
$reflectionClass = new \ReflectionClass( $class ); |
| 13 |
|
| 14 |
return $reflectionClass->getConstructor(); |
| 15 |
} |
| 16 |
|
| 17 |
public function getCtorParams( $class ) { |
| 18 |
return ( $reflectedCtor = $this->getCtor( $class ) ) |
| 19 |
? $reflectedCtor->getParameters() |
| 20 |
: null; |
| 21 |
} |
| 22 |
|
| 23 |
public function getParamTypeHint( \ReflectionFunctionAbstract $function, \ReflectionParameter $param ) { |
| 24 |
if ( version_compare( PHP_VERSION, '8.0.0', '<' ) ) { |
| 25 |
return ( $reflectionClass = $param->getClass() ) |
| 26 |
? $reflectionClass->getName() |
| 27 |
: null; |
| 28 |
} |
| 29 |
|
| 30 |
$type = $param->getType(); |
| 31 |
|
| 32 |
if ( 'ReflectionNamedType' === get_class( $type ) ) { |
| 33 |
$class = new \ReflectionClass( $type->getName() ); |
| 34 |
return $class->getName(); |
| 35 |
} |
| 36 |
|
| 37 |
return null; |
| 38 |
} |
| 39 |
|
| 40 |
public function getFunction( $functionName ) { |
| 41 |
return new \ReflectionFunction( $functionName ); |
| 42 |
} |
| 43 |
|
| 44 |
public function getMethod( $classNameOrInstance, $methodName ) { |
| 45 |
$className = is_string( $classNameOrInstance ) |
| 46 |
? $classNameOrInstance |
| 47 |
: get_class( $classNameOrInstance ); |
| 48 |
|
| 49 |
return new \ReflectionMethod( $className, $methodName ); |
| 50 |
} |
| 51 |
} |
| 52 |
|