Reflection.php

Same filename and directory in other branches
  1. 9 core/lib/Drupal/Component/Utility/Reflection.php
  2. 10 core/lib/Drupal/Component/Utility/Reflection.php

Namespace

Drupal\Component\Utility

File

core/lib/Drupal/Component/Utility/Reflection.php

View source
<?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;
        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;
    }

}

Classes

Title Deprecated Summary
Reflection Provides helper methods for reflection.

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