private function XmlDumper::addService in Service Container 7
Same name and namespace in other branches
- 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php \Symfony\Component\DependencyInjection\Dumper\XmlDumper::addService()
Adds a service.
Parameters
Definition $definition:
string $id:
\DOMElement $parent:
2 calls to XmlDumper::addService()
- XmlDumper::addServices in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Dumper/ XmlDumper.php - Adds services.
- XmlDumper::convertParameters in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Dumper/ XmlDumper.php - Converts parameters.
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Dumper/ XmlDumper.php, line 111
Class
- XmlDumper
- XmlDumper dumps a service container as an XML string.
Namespace
Symfony\Component\DependencyInjection\DumperCode
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(false)) {
$service
->setAttribute('factory-method', $definition
->getFactoryMethod(false));
}
if ($definition
->getFactoryClass(false)) {
$service
->setAttribute('factory-class', $definition
->getFactoryClass(false));
}
if ($definition
->getFactoryService(false)) {
$service
->setAttribute('factory-service', $definition
->getFactoryService(false));
}
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(false)) {
$service
->setAttribute('synchronized', 'true');
}
if ($definition
->isLazy()) {
$service
->setAttribute('lazy', 'true');
}
if (null !== ($decorated = $definition
->getDecoratedService())) {
list($decorated, $renamedId) = $decorated;
$service
->setAttribute('decorates', $decorated);
if (null !== $renamedId) {
$service
->setAttribute('decoration-inner-name', $renamedId);
}
}
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
->getFactory()) {
$factory = $this->document
->createElement('factory');
if (is_array($callable) && $callable[0] instanceof Definition) {
$this
->addService($callable[0], null, $factory);
$factory
->setAttribute('method', $callable[1]);
}
elseif (is_array($callable)) {
$factory
->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
$factory
->setAttribute('method', $callable[1]);
}
else {
$factory
->setAttribute('function', $callable);
}
$service
->appendChild($factory);
}
if ($callable = $definition
->getConfigurator()) {
$configurator = $this->document
->createElement('configurator');
if (is_array($callable) && $callable[0] instanceof Definition) {
$this
->addService($callable[0], null, $configurator);
$configurator
->setAttribute('method', $callable[1]);
}
elseif (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);
}