You are here

public static function Reflection::getParameterClassName in Drupal 9

Gets the parameter's class name.

Parameters

\ReflectionParameter $parameter: The parameter.

Return value

string|null The parameter's class name or NULL if the parameter is not a class.

4 calls to Reflection::getParameterClassName()
ArgumentsResolver::getArgument in core/lib/Drupal/Component/Utility/ArgumentsResolver.php
Gets the argument value for a parameter.
EntityResolverManager::setParametersFromReflection in core/lib/Drupal/Core/Entity/EntityResolverManager.php
Sets the upcasting information using reflection.
ReflectionTest::testGetParameterClassName in core/tests/Drupal/Tests/Component/Utility/ReflectionTest.php
@covers ::getParameterClassName @dataProvider providerGetParameterClassName
TaggedHandlersPass::processServiceCollectorPass in core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php
Processes a service collector service pass.

File

core/lib/Drupal/Component/Utility/Reflection.php, line 19

Class

Reflection
Provides helper methods for reflection.

Namespace

Drupal\Component\Utility

Code

public static function getParameterClassName(\ReflectionParameter $parameter) : ?string {
  $name = NULL;
  if ($parameter
    ->hasType() && !$parameter
    ->getType()
    ->isBuiltin()) {
    $name = $parameter
      ->getType()
      ->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;
}