You are here

private function PhpDumper::exportParameters in Service Container 7

Same name and namespace in other branches
  1. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php \Symfony\Component\DependencyInjection\Dumper\PhpDumper::exportParameters()

Exports parameters.

Parameters

array $parameters:

string $path:

int $indent:

Return value

string

Throws

InvalidArgumentException

1 call to PhpDumper::exportParameters()
PhpDumper::addDefaultParametersMethod in modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Adds default parameters method.

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php, line 1089

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function exportParameters($parameters, $path = '', $indent = 12) {
  $php = array();
  foreach ($parameters as $key => $value) {
    if (is_array($value)) {
      $value = $this
        ->exportParameters($value, $path . '/' . $key, $indent + 4);
    }
    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));
    }
    else {
      $value = $this
        ->export($value);
    }
    $php[] = sprintf('%s%s => %s,', str_repeat(' ', $indent), var_export($key, true), $value);
  }
  return sprintf("array(\n%s\n%s)", implode("\n", $php), str_repeat(' ', $indent - 4));
}