class Reflection

Same name in other branches
  1. 9 core/lib/Drupal/Component/Utility/Reflection.php \Drupal\Component\Utility\Reflection
  2. 10 core/lib/Drupal/Component/Utility/Reflection.php \Drupal\Component\Utility\Reflection

Provides helper methods for reflection.

Hierarchy

Expanded class hierarchy of Reflection

3 files declare their use of Reflection
EntityResolverManager.php in core/lib/Drupal/Core/Entity/EntityResolverManager.php
ReflectionTest.php in core/tests/Drupal/Tests/Component/Utility/ReflectionTest.php
TaggedHandlersPass.php in core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php

File

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

Namespace

Drupal\Component\Utility
View source
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;
        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;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Reflection::getParameterClassName public static function Gets the parameter's class name.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.