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

Breadcrumb

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

function ProxyHelper::exportSignature

2 calls to ProxyHelper::exportSignature()
LazyClosure::getCode in vendor/symfony/dependency-injection/Argument/LazyClosure.php
ProxyHelper::generateLazyProxy in vendor/symfony/var-exporter/ProxyHelper.php
Helps generate lazy-loading virtual proxies.

File

vendor/symfony/var-exporter/ProxyHelper.php, line 241

Class

ProxyHelper
@author Nicolas Grekas <p@tchwork.com>

Namespace

Symfony\Component\VarExporter

Code

public static function exportSignature(\ReflectionFunctionAbstract $function, bool $withParameterTypes = true, ?string &$args = null) : string {
    $byRefIndex = 0;
    $args = '';
    $param = null;
    $parameters = [];
    $namespace = $function instanceof \ReflectionMethod ? $function->class : $function->getNamespaceName() . '\\';
    $namespace = substr($namespace, 0, strrpos($namespace, '\\') ?: 0);
    foreach ($function->getParameters() as $param) {
        $parameters[] = ($param->getAttributes(\SensitiveParameter::class) ? '#[\\SensitiveParameter] ' : '') . ($withParameterTypes && $param->hasType() ? self::exportType($param) . ' ' : '') . ($param->isPassedByReference() ? '&' : '') . ($param->isVariadic() ? '...' : '') . '$' . $param->name . ($param->isOptional() && !$param->isVariadic() ? ' = ' . self::exportDefault($param, $namespace) : '');
        if ($param->isPassedByReference()) {
            $byRefIndex = 1 + $param->getPosition();
        }
        $args .= ($param->isVariadic() ? '...$' : '$') . $param->name . ', ';
    }
    if (!$param || !$byRefIndex) {
        $args = '...\\func_get_args()';
    }
    elseif ($param->isVariadic()) {
        $args = substr($args, 0, -2);
    }
    else {
        $args = explode(', ', $args, 1 + $byRefIndex);
        $args[$byRefIndex] = \sprintf('...\\array_slice(\\func_get_args(), %d)', $byRefIndex);
        $args = implode(', ', $args);
    }
    $signature = 'function ' . ($function->returnsReference() ? '&' : '') . ($function->isClosure() ? '' : $function->name) . '(' . implode(', ', $parameters) . ')';
    if ($function instanceof \ReflectionMethod) {
        $signature = ($function->isPublic() ? 'public ' : ($function->isProtected() ? 'protected ' : 'private ')) . ($function->isStatic() ? 'static ' : '') . $signature;
    }
    if ($function->hasReturnType()) {
        $signature .= ': ' . self::exportType($function);
    }
    static $getPrototype;
    $getPrototype ??= (new \ReflectionMethod(\ReflectionMethod::class, 'getPrototype'))->invoke(...);
    while ($function) {
        if ($function->hasTentativeReturnType()) {
            return '#[\\ReturnTypeWillChange] ' . $signature;
        }
        try {
            $function = $function instanceof \ReflectionMethod && $function->isAbstract() ? false : $getPrototype($function);
        } catch (\ReflectionException) {
            break;
        }
    }
    return $signature;
}
RSS feed
Powered by Drupal