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

Breadcrumb

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

function PhpDumper::exportParameters

Throws

InvalidArgumentException

1 call to PhpDumper::exportParameters()
PhpDumper::addDefaultParametersMethod in vendor/symfony/dependency-injection/Dumper/PhpDumper.php

File

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

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function exportParameters(array $parameters, string $path = '', int $indent = 12, bool &$hasEnum = false) : string {
    $php = [];
    foreach ($parameters as $key => $value) {
        if (\is_array($value)) {
            $value = $this->exportParameters($value, $path . '/' . $key, $indent + 4, $hasEnum);
        }
        elseif ($value instanceof ArgumentInterface) {
            throw new InvalidArgumentException(\sprintf('You cannot dump a container with parameters that contain special arguments. "%s" found in "%s".', get_debug_type($value), $path . '/' . $key));
        }
        elseif ($value instanceof Variable) {
            throw new InvalidArgumentException(\sprintf('You cannot dump a container with parameters that contain variable references. Variable "%s" found in "%s".', $value, $path . '/' . $key));
        }
        elseif ($value instanceof Definition) {
            throw new InvalidArgumentException(\sprintf('You cannot dump a container with parameters that contain service definitions. Definition for "%s" found in "%s".', $value->getClass(), $path . '/' . $key));
        }
        elseif ($value instanceof Reference) {
            throw new InvalidArgumentException(\sprintf('You cannot dump a container with parameters that contain references to other services (reference to service "%s" found in "%s").', $value, $path . '/' . $key));
        }
        elseif ($value instanceof Expression) {
            throw new InvalidArgumentException(\sprintf('You cannot dump a container with parameters that contain expressions. Expression "%s" found in "%s".', $value, $path . '/' . $key));
        }
        elseif ($value instanceof \UnitEnum) {
            $hasEnum = true;
            $value = \sprintf('\\%s::%s', $value::class, $value->name);
        }
        else {
            $value = $this->export($value);
        }
        $php[] = \sprintf('%s%s => %s,', str_repeat(' ', $indent), $this->export($key), $value);
    }
    return \sprintf("[\n%s\n%s]", implode("\n", $php), str_repeat(' ', $indent - 4));
}
RSS feed
Powered by Drupal