Adds synchronizer methods.
string $id A service identifier:
Definition $definition A Definition instance:
private function addServiceSynchronizer($id, Definition $definition) {
if (!$definition
->isSynchronized()) {
return;
}
$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;
}
$name = Container::camelize($id);
return <<<EOF
/**
* Updates the '{<span class="php-variable">$id</span>}' service.
*/
protected function synchronize{<span class="php-variable">$name</span>}Service()
{
{<span class="php-variable">$code</span>} }
EOF;
}