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

Breadcrumb

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

function ProxyHelper::exportDefault

1 call to ProxyHelper::exportDefault()
ProxyHelper::exportSignature in vendor/symfony/var-exporter/ProxyHelper.php

File

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

Class

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

Namespace

Symfony\Component\VarExporter

Code

private static function exportDefault(\ReflectionParameter $param, $namespace) : string {
    $default = rtrim(substr(explode('$' . $param->name . ' = ', (string) $param, 2)[1] ?? '', 0, -2));
    if (\in_array($default, [
        '<default>',
        'NULL',
    ], true)) {
        return 'null';
    }
    if (str_ends_with($default, "...'") && preg_match("/^'(?:[^'\\\\]*+(?:\\\\.)*+)*+'\$/", $default)) {
        return VarExporter::export($param->getDefaultValue());
    }
    $regexp = "/(\"(?:[^\"\\\\]*+(?:\\\\.)*+)*+\"|'(?:[^'\\\\]*+(?:\\\\.)*+)*+')/";
    $parts = preg_split($regexp, $default, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
    $regexp = '/([\\[\\( ]|^)([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*+(?:\\\\[a-zA-Z0-9_\\x7f-\\xff]++)*+)(\\(?)(?!: )/';
    $callback = false !== strpbrk($default, "\\:('") && ($class = $param->getDeclaringClass()) ? fn($m) => $m[1] . match ($m[2]) {    'new', 'false', 'true', 'null' => $m[2],
        'NULL' => 'null',
        'self' => '\\' . $class->name,
        'namespace\\parent', 'parent' => ($parent = $class->getParentClass()) ? '\\' . $parent->name : 'parent',
        default => self::exportSymbol($m[2], '(' !== $m[3], $namespace),
    
    } . $m[3] : fn($m) => $m[1] . match ($m[2]) {    'new', 'false', 'true', 'null', 'self', 'parent' => $m[2],
        'NULL' => 'null',
        default => self::exportSymbol($m[2], '(' !== $m[3], $namespace),
    
    } . $m[3];
    return implode('', array_map(fn($part) => match ($part[0]) {    '"' => $part,
        "'" => false !== strpbrk($part, "\\\x00\r\n") ? '"' . substr(str_replace([
            '$',
            "\x00",
            "\r",
            "\n",
        ], [
            '\\$',
            '\\0',
            '\\r',
            '\\n',
        ], $part), 1, -1) . '"' : $part,
        default => preg_replace_callback($regexp, $callback, $part),
    
    }, $parts));
}
RSS feed
Powered by Drupal