private function PhpDumper::wrapServiceConditionals

Wraps the service conditionals.

Parameters

string $value:

string $code:

Return value

string

1 call to PhpDumper::wrapServiceConditionals()
PhpDumper::addServiceMethodCalls in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Adds method calls to a service definition.

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php, line 860

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function wrapServiceConditionals($value, $code) {
  if (!($services = ContainerBuilder::getServiceConditionals($value))) {
    return $code;
  }
  $conditions = array();
  foreach ($services as $service) {
    $conditions[] = sprintf("\$this->has('%s')", $service);
  }

  // re-indent the wrapped code
  $code = implode("\n", array_map(function ($line) {
    return $line ? '    ' . $line : $line;
  }, explode("\n", $code)));
  return sprintf("        if (%s) {\n%s        }\n", implode(' && ', $conditions), $code);
}