Permalink
Browse files

[DependencyInjection] added a way to automatically update scoped serv…

…ices

A service can now be marked as synchronized; when set, all method calls
involving this service will be called each time this service is set.
When in a scope, methods are also called to restore the previous version of the
service.
  • Loading branch information...
1 parent 469330d commit ec1e7ca6ac7364efecf5cc1ac891089a6d38da49 @fabpot committed Feb 6, 2013
Showing with 366 additions and 24 deletions.
  1. +13 −6 src/Symfony/Component/DependencyInjection/Container.php
  2. +60 −14 src/Symfony/Component/DependencyInjection/ContainerBuilder.php
  3. +30 −0 src/Symfony/Component/DependencyInjection/Definition.php
  4. +57 −2 src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
  5. +9 −0 src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
  6. +8 −0 src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
  7. +1 −1 src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
  8. +4 −0 src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
  9. +1 −0 src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
  10. +47 −0 src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
  11. +13 −1 src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
  12. +9 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php
  13. +3 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot
  14. +5 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php
  15. +40 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php
  16. +40 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php
  17. +1 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml
  18. +6 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml
  19. +4 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml
  20. +9 −0 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml
  21. +3 −0 src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
  22. +3 −0 src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
View
19 src/Symfony/Component/DependencyInjection/Container.php
@@ -206,6 +206,10 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
}
$this->services[$id] = $service;
+
+ if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
+ $this->$method();
+ }
}
/**
@@ -221,7 +225,7 @@ public function has($id)
{
$id = strtolower($id);
- return isset($this->services[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
+ return array_key_exists($id, $this->services) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
}
/**
@@ -247,7 +251,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
{
$id = strtolower($id);
- if (isset($this->services[$id])) {
+ if (array_key_exists($id, $this->services)) {
return $this->services[$id];
}
@@ -263,7 +267,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
} catch (\Exception $e) {
unset($this->loading[$id]);
- if (isset($this->services[$id])) {
+ if (array_key_exists($id, $this->services)) {
unset($this->services[$id]);
}
@@ -289,7 +293,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
*/
public function initialized($id)
{
- return isset($this->services[strtolower($id)]);
+ return array_key_exists(strtolower($id), $this->services);
}
/**
@@ -393,8 +397,11 @@ public function leaveScope($name)
$services = $this->scopeStacks[$name]->pop();
$this->scopedServices += $services;
- array_unshift($services, $this->services);
- $this->services = call_user_func_array('array_merge', $services);
+ foreach ($services as $array) {
+ foreach ($array as $id => $service) {
+ $this->set($id, $service, $name);
+ }
+ }
}
}
View
74 src/Symfony/Component/DependencyInjection/ContainerBuilder.php
@@ -47,6 +47,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
private $definitions = array();
/**
+ * @var Definition[]
+ */
+ private $obsoleteDefinitions = array();
+
+ /**
* @var Alias[]
*/
private $aliases = array();
@@ -351,14 +356,28 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
if ($this->isFrozen()) {
// setting a synthetic service on a frozen container is alright
- if (!isset($this->definitions[$id]) || !$this->definitions[$id]->isSynthetic()) {
+ if (
+ (!isset($this->definitions[$id]) && !isset($this->obsoleteDefinitions[$id]))
+ ||
+ (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())
+ ||
+ (isset($this->obsoleteDefinitions[$id]) && !$this->obsoleteDefinitions[$id]->isSynthetic())
+ ) {
throw new BadMethodCallException(sprintf('Setting service "%s" on a frozen container is not allowed.', $id));
}
}
+ if (isset($this->definitions[$id])) {
+ $this->obsoleteDefinitions[$id] = $this->definitions[$id];
+ }
+
unset($this->definitions[$id], $this->aliases[$id]);
parent::set($id, $service, $scope);
+
+ if (isset($this->obsoleteDefinitions[$id]) && $this->obsoleteDefinitions[$id]->isSynchronized()) {
+ $this->synchronize($id);
+ }
}
/**
@@ -885,19 +904,7 @@ private function createService(Definition $definition, $id)
}
foreach ($definition->getMethodCalls() as $call) {
- $services = self::getServiceConditionals($call[1]);
-
- $ok = true;
- foreach ($services as $s) {
- if (!$this->has($s)) {
- $ok = false;
- break;
- }
- }
-
- if ($ok) {
- call_user_func_array(array($service, $call[0]), $this->resolveServices($parameterBag->resolveValue($call[1])));
- }
+ $this->callMethod($service, $call);
}
$properties = $this->resolveServices($parameterBag->resolveValue($definition->getProperties()));
@@ -999,4 +1006,43 @@ public static function getServiceConditionals($value)
return $services;
}
+
+ /**
+ * Synchronizes a service change.
+ *
+ * This method updates all services that depend on the given
+ * service by calling all methods referencing it.
+ *
+ * @param string $id A service id
+ */
+ private function synchronize($id)
+ {
+ foreach ($this->definitions as $definitionId => $definition) {
+ // only check initialized services
+ if (!$this->initialized($definitionId)) {
+ continue;
+ }
+
+ foreach ($definition->getMethodCalls() as $call) {
+ foreach ($call[1] as $argument) {
+ if ($argument instanceof Reference && $id == (string) $argument) {
+ $this->callMethod($this->get($definitionId), $call);
+ }
+ }
+ }
+ }
+ }
+
+ private function callMethod($service, $call)
+ {
+ $services = self::getServiceConditionals($call[1]);
+
+ foreach ($services as $s) {
+ if (!$this->has($s)) {
+ return;
+ }
+ }
+
+ call_user_func_array(array($service, $call[0]), $this->resolveServices($this->getParameterBag()->resolveValue($call[1])));
+ }
}
View
30 src/Symfony/Component/DependencyInjection/Definition.php
@@ -36,6 +36,7 @@ class Definition
private $public;
private $synthetic;
private $abstract;
+ private $synchronized;
protected $arguments;
@@ -56,6 +57,7 @@ public function __construct($class = null, array $arguments = array())
$this->tags = array();
$this->public = true;
$this->synthetic = false;
+ $this->synchronized = false;
$this->abstract = false;
$this->properties = array();
}
@@ -570,6 +572,34 @@ public function isPublic()
}
/**
+ * Sets the synchronized flag of this service.
+ *
+ * @param Boolean $boolean
+ *
+ * @return Definition The current instance
+ *
+ * @api
+ */
+ public function setSynchronized($boolean)
+ {
+ $this->synchronized = (Boolean) $boolean;
+
+ return $this;
+ }
+
+ /**
+ * Whether this service is synchronized.
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function isSynchronized()
+ {
+ return $this->synchronized;
+ }
+
+ /**
* Sets whether this definition is synthetic, that is not constructed by the
* container, but dynamically injected.
*
View
59 src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
@@ -567,7 +567,7 @@ protected function get{$name}Service()
*/
private function addServices()
{
- $publicServices = $privateServices = $aliasServices = '';
+ $publicServices = $privateServices = $aliasServices = $synchronizers = '';
$definitions = $this->container->getDefinitions();
ksort($definitions);
foreach ($definitions as $id => $definition) {
@@ -576,6 +576,8 @@ private function addServices()
} else {
$privateServices .= $this->addService($id, $definition);
}
+
+ $synchronizers .= $this->addServiceSynchronizer($id, $definition);
}
$aliases = $this->container->getAliases();
@@ -584,7 +586,60 @@ private function addServices()
$aliasServices .= $this->addServiceAlias($alias, $id);
}
- return $publicServices.$aliasServices.$privateServices;
+ return $publicServices.$aliasServices.$synchronizers.$privateServices;
+ }
+
+ /**
+ * Adds synchronizer methods.
+ *
+ * @param string $id A service identifier
+ * @param 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('$definitionId')) {
+ $call
+ }
+
+EOF;
+ }
+ }
+ }
+ }
+
+ if (!$code) {
+ return;
+ }
+
+ $name = Container::camelize($id);
+
+ return <<<EOF
+
+ /**
+ * Updates the '$id' service.
+ */
+ protected function synchronize{$name}Service()
+ {
+$code }
+
+EOF;
}
private function addNewInstance($id, Definition $definition, $return, $instantiation)
View
9 src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
@@ -127,6 +127,12 @@ private function addService($definition, $id, \DOMElement $parent)
if (!$definition->isPublic()) {
$service->setAttribute('public', 'false');
}
+ if ($definition->isSynthetic()) {
+ $service->setAttribute('synthetic', 'true');
+ }
+ if ($definition->isSynchronized()) {
+ $service->setAttribute('synchronized', 'true');
+ }
foreach ($definition->getTags() as $name => $tags) {
foreach ($tags as $attributes) {
@@ -239,6 +245,9 @@ private function convertParameters($parameters, $type, \DOMElement $parent, $key
} elseif ($behaviour == ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
$element->setAttribute('on-invalid', 'ignore');
}
+ if (!$value->isStrict()) {
+ $element->setAttribute('strict', 'false');
+ }
} elseif ($value instanceof Definition) {
$element->setAttribute('type', 'service');
$this->addService($value, null, $element);
View
8 src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
@@ -94,6 +94,14 @@ private function addService($id, $definition)
$code .= sprintf(" file: %s\n", $definition->getFile());
}
+ if ($definition->isSynthetic()) {
+ $code .= sprintf(" synthetic: true\n");
+ }
+
+ if ($definition->isSynchronized()) {
+ $code .= sprintf(" synchronized: true\n");
+ }
+
if ($definition->getFactoryMethod()) {
$code .= sprintf(" factory_method: %s\n", $definition->getFactoryMethod());
}
View
2 src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
@@ -148,7 +148,7 @@ private function parseDefinition($id, $service, $file)
$definition = new Definition();
}
- foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'abstract') as $key) {
+ foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'synchronized', 'abstract') as $key) {
if (isset($service[$key])) {
$method = 'set'.str_replace('-', '', $key);
$definition->$method((string) $service->getAttributeAsPhp($key));
View
4 src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
@@ -153,6 +153,10 @@ private function parseDefinition($id, $service, $file)
$definition->setSynthetic($service['synthetic']);
}
+ if (isset($service['synchronized'])) {
+ $definition->setSynchronized($service['synchronized']);
+ }
+
if (isset($service['public'])) {
$definition->setPublic($service['public']);
}
View
1 src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
@@ -86,6 +86,7 @@
<xsd:attribute name="scope" type="xsd:string" />
<xsd:attribute name="public" type="boolean" />
<xsd:attribute name="synthetic" type="boolean" />
+ <xsd:attribute name="synchronized" type="boolean" />
<xsd:attribute name="abstract" type="boolean" />
<xsd:attribute name="factory-class" type="xsd:string" />
<xsd:attribute name="factory-method" type="xsd:string" />
View
47 src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
@@ -22,6 +22,7 @@
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
+use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\Config\Resource\FileResource;
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@@ -577,6 +578,52 @@ public function testNoExceptionWhenSetSyntheticServiceOnAFrozenContainer()
$this->assertEquals($a, $container->get('a'));
}
+ public function testSetOnSynchronizedService()
+ {
+ $container = new ContainerBuilder();
+ $container->register('baz', 'BazClass')
+ ->setSynchronized(true)
+ ;
+ $container->register('bar', 'BarClass')
+ ->addMethodCall('setBaz', array(new Reference('baz')))
+ ;
+
+ $container->set('baz', $baz = new \BazClass());
+ $this->assertSame($baz, $container->get('bar')->getBaz());
+
+ $container->set('baz', $baz = new \BazClass());
+ $this->assertSame($baz, $container->get('bar')->getBaz());
+ }
+
+ public function testSynchronizedServiceWithScopes()
+ {
+ $container = new ContainerBuilder();
+ $container->addScope(new Scope('foo'));
+ $container->register('baz', 'BazClass')
+ ->setSynthetic(true)
+ ->setSynchronized(true)
+ ->setScope('foo')
+ ;
+ $container->register('bar', 'BarClass')
+ ->addMethodCall('setBaz', array(new Reference('baz', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)))
+ ;
+ $container->compile();
+
+ $container->enterScope('foo');
+ $container->set('baz', $outerBaz = new \BazClass(), 'foo');
+ $this->assertSame($outerBaz, $container->get('bar')->getBaz());
+
+ $container->enterScope('foo');
+ $container->set('baz', $innerBaz = new \BazClass(), 'foo');
+ $this->assertSame($innerBaz, $container->get('bar')->getBaz());
+ $container->leaveScope('foo');
+
+ $this->assertNotSame($innerBaz, $container->get('bar')->getBaz());
+ $this->assertSame($outerBaz, $container->get('bar')->getBaz());
+
+ $container->leaveScope('foo');
+ }
+
/**
* @expectedException BadMethodCallException
*/
View
14 src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
@@ -149,7 +149,19 @@ public function testSetIsSynthetic()
$def = new Definition('stdClass');
$this->assertFalse($def->isSynthetic(), '->isSynthetic() returns false by default');
$this->assertSame($def, $def->setSynthetic(true), '->setSynthetic() implements a fluent interface');
- $this->assertTrue($def->isSynthetic(), '->isSynthetic() returns true if the instance must not be public.');
+ $this->assertTrue($def->isSynthetic(), '->isSynthetic() returns true if the service is synthetic.');
+ }
+
+ /**
+ * @covers Symfony\Component\DependencyInjection\Definition::setSynchronized
+ * @covers Symfony\Component\DependencyInjection\Definition::isSynchronized
+ */
+ public function testSetIsSynchronized()
+ {
+ $def = new Definition('stdClass');
+ $this->assertFalse($def->isSynchronized(), '->isSynchronized() returns false by default');
+ $this->assertSame($def, $def->setSynchronized(true), '->setSynchronized() implements a fluent interface');
+ $this->assertTrue($def->isSynchronized(), '->isSynchronized() returns true if the service is synchronized.');
}
/**
View
9 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php
@@ -71,5 +71,14 @@
->register('baz', 'Baz')
->addMethodCall('setFoo', array(new Reference('foo_with_inline')))
;
+$container
+ ->register('request', 'Request')
+ ->setSynthetic(true)
+ ->setSynchronized(true)
+;
+$container
+ ->register('depends_on_request', 'stdClass')
+ ->addMethodCall('setRequest', array(new Reference('request', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)))
+;
return $container;
View
3 src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot
@@ -12,6 +12,8 @@ digraph sc {
node_foo_with_inline [label="foo_with_inline\nFoo\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_inlined [label="inlined\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_baz [label="baz\nBaz\n", shape=record, fillcolor="#eeeeee", style="filled"];
+ node_request [label="request\nRequest\n", shape=record, fillcolor="#eeeeee", style="filled"];
+ node_depends_on_request [label="depends_on_request\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];
@@ -28,4 +30,5 @@ digraph sc {
node_foo_with_inline -> node_inlined [label="setBar()" style="dashed"];
node_inlined -> node_baz [label="setBaz()" style="dashed"];
node_baz -> node_foo_with_inline [label="setFoo()" style="dashed"];
+ node_depends_on_request -> node_request [label="setRequest()" style="dashed"];
}
View
5 src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php
@@ -13,6 +13,11 @@ public function setBaz(BazClass $baz)
{
$this->baz = $baz;
}
+
+ public function getBaz()
+ {
+ return $this->baz;
+ }
}
class BazClass
View
40 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php
@@ -61,6 +61,23 @@ protected function getBazService()
}
/**
+ * Gets the 'depends_on_request' service.
+ *
+ * This service is shared.
+ * This method always returns the same instance of the service.
+ *
+ * @return stdClass A stdClass instance.
+ */
+ protected function getDependsOnRequestService()
+ {
+ $this->services['depends_on_request'] = $instance = new \stdClass();
+
+ $instance->setRequest($this->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE));
+
+ return $instance;
+ }
+
+ /**
* Gets the 'factory_service' service.
*
* This service is shared.
@@ -169,6 +186,19 @@ protected function getMethodCall1Service()
}
/**
+ * Gets the 'request' service.
+ *
+ * This service is shared.
+ * This method always returns the same instance of the service.
+ *
+ * @throws RuntimeException always since this service is expected to be injected dynamically
+ */
+ protected function getRequestService()
+ {
+ throw new RuntimeException('You have requested a synthetic service ("request"). The DIC does not know how to construct this service.');
+ }
+
+ /**
* Gets the alias_for_foo service alias.
*
* @return FooClass An instance of the foo service
@@ -179,6 +209,16 @@ protected function getAliasForFooService()
}
/**
+ * Updates the 'request' service.
+ */
+ protected function synchronizeRequestService()
+ {
+ if ($this->initialized('depends_on_request')) {
+ $this->get('depends_on_request')->setRequest($this->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE));
+ }
+ }
+
+ /**
* Gets the 'inlined' service.
*
* This service is shared.
View
40 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php
@@ -70,6 +70,23 @@ protected function getBazService()
}
/**
+ * Gets the 'depends_on_request' service.
+ *
+ * This service is shared.
+ * This method always returns the same instance of the service.
+ *
+ * @return stdClass A stdClass instance.
+ */
+ protected function getDependsOnRequestService()
+ {
+ $this->services['depends_on_request'] = $instance = new \stdClass();
+
+ $instance->setRequest($this->get('request'));
+
+ return $instance;
+ }
+
+ /**
* Gets the 'factory_service' service.
*
* This service is shared.
@@ -175,6 +192,19 @@ protected function getMethodCall1Service()
}
/**
+ * Gets the 'request' service.
+ *
+ * This service is shared.
+ * This method always returns the same instance of the service.
+ *
+ * @throws RuntimeException always since this service is expected to be injected dynamically
+ */
+ protected function getRequestService()
+ {
+ throw new RuntimeException('You have requested a synthetic service ("request"). The DIC does not know how to construct this service.');
+ }
+
+ /**
* Gets the alias_for_foo service alias.
*
* @return FooClass An instance of the foo service
@@ -185,6 +215,16 @@ protected function getAliasForFooService()
}
/**
+ * Updates the 'request' service.
+ */
+ protected function synchronizeRequestService()
+ {
+ if ($this->initialized('depends_on_request')) {
+ $this->get('depends_on_request')->setRequest($this->get('request'));
+ }
+ }
+
+ /**
* {@inheritdoc}
*/
public function getParameter($name)
View
1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml
@@ -46,5 +46,6 @@
<service id="alias_for_foo" alias="foo" />
<service id="another_alias_for_foo" alias="foo" public="false" />
<service id="factory_service" factory-method="getInstance" factory-service="baz_factory" />
+ <service id="request" class="Request" synthetic="true" synchronized="true"/>
</services>
</container>
View
6 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml
@@ -67,6 +67,12 @@
<argument type="service" id="foo_with_inline"/>
</call>
</service>
+ <service id="request" class="Request" synthetic="true" synchronized="true"/>
+ <service id="depends_on_request" class="stdClass">
+ <call method="setRequest">
+ <argument type="service" id="request" on-invalid="null" strict="false"/>
+ </call>
+ </service>
<service id="alias_for_foo" alias="foo"/>
</services>
</container>
View
4 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml
@@ -24,3 +24,7 @@ services:
alias: foo
public: false
factory_service: { class: BazClass, factory_method: getInstance, factory_service: baz_factory }
+ request:
+ class: Request
+ synthetic: true
+ synchronized: true
View
9 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml
@@ -57,4 +57,13 @@ services:
calls:
- [setFoo, ['@foo_with_inline']]
+ request:
+ class: Request
+ synthetic: true
+ synchronized: true
+ depends_on_request:
+ class: stdClass
+ calls:
+ - [setRequest, ['@?request']]
+
alias_for_foo: @foo
View
3 src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
@@ -185,6 +185,9 @@ public function testLoadServices()
$this->assertEquals('getInstance', $services['factory_service']->getFactoryMethod());
$this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());
+ $this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
+ $this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag');
+
$aliases = $container->getAliases();
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
View
3 src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
@@ -128,6 +128,9 @@ public function testLoadServices()
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
$this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());
+ $this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
+ $this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag');
+
$aliases = $container->getAliases();
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses aliases');
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');

0 comments on commit ec1e7ca

Please sign in to comment.