Adds a service.
Definition $definition:
string $id:
\DOMElement $parent:
private function addService($definition, $id, \DOMElement $parent) {
$service = $this->document
->createElement('service');
if (null !== $id) {
$service
->setAttribute('id', $id);
}
if ($definition
->getClass()) {
$service
->setAttribute('class', $definition
->getClass());
}
if ($definition
->getFactoryMethod()) {
$service
->setAttribute('factory-method', $definition
->getFactoryMethod());
}
if ($definition
->getFactoryService()) {
$service
->setAttribute('factory-service', $definition
->getFactoryService());
}
if (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition
->getScope())) {
$service
->setAttribute('scope', $scope);
}
if (!$definition
->isPublic()) {
$service
->setAttribute('public', 'false');
}
if ($definition
->isSynthetic()) {
$service
->setAttribute('synthetic', 'true');
}
if ($definition
->isSynchronized()) {
$service
->setAttribute('synchronized', 'true');
}
if ($definition
->isLazy()) {
$service
->setAttribute('lazy', 'true');
}
foreach ($definition
->getTags() as $name => $tags) {
foreach ($tags as $attributes) {
$tag = $this->document
->createElement('tag');
$tag
->setAttribute('name', $name);
foreach ($attributes as $key => $value) {
$tag
->setAttribute($key, $value);
}
$service
->appendChild($tag);
}
}
if ($definition
->getFile()) {
$file = $this->document
->createElement('file');
$file
->appendChild($this->document
->createTextNode($definition
->getFile()));
$service
->appendChild($file);
}
if ($parameters = $definition
->getArguments()) {
$this
->convertParameters($parameters, 'argument', $service);
}
if ($parameters = $definition
->getProperties()) {
$this
->convertParameters($parameters, 'property', $service, 'name');
}
$this
->addMethodCalls($definition
->getMethodCalls(), $service);
if ($callable = $definition
->getConfigurator()) {
$configurator = $this->document
->createElement('configurator');
if (is_array($callable)) {
$configurator
->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
$configurator
->setAttribute('method', $callable[1]);
}
else {
$configurator
->setAttribute('function', $callable);
}
$service
->appendChild($configurator);
}
$parent
->appendChild($service);
}