diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
index c4d0fb3e4cfe..47db04b87133 100644
--- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
+++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
@@ -5,6 +5,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\InterfaceInjector;
/*
@@ -81,10 +82,12 @@ protected function addInterfaceInjectors()
return sprintf(" \n%s \n", $code);
}
- protected function addService($id, $definition)
+ protected function addService($definition, $id = null, $depth = 4)
{
- $code = sprintf(" \n",
- $id,
+ $white = str_repeat(' ', $depth);
+ $code = sprintf("%s\n",
+ $white,
+ (null !== $id ? sprintf(' id="%s"', $id): ''),
$definition->getClass() ? sprintf(' class="%s"', $definition->getClass()) : '',
$definition->getFactoryMethod() ? sprintf(' factory-method="%s"', $definition->getFactoryMethod()) : '',
$definition->getFactoryService() ? sprintf(' factory-service="%s"', $definition->getFactoryService()) : '',
@@ -99,39 +102,39 @@ protected function addService($id, $definition)
}
$att = $att ? ' '.implode(' ', $att) : '';
- $code .= sprintf(" \n", $name, $att);
+ $code .= sprintf("%s \n", $white, $name, $att);
}
}
if ($definition->getFile()) {
- $code .= sprintf(" %s\n", $definition->getFile());
+ $code .= sprintf("%s %s\n", $white, $definition->getFile());
}
if ($definition->getArguments()) {
- $code .= $this->convertParameters($definition->getArguments(), 'argument', 6);
+ $code .= $this->convertParameters($definition->getArguments(), 'argument', $depth + 2);
}
foreach ($definition->getMethodCalls() as $call) {
if (count($call[1])) {
- $code .= sprintf(" \n%s \n", $call[0], $this->convertParameters($call[1], 'argument', 8));
+ $code .= sprintf("%s \n%s%s \n", $white, $call[0], $this->convertParameters($call[1], 'argument', $depth + 4), $white);
} else {
- $code .= sprintf(" \n", $call[0]);
+ $code .= sprintf("%s \n", $white, $call[0]);
}
}
if ($callable = $definition->getConfigurator()) {
if (is_array($callable)) {
if (is_object($callable[0]) && $callable[0] instanceof Reference) {
- $code .= sprintf(" \n", $callable[0], $callable[1]);
+ $code .= sprintf("%s \n", $white, $callable[0], $callable[1]);
} else {
- $code .= sprintf(" \n", $callable[0], $callable[1]);
+ $code .= sprintf("%s \n", $white, $callable[0], $callable[1]);
}
} else {
- $code .= sprintf(" \n", $callable);
+ $code .= sprintf("%s \n", $white, $callable);
}
}
- $code .= " \n";
+ $code .= $white . "\n";
return $code;
}
@@ -152,7 +155,7 @@ protected function addServices()
$code = '';
foreach ($this->container->getDefinitions() as $id => $definition) {
- $code .= $this->addService($id, $definition);
+ $code .= $this->addService($definition, $id);
}
foreach ($this->container->getAliases() as $alias => $id) {
@@ -177,6 +180,9 @@ protected function convertParameters($parameters, $type='parameter', $depth = 2)
if (is_object($value) && $value instanceof Reference) {
$xml .= sprintf("%s<%s%s type=\"service\" id=\"%s\" %s/>\n", $white, $type, $key, (string) $value, $this->getXmlInvalidBehavior($value));
+
+ } else if (is_object($value) && $value instanceof Definition) {
+ $xml .= sprintf("%s<%s%s type=\"service\">\n%s%s%s>\n", $white, $type, $key, $this->addService($value, null, $depth + 2), $white, $type);
} else {
if (in_array($value, array('null', 'true', 'false'), true)) {
$attributes = ' type="string"';
diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/XmlDumperTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/XmlDumperTest.php
index 94286925f1b0..c31753da0b75 100644
--- a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/XmlDumperTest.php
+++ b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/XmlDumperTest.php
@@ -100,4 +100,29 @@ public function testInterfaceInjectors()
", $classBody);
}
+
+ public function testDumpAnonymousServices()
+ {
+ include self::$fixturesPath.'/containers/container11.php';
+ $dumper = new XmlDumper($container);
+ $this->assertEquals("
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+", $dumper->dump());
+ }
}
diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container11.php b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container11.php
new file mode 100644
index 000000000000..07900977abe4
--- /dev/null
+++ b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container11.php
@@ -0,0 +1,12 @@
+
+ register('foo', 'FooClass')->
+ addArgument(new Definition('BarClass', array(new Definition('BazClass'))))
+;
+
+return $container;