Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98abc7b

Browse files
committed
[DependencyInjection] deprecated synchronized services
1 parent b009902 commit 98abc7b

File tree

15 files changed

+55
-15
lines changed

15 files changed

+55
-15
lines changed

UPGRADE-3.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ UPGRADE FROM 2.x to 3.0
9595
been removed in favor of `Definition::setFactory()`. Services defined using
9696
YAML or XML use the same syntax as configurators.
9797

98+
* Synchronized services are deprecated and the following methods will be
99+
removed: `ContainerBuilder::synchronize()`, `Definition::isSynchronized()`,
100+
and `Definition::setSynchronized()`.
101+
98102
### EventDispatcher
99103

100104
* The interface `Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface`

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
362362
$serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
363363
$serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');
364364
$serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false');
365-
$serviceXML->setAttribute('synchronized', $definition->isSynchronized() ? 'true' : 'false');
365+
if (method_exists($definition, 'isSynchronized')) {
366+
$serviceXML->setAttribute('synchronized', $definition->isSynchronized(false) ? 'true' : 'false');
367+
}
366368
$serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false');
367369
$serviceXML->setAttribute('file', $definition->getFile());
368370

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,23 @@ public static function getContainerDefinitions()
9292
$definition1 = new Definition('Full\\Qualified\\Class1');
9393
$definition2 = new Definition('Full\\Qualified\\Class2');
9494

95+
if (method_exists($definition1, 'setSynchronized')) {
96+
$definition1->setSynchronized(true, false);
97+
$definition2->setSynchronized(false, false);
98+
}
99+
95100
return array(
96101
'definition_1' => $definition1
97102
->setPublic(true)
98103
->setSynthetic(false)
99104
->setLazy(true)
100-
->setSynchronized(true)
101105
->setAbstract(true)
102106
->setFactory(array('Full\\Qualified\\FactoryClass', 'get')),
103107
'definition_2' => $definition2
104108
->setPublic(false)
105109
->setSynthetic(true)
106110
->setFile('/path/to/file')
107111
->setLazy(false)
108-
->setSynchronized(false)
109112
->setAbstract(false)
110113
->addTag('tag1', array('attr1' => 'val1', 'attr2' => 'val2'))
111114
->addTag('tag1', array('attr3' => 'val3'))

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.7.0
5+
-----
6+
7+
* deprecated synchronized services
8+
49
2.6.0
510
-----
611

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
412412

413413
parent::set($id, $service, $scope);
414414

415-
if (isset($this->obsoleteDefinitions[$id]) && $this->obsoleteDefinitions[$id]->isSynchronized()) {
415+
if (isset($this->obsoleteDefinitions[$id]) && $this->obsoleteDefinitions[$id]->isSynchronized(false)) {
416416
$this->synchronize($id);
417417
}
418418
}
@@ -1121,9 +1121,13 @@ private function getProxyInstantiator()
11211121
* service by calling all methods referencing it.
11221122
*
11231123
* @param string $id A service id
1124+
*
1125+
* @deprecated since version 2.7, will be removed in 3.0.
11241126
*/
11251127
private function synchronize($id)
11261128
{
1129+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
1130+
11271131
foreach ($this->definitions as $definitionId => $definition) {
11281132
// only check initialized services
11291133
if (!$this->initialized($definitionId)) {

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,15 @@ public function isPublic()
655655
* @return Definition The current instance
656656
*
657657
* @api
658+
*
659+
* @deprecated since version 2.7, will be removed in 3.0.
658660
*/
659-
public function setSynchronized($boolean)
661+
public function setSynchronized($boolean, $triggerDeprecationError = true)
660662
{
663+
if ($triggerDeprecationError) {
664+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
665+
}
666+
661667
$this->synchronized = (bool) $boolean;
662668

663669
return $this;
@@ -669,9 +675,15 @@ public function setSynchronized($boolean)
669675
* @return bool
670676
*
671677
* @api
678+
*
679+
* @deprecated since version 2.7, will be removed in 3.0.
672680
*/
673-
public function isSynchronized()
681+
public function isSynchronized($triggerDeprecationError = true)
674682
{
683+
if ($triggerDeprecationError) {
684+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
685+
}
686+
675687
return $this->synchronized;
676688
}
677689

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,17 @@ private function addServices()
695695
* @param Definition $definition A Definition instance
696696
*
697697
* @return string|null
698+
*
699+
* @deprecated since version 2.7, will be removed in 3.0.
698700
*/
699701
private function addServiceSynchronizer($id, Definition $definition)
700702
{
701-
if (!$definition->isSynchronized()) {
703+
if (!$definition->isSynchronized(false)) {
702704
return;
703705
}
704706

707+
trigger_error('Synchronized services were deprecated in version 2.7 and won\'t work anymore in 3.0.', E_USER_DEPRECATED);
708+
705709
$code = '';
706710
foreach ($this->container->getDefinitions() as $definitionId => $definition) {
707711
foreach ($definition->getMethodCalls() as $call) {

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private function addService($definition, $id, \DOMElement $parent)
135135
if ($definition->isSynthetic()) {
136136
$service->setAttribute('synthetic', 'true');
137137
}
138-
if ($definition->isSynchronized()) {
138+
if ($definition->isSynchronized(false)) {
139139
$service->setAttribute('synchronized', 'true');
140140
}
141141
if ($definition->isLazy()) {

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function addService($id, $definition)
103103
$code .= sprintf(" synthetic: true\n");
104104
}
105105

106-
if ($definition->isSynchronized()) {
106+
if ($definition->isSynchronized(false)) {
107107
$code .= sprintf(" synchronized: true\n");
108108
}
109109

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,17 @@ private function parseDefinition($id, \DOMElement $service, $file)
145145
$definition = new Definition();
146146
}
147147

148-
foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'synchronized', 'lazy', 'abstract') as $key) {
148+
foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) {
149149
if ($value = $service->getAttribute($key)) {
150150
$method = 'set'.str_replace('-', '', $key);
151151
$definition->$method(XmlUtils::phpize($value));
152152
}
153153
}
154154

155+
if ($value = $service->getAttribute('synchronized')) {
156+
$definition->setSynchronized(XmlUtils::phpize($value), false);
157+
}
158+
155159
if ($files = $this->getChildren($service, 'file')) {
156160
$definition->setFile($files[0]->nodeValue);
157161
}

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private function parseDefinition($id, $service, $file)
171171
}
172172

173173
if (isset($service['synchronized'])) {
174-
$definition->setSynchronized($service['synchronized']);
174+
$definition->setSynchronized($service['synchronized'], false);
175175
}
176176

177177
if (isset($service['lazy'])) {

src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ public function testSetIsSynthetic()
167167
* @covers Symfony\Component\DependencyInjection\Definition::setSynchronized
168168
* @covers Symfony\Component\DependencyInjection\Definition::isSynchronized
169169
*/
170-
public function testSetIsSynchronized()
170+
public function testLegacySetIsSynchronized()
171171
{
172+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
173+
172174
$def = new Definition('stdClass');
173175
$this->assertFalse($def->isSynchronized(), '->isSynchronized() returns false by default');
174176
$this->assertSame($def, $def->setSynchronized(true), '->setSynchronized() implements a fluent interface');

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
$container
7878
->register('request', 'Request')
7979
->setSynthetic(true)
80-
->setSynchronized(true)
80+
->setSynchronized(true, false)
8181
;
8282
$container
8383
->register('depends_on_request', 'stdClass')

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function testLoadServices()
219219
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
220220

221221
$this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
222-
$this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag');
222+
$this->assertTrue($services['request']->isSynchronized(false), '->load() parses the synchronized flag');
223223
$this->assertTrue($services['request']->isLazy(), '->load() parses the lazy flag');
224224

225225
$aliases = $container->getAliases();

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testLoadServices()
146146
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
147147

148148
$this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
149-
$this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag');
149+
$this->assertTrue($services['request']->isSynchronized(false), '->load() parses the synchronized flag');
150150
$this->assertTrue($services['request']->isLazy(), '->load() parses the lazy flag');
151151

152152
$aliases = $container->getAliases();

0 commit comments

Comments
 (0)