You are here

private function YamlDumper::addService in Service Container 7

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

Adds a service.

Parameters

string $id:

Definition $definition:

Return value

string

1 call to YamlDumper::addService()
YamlDumper::addServices in modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
Adds services.

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php, line 64

Class

YamlDumper
YamlDumper dumps a service container as a YAML string.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function addService($id, $definition) {
  $code = "    {$id}:\n";
  if ($definition
    ->getClass()) {
    $code .= sprintf("        class: %s\n", $definition
      ->getClass());
  }
  if (!$definition
    ->isPublic()) {
    $code .= "        public: false\n";
  }
  $tagsCode = '';
  foreach ($definition
    ->getTags() as $name => $tags) {
    foreach ($tags as $attributes) {
      $att = array();
      foreach ($attributes as $key => $value) {
        $att[] = sprintf('%s: %s', $this->dumper
          ->dump($key), $this->dumper
          ->dump($value));
      }
      $att = $att ? ', ' . implode(', ', $att) : '';
      $tagsCode .= sprintf("            - { name: %s%s }\n", $this->dumper
        ->dump($name), $att);
    }
  }
  if ($tagsCode) {
    $code .= "        tags:\n" . $tagsCode;
  }
  if ($definition
    ->getFile()) {
    $code .= sprintf("        file: %s\n", $definition
      ->getFile());
  }
  if ($definition
    ->isSynthetic()) {
    $code .= sprintf("        synthetic: true\n");
  }
  if ($definition
    ->isSynchronized(false)) {
    $code .= sprintf("        synchronized: true\n");
  }
  if ($definition
    ->getFactoryClass(false)) {
    $code .= sprintf("        factory_class: %s\n", $definition
      ->getFactoryClass(false));
  }
  if ($definition
    ->isLazy()) {
    $code .= sprintf("        lazy: true\n");
  }
  if ($definition
    ->getFactoryMethod(false)) {
    $code .= sprintf("        factory_method: %s\n", $definition
      ->getFactoryMethod(false));
  }
  if ($definition
    ->getFactoryService(false)) {
    $code .= sprintf("        factory_service: %s\n", $definition
      ->getFactoryService(false));
  }
  if ($definition
    ->getArguments()) {
    $code .= sprintf("        arguments: %s\n", $this->dumper
      ->dump($this
      ->dumpValue($definition
      ->getArguments()), 0));
  }
  if ($definition
    ->getProperties()) {
    $code .= sprintf("        properties: %s\n", $this->dumper
      ->dump($this
      ->dumpValue($definition
      ->getProperties()), 0));
  }
  if ($definition
    ->getMethodCalls()) {
    $code .= sprintf("        calls:\n%s\n", $this->dumper
      ->dump($this
      ->dumpValue($definition
      ->getMethodCalls()), 1, 12));
  }
  if (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition
    ->getScope())) {
    $code .= sprintf("        scope: %s\n", $scope);
  }
  if (null !== ($decorated = $definition
    ->getDecoratedService())) {
    list($decorated, $renamedId) = $decorated;
    $code .= sprintf("        decorates: %s\n", $decorated);
    if (null !== $renamedId) {
      $code .= sprintf("        decoration_inner_name: %s\n", $renamedId);
    }
  }
  if ($callable = $definition
    ->getFactory()) {
    $code .= sprintf("        factory: %s\n", $this->dumper
      ->dump($this
      ->dumpCallable($callable), 0));
  }
  if ($callable = $definition
    ->getConfigurator()) {
    $code .= sprintf("        configurator: %s\n", $this->dumper
      ->dump($this
      ->dumpCallable($callable), 0));
  }
  return $code;
}