You are here

private function PhpDumper::addServiceSynchronizer in Service Container 7.2

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

Adds synchronizer methods.

Parameters

string $id A service identifier:

Definition $definition A Definition instance:

Return value

string|null

Deprecated

since version 2.7, will be removed in 3.0.

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

File

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

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function addServiceSynchronizer($id, Definition $definition) {
  if (!$definition
    ->isSynchronized(false)) {
    return;
  }
  if ('request' !== $id) {
    trigger_error('Synchronized services were deprecated in version 2.7 and won\'t work anymore in 3.0.', E_USER_DEPRECATED);
  }
  $code = '';
  foreach ($this->container
    ->getDefinitions() as $definitionId => $definition) {
    foreach ($definition
      ->getMethodCalls() as $call) {
      foreach ($call[1] as $argument) {
        if ($argument instanceof Reference && $id == (string) $argument) {
          $arguments = array();
          foreach ($call[1] as $value) {
            $arguments[] = $this
              ->dumpValue($value);
          }
          $call = $this
            ->wrapServiceConditionals($call[1], sprintf("\$this->get('%s')->%s(%s);", $definitionId, $call[0], implode(', ', $arguments)));
          $code .= <<<EOF
        if (\$this->initialized('{<span class="php-variable">$definitionId</span>}')) {
            {<span class="php-variable">$call</span>}
        }

EOF;
        }
      }
    }
  }
  if (!$code) {
    return;
  }
  return <<<EOF

    /**
     * Updates the '{<span class="php-variable">$id</span>}' service.
     */
    protected function synchronize{<span class="php-variable">$this</span>
  -&gt;<span class="php-function-or-constant function member-of-self">camelize</span>(<span class="php-variable">$id</span>)}Service()
    {
{<span class="php-variable">$code</span>}    }

EOF;
}