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

Skip to content

Commit 9a0ac34

Browse files
committed
[DependencyInjection] deprecated synchronized services
1 parent b009902 commit 9a0ac34

File tree

11 files changed

+40
-9
lines changed

11 files changed

+40
-9
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/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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,13 @@ 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
*/
659661
public function setSynchronized($boolean)
660662
{
663+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
664+
661665
$this->synchronized = (bool) $boolean;
662666

663667
return $this;
@@ -669,9 +673,15 @@ public function setSynchronized($boolean)
669673
* @return bool
670674
*
671675
* @api
676+
*
677+
* @deprecated since version 2.7, will be removed in 3.0.
672678
*/
673-
public function isSynchronized()
679+
public function isSynchronized($triggerDeprecationError = true)
674680
{
681+
if ($triggerDeprecationError) {
682+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
683+
}
684+
675685
return $this->synchronized;
676686
}
677687

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/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/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)