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

Breadcrumb

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

function PhpDumper::dumpLiteralClass

Dumps a string to a literal (aka PHP Code) class value.

Throws

RuntimeException

2 calls to PhpDumper::dumpLiteralClass()
PhpDumper::addNewInstance in vendor/symfony/dependency-injection/Dumper/PhpDumper.php
PhpDumper::addServiceConfigurator in vendor/symfony/dependency-injection/Dumper/PhpDumper.php

File

vendor/symfony/dependency-injection/Dumper/PhpDumper.php, line 2000

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function dumpLiteralClass(string $class) : string {
    if (str_contains($class, '$')) {
        return \sprintf('${($_ = %s) && false ?: "_"}', $class);
    }
    if (!str_starts_with($class, "'") || !preg_match('/^\'(?:\\\\{2})?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\{2}[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*\'$/', $class)) {
        throw new RuntimeException(\sprintf('Cannot dump definition because of invalid class name (%s).', $class ?: 'n/a'));
    }
    $class = substr(str_replace('\\\\', '\\', $class), 1, -1);
    return str_starts_with($class, '\\') ? $class : '\\' . $class;
}
RSS feed
Powered by Drupal