diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php
index 813c603372..55fc875889 100755
--- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php
+++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php
@@ -408,6 +408,7 @@ class DoctrineExtension extends AbstractDoctrineExtension
new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name']))
);
$ormEmDef = new Definition('%doctrine.orm.entity_manager_class%', $ormEmArgs);
+ $ormEmDef->setFactoryClass('%doctrine.orm.entity_manager_class%');
$ormEmDef->setFactoryMethod('create');
$ormEmDef->addTag('doctrine.orm.entity_manager');
$container->setDefinition($entityManagerService, $ormEmDef);
diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
index bd9fbefc9e..46a4e40467 100755
--- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
+++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
@@ -157,6 +157,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.orm.entity_manager', $definition->getTags());
@@ -198,6 +199,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.orm.entity_manager', $definition->getTags());
@@ -239,6 +241,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.orm.entity_manager', $definition->getTags());
@@ -279,6 +282,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.orm.entity_manager', $definition->getTags());
@@ -313,6 +317,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.orm.dm1_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.orm.entity_manager', $definition->getTags());
@@ -334,6 +339,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.orm.dm2_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.orm.entity_manager', $definition->getTags());
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php
index 880005e174..0eb11749b3 100644
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php
+++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php
@@ -165,6 +165,7 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
new Reference($eventManagerId),
);
$odmDmDef = new Definition('%doctrine.odm.mongodb.document_manager_class%', $odmDmArgs);
+ $odmDmDef->setFactoryClass('%doctrine.odm.mongodb.document_manager_class%');
$odmDmDef->setFactoryMethod('create');
$odmDmDef->addTag('doctrine.odm.mongodb.document_manager');
$container->setDefinition(sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManager['name']), $odmDmDef);
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php
index b500b08e06..dee13dabc7 100644
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php
+++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php
@@ -65,6 +65,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
$this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
@@ -92,6 +93,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
$this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
@@ -126,6 +128,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
$this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
@@ -154,6 +157,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
$this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
@@ -184,6 +188,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.odm.mongodb.dm1_document_manager');
$this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
@@ -199,6 +204,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase
$definition = $container->getDefinition('doctrine.odm.mongodb.dm2_document_manager');
$this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
+ $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
$this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php
index 4b93f9ac0f..dc2654e772 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php
@@ -41,7 +41,7 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
// non-synthetic, non-abstract service has class
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
- if ($definition->getFactoryService()) {
+ if ($definition->getFactoryClass() || $definition->getFactoryService()) {
throw new \RuntimeException(sprintf(
'Please add the class to service "%s" even if it is constructed '
.'by a factory since we might need to add method calls based on '
diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
index a0cc8213f5..d3961ca574 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
@@ -49,8 +49,9 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
$def->setClass($parentDef->getClass());
$def->setArguments($parentDef->getArguments());
$def->setMethodCalls($parentDef->getMethodCalls());
- $def->setFactoryService($parentDef->getFactoryService());
+ $def->setFactoryClass($parentDef->getFactoryClass());
$def->setFactoryMethod($parentDef->getFactoryMethod());
+ $def->setFactoryService($parentDef->getFactoryService());
$def->setConfigurator($parentDef->getConfigurator());
$def->setFile($parentDef->getFile());
$def->setPublic($parentDef->isPublic());
@@ -60,6 +61,9 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
if (isset($changes['class'])) {
$def->setClass($definition->getClass());
}
+ if (isset($changes['factory_class'])) {
+ $def->setFactoryClass($definition->getFactoryClass());
+ }
if (isset($changes['factory_method'])) {
$def->setFactoryMethod($definition->getFactoryMethod());
}
diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInterfaceInjectorsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInterfaceInjectorsPass.php
index 1373665cd0..2fecee1b66 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInterfaceInjectorsPass.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInterfaceInjectorsPass.php
@@ -32,7 +32,7 @@ class ResolveInterfaceInjectorsPass implements CompilerPassInterface
$loaded = false;
foreach ($container->getInterfaceInjectors() as $injector) {
- if (null !== $definition->getFactoryService()) {
+ if (null !== $definition->getFactoryClass() || null !== $definition->getFactoryService()) {
continue;
}
diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
index 8bf948e67b..008ef416c2 100644
--- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
@@ -695,10 +695,12 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
$arguments = $this->resolveServices($this->getParameterBag()->resolveValue($definition->getArguments()));
if (null !== $definition->getFactoryMethod()) {
- if (null !== $definition->getFactoryService()) {
+ if (null !== $definition->getFactoryClass()) {
+ $factory = $this->getParameterBag()->resolveValue($definition->getFactoryClass());
+ } elseif (null !== $definition->getFactoryService()) {
$factory = $this->get($this->getParameterBag()->resolveValue($definition->getFactoryService()));
} else {
- $factory = $this->getParameterBag()->resolveValue($definition->getClass());
+ throw new \RuntimeException('Cannot create service from factory method without a factory service or factory class.');
}
$service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments);
diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php
index fa70eb6d14..e3d58cb6f2 100644
--- a/src/Symfony/Component/DependencyInjection/Definition.php
+++ b/src/Symfony/Component/DependencyInjection/Definition.php
@@ -20,6 +20,7 @@ class Definition
{
protected $class;
protected $file;
+ protected $factoryClass;
protected $factoryMethod;
protected $factoryService;
protected $scope;
@@ -50,15 +51,40 @@ class Definition
}
/**
- * Sets the factory method able to create an instance of this class.
+ * Sets the name of the class that acts as a factory using the factory method,
+ * which will be invoked statically.
*
- * @param string $method The method name
+ * @param string $factoryClass The factory class name
*
* @return Definition The current instance
*/
- public function setFactoryMethod($method)
+ public function setFactoryClass($factoryClass)
{
- $this->factoryMethod = $method;
+ $this->factoryClass = $factoryClass;
+
+ return $this;
+ }
+
+ /**
+ * Gets the factory class.
+ *
+ * @return string The factory class name
+ */
+ public function getFactoryClass()
+ {
+ return $this->factoryClass;
+ }
+
+ /**
+ * Sets the factory method able to create an instance of this class.
+ *
+ * @param string $factoryMethod The factory method name
+ *
+ * @return Definition The current instance
+ */
+ public function setFactoryMethod($factoryMethod)
+ {
+ $this->factoryMethod = $factoryMethod;
return $this;
}
@@ -74,7 +100,7 @@ class Definition
}
/**
- * Sets the name of the service that acts as a factory using the constructor method.
+ * Sets the name of the service that acts as a factory using the factory method.
*
* @param string $factoryService The factory service id
*
diff --git a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php
index cde424c50b..e74a1bf7e3 100644
--- a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php
+++ b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php
@@ -37,11 +37,11 @@ class DefinitionDecorator extends Definition
return parent::setClass($class);
}
- public function setFactoryService($service)
+ public function setFactoryClass($class)
{
- $this->changes['factory_service'] = true;
+ $this->changes['factory_class'] = true;
- return parent::setFactoryService($service);
+ return parent::setFactoryClass($class);
}
public function setFactoryMethod($method)
@@ -51,6 +51,13 @@ class DefinitionDecorator extends Definition
return parent::setFactoryMethod($method);
}
+ public function setFactoryService($service)
+ {
+ $this->changes['factory_service'] = true;
+
+ return parent::setFactoryService($service);
+ }
+
public function setConfigurator($callable)
{
$this->changes['configurator'] = true;
diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
index 57e984f408..7829b10b1a 100644
--- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
+++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
@@ -230,10 +230,12 @@ EOF;
}
if (null !== $sDefinition->getFactoryMethod()) {
- if (null !== $sDefinition->getFactoryService()) {
+ if (null !== $sDefinition->getFactoryClass()) {
+ $code .= sprintf(" \$%s = call_user_func(array(%s, '%s')%s);\n", $name, $this->dumpValue($sDefinition->getFactoryClass()), $sDefinition->getFactoryMethod(), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
+ } elseif (null !== $sDefinition->getFactoryService()) {
$code .= sprintf(" \$%s = %s->%s(%s);\n", $name, $this->getServiceCall($sDefinition->getFactoryService()), $sDefinition->getFactoryMethod(), implode(', ', $arguments));
} else {
- $code .= sprintf(" \$%s = call_user_func(array(%s, '%s')%s);\n", $name, $class, $sDefinition->getFactoryMethod(), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
+ throw new \RuntimeException('Factory service or factory class must be defined in service definition for '.$id);
}
} elseif (false !== strpos($class, '$')) {
$code .= sprintf(" \$class = %s;\n \$%s = new \$class(%s);\n", $class, $name, implode(', ', $arguments));
@@ -294,10 +296,12 @@ EOF;
}
if (null !== $definition->getFactoryMethod()) {
- if (null !== $definition->getFactoryService()) {
+ if (null !== $definition->getFactoryClass()) {
+ $code = sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass()), $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : '');
+ } elseif (null !== $definition->getFactoryService()) {
$code = sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService()), $definition->getFactoryMethod(), implode(', ', $arguments));
} else {
- $code = sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $class, $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : '');
+ throw new \RuntimeException('Factory method requires a factory service or factory class in service definition for '.$id);
}
} elseif (false !== strpos($class, '$')) {
$code = sprintf(" \$class = %s;\n $return{$instantiation}new \$class(%s);\n", $class, implode(', ', $arguments));
@@ -404,8 +408,10 @@ EOF;
$return = '';
if ($definition->isSynthetic()) {
$return = sprintf('@throws \RuntimeException always since this service is expected to be injected dynamically');
- } else if ($class = $definition->getClass()) {
+ } elseif ($class = $definition->getClass()) {
$return = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'Object' : $class, $class);
+ } elseif ($definition->getFactoryClass()) {
+ $return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
} elseif ($definition->getFactoryService()) {
$return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod());
}
@@ -821,10 +827,12 @@ EOF;
}
if (null !== $value->getFactoryMethod()) {
- if (null !== $value->getFactoryService()) {
+ if (null !== $value->getFactoryClass()) {
+ return sprintf("call_user_func(array(%s, '%s')%s)", $this->dumpValue($value->getFactoryClass()), $value->getFactoryMethod(), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
+ } elseif (null !== $value->getFactoryService()) {
return sprintf("%s->%s(%s)", $this->getServiceCall($value->getFactoryService()), $value->getFactoryMethod(), implode(', ', $arguments));
} else {
- return sprintf("call_user_func(array(%s, '%s')%s)", $class, $value->getFactoryMethod(), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
+ throw new \RuntimeException('Cannot dump definitions which have factory method without factory service or factory class.');
}
}
diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
index ec0a10625e..ec39573f83 100644
--- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
+++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
@@ -143,7 +143,7 @@ class XmlFileLoader extends FileLoader
$definition = new Definition();
}
- foreach (array('class', 'scope', 'public', 'factory-method', 'factory-service', 'synthetic', 'abstract') as $key) {
+ foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'abstract') as $key) {
if (isset($service[$key])) {
$method = 'set'.str_replace('-', '', $key);
$definition->$method((string) $service->getAttributeAsPhp($key));
diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
index 65def0455f..926a274a00 100644
--- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
@@ -165,6 +165,10 @@ class YamlFileLoader extends FileLoader
$definition->setAbstract($service['abstract']);
}
+ if (isset($service['factory_class'])) {
+ $definition->setFactoryClass($service['factory_class']);
+ }
+
if (isset($service['factory_method'])) {
$definition->setFactoryMethod($service['factory_method']);
}
diff --git a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
index a6ccf726ee..35a8a684c9 100644
--- a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
+++ b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
@@ -105,6 +105,7 @@
+
diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckDefinitionValidityPassTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckDefinitionValidityPassTest.php
new file mode 100644
index 0000000000..73d46bbc38
--- /dev/null
+++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckDefinitionValidityPassTest.php
@@ -0,0 +1,61 @@
+register('a')->setSynthetic(true)->setPublic(false);
+
+ $this->process($container);
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ */
+ public function testProcessDetectsSyntheticPrototypeDefinitions()
+ {
+ $container = new ContainerBuilder();
+ $container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
+
+ $this->process($container);
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ */
+ public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
+ {
+ $container = new ContainerBuilder();
+ $container->register('a')->setSynthetic(false)->setAbstract(false);
+
+ $this->process($container);
+ }
+
+ public function testProcess()
+ {
+ $container = new ContainerBuilder();
+ $container->register('a', 'class');
+ $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
+ $container->register('c', 'class')->setAbstract(true);
+ $container->register('d', 'class')->setSynthetic(true);
+
+ $this->process($container);
+ }
+
+ protected function process(ContainerBuilder $container)
+ {
+ $pass = new CheckDefinitionValidityPass();
+ $pass->process($container);
+ }
+}
\ No newline at end of file
diff --git a/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php
index b9d68f072e..4a14e40664 100644
--- a/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php
+++ b/tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php
@@ -247,7 +247,7 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
{
$builder = new ContainerBuilder();
$builder->register('bar', 'stdClass');
- $builder->register('foo1', 'FooClass')->setFactoryMethod('getInstance')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
+ $builder->register('foo1', 'FooClass')->setFactoryClass('FooClass')->setFactoryMethod('getInstance')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
$builder->setParameter('value', 'bar');
$this->assertTrue($builder->get('foo1')->called, '->createService() calls the factory method to create the service instance');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar')), $builder->get('foo1')->arguments, '->createService() passes the arguments to the factory method');
diff --git a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php
index ff80fba5d8..6c74adfe4a 100644
--- a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php
+++ b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php
@@ -34,8 +34,9 @@ class DefinitionDecoratorTest extends \PHPUnit_Framework_TestCase
{
return array(
array('class', 'class'),
- array('factoryService', 'factory_service'),
+ array('factoryClass', 'factory_class'),
array('factoryMethod', 'factory_method'),
+ array('factoryService', 'factory_service'),
array('configurator', 'configurator'),
array('file', 'file'),
);
diff --git a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php
index 41ded4f06b..5a6097dcd3 100644
--- a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php
+++ b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php
@@ -27,13 +27,18 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
}
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setFactoryMethod
- * @covers Symfony\Component\DependencyInjection\Definition::getFactoryMethod
- */
- public function testSetGetConstructor()
+ public function testSetGetFactoryClass()
{
$def = new Definition('stdClass');
+ $this->assertNull($def->getFactoryClass());
+ $this->assertSame($def, $def->setFactoryClass('stdClass2'), "->setFactoryClass() implements a fluent interface.");
+ $this->assertEquals('stdClass2', $def->getFactoryClass(), "->getFactoryClass() returns current class to construct this service.");
+ }
+
+ public function testSetGetFactoryMethod()
+ {
+ $def = new Definition('stdClass');
+ $this->assertNull($def->getFactoryMethod());
$this->assertSame($def, $def->setFactoryMethod('foo'), '->setFactoryMethod() implements a fluent interface');
$this->assertEquals('foo', $def->getFactoryMethod(), '->getFactoryMethod() returns the factory method name');
}
@@ -42,8 +47,8 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
{
$def = new Definition('stdClass');
$this->assertNull($def->getFactoryService());
- $this->assertSame($def, $def->setFactoryService('stdClass2'), "->setFactoryService() implements a fluent interface.");
- $this->assertEquals('stdClass2', $def->getFactoryService(), "->getFactoryService() returns current service to construct this service.");
+ $this->assertSame($def, $def->setFactoryService('foo.bar'), "->setFactoryService() implements a fluent interface.");
+ $this->assertEquals('foo.bar', $def->getFactoryService(), "->getFactoryService() returns current service to construct this service.");
}
/**
diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php
index 46c9dbb909..03e4c9db92 100644
--- a/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php
+++ b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php
@@ -12,6 +12,7 @@ $container->
register('foo', 'FooClass')->
addTag('foo', array('foo' => 'foo'))->
addTag('foo', array('bar' => 'bar'))->
+ setFactoryClass('FooClass')->
setFactoryMethod('getInstance')->
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, new Reference('service_container')))->
setScope('prototype')->
@@ -27,6 +28,7 @@ $container->
;
$container->
register('foo.baz', '%baz_class%')->
+ setFactoryClass('%baz_class%')->
setFactoryMethod('getInstance')->
setConfigurator(array('%baz_class%', 'configureStatic1'))
;