Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ReflectionCaster.php

function ReflectionCaster::getSignature

3 calls to ReflectionCaster::getSignature()
ClassStub::__construct in vendor/symfony/var-dumper/Caster/ClassStub.php
ExceptionCaster::extractSource in vendor/symfony/var-dumper/Caster/ExceptionCaster.php
ReflectionCaster::castClosure in vendor/symfony/var-dumper/Caster/ReflectionCaster.php

File

vendor/symfony/var-dumper/Caster/ReflectionCaster.php, line 359

Class

ReflectionCaster
Casts Reflector related classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

public static function getSignature(array $a) : string {
    $prefix = Caster::PREFIX_VIRTUAL;
    $signature = '';
    if (isset($a[$prefix . 'parameters'])) {
        foreach ($a[$prefix . 'parameters']->value as $k => $param) {
            $signature .= ', ';
            if ($type = $param->getType()) {
                if (!$type instanceof \ReflectionNamedType) {
                    $signature .= $type . ' ';
                }
                else {
                    if ($param->allowsNull() && !\in_array($type->getName(), [
                        'mixed',
                        'null',
                    ], true)) {
                        $signature .= '?';
                    }
                    $signature .= substr(strrchr('\\' . $type->getName(), '\\'), 1) . ' ';
                }
            }
            $signature .= $k;
            if (!$param->isDefaultValueAvailable()) {
                continue;
            }
            $v = $param->getDefaultValue();
            $signature .= ' = ';
            if ($param->isDefaultValueConstant()) {
                $signature .= substr(strrchr('\\' . $param->getDefaultValueConstantName(), '\\'), 1);
            }
            elseif (null === $v) {
                $signature .= 'null';
            }
            elseif (\is_array($v)) {
                $signature .= $v ? '[…' . \count($v) . ']' : '[]';
            }
            elseif (\is_string($v)) {
                $signature .= 10 > \strlen($v) && !str_contains($v, '\\') ? "'{$v}'" : "'…" . \strlen($v) . "'";
            }
            elseif (\is_bool($v)) {
                $signature .= $v ? 'true' : 'false';
            }
            elseif (\is_object($v)) {
                $signature .= 'new ' . substr(strrchr('\\' . get_debug_type($v), '\\'), 1);
            }
            else {
                $signature .= $v;
            }
        }
    }
    $signature = (empty($a[$prefix . 'returnsReference']) ? '' : '&') . '(' . substr($signature, 2) . ')';
    if (isset($a[$prefix . 'returnType'])) {
        $signature .= ': ' . substr(strrchr('\\' . $a[$prefix . 'returnType'], '\\'), 1);
    }
    return $signature;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal