-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReflection.php
More file actions
36 lines (31 loc) · 942 Bytes
/
Reflection.php
File metadata and controls
36 lines (31 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Drupal\Component\Utility;
/**
* Provides helper methods for reflection.
*/
final class Reflection {
/**
* Gets the parameter's class name.
*
* @param \ReflectionParameter $parameter
* The parameter.
*
* @return string|null
* The parameter's class name or NULL if the parameter is not a class.
*/
public static function getParameterClassName(\ReflectionParameter $parameter) : ?string {
$name = NULL;
$parameterType = $parameter->getType();
if ($parameterType instanceof \ReflectionNamedType && !$parameterType->isBuiltin()) {
$name = $parameterType->getName();
$lc_name = strtolower($name);
switch ($lc_name) {
case 'self':
return $parameter->getDeclaringClass()->getName();
case 'parent':
return ($parent = $parameter->getDeclaringClass()->getParentClass()) ? $parent->name : NULL;
}
}
return $name;
}
}