8000 [DependencyInjection] deprecated synchronized services · symfony/symfony@d7cd280 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7cd280

Browse files
committed
[DependencyInjection] deprecated synchronized services
1 parent 7f8ff50 commit d7cd280

24 files changed

+173
-86
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 have been
99+
removed: `ContainerBuilder::synchronize()`, `Definition::isSynchronized()`,
100+
and `Definition::setSynchronized()`.
101+
98102
### EventDispatcher
99103

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

autoload.php.dist

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ class DeprecationErrorHandler
4444
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
4545
$method = $trace[$i]['function'];
4646

47-
$type =
48-
0 === strpos($method, 'testLegacy')
49-
|| 0 === strpos($method, 'provideLegacy')
50-
|| strpos($class, '\Legacy')
51-
? 'legacy' : 'remaining';
47+
$type = 0 === strpos($method, 'testLegacy') || 0 === strpos($method, 'provideLegacy') || 0 === strpos($method, 'getLegacy') || strpos($class, '\Legacy') ? 'legacy' : 'remaining';
5248

5349
if ('legacy' === $type && 0 === (error_reporting() & E_USER_DEPRECATED)) {
5450
@++$deprecations[$type]['Silenced']['count'];

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
215215
'public' => $definition->isPublic(),
216216
'synthetic' => $definition->isSynthetic(),
217217
'lazy' => $definition->isLazy(),
218-
'synchronized' => $definition->isSynchronized(),
219-
'abstract' => $definition->isAbstract(),
220-
'file' => $definition->getFile(),
221218
);
219+
if (method_exists($definition, 'isSynchronized')) {
220+
$data['synchronized'] = $definition->isSynchronized();
221+
}
222+
223+
$data['abstract'] = $definition->isAbstract();
224+
$data['file'] = $definition->getFile();
222225

223226
if ($definition->getFactoryClass()) {
224227
$data['factory_class'] = $definition->getFactoryClass();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,13 @@ protected function describeContainerDefinition(Definition $definition, array $op
183183
."\n".'- Public: '.($definition->isPublic() ? 'yes' : 'no')
184184
."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no')
185185
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')
186-
."\n".'- Synchronized: '.($definition->isSynchronized() ? 'yes' : 'no')
187-
."\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no');
186+
;
187+
188+
if (method_exists($definition, 'isSynchronized')) {
189+
$output .= "\n".'- Synchronized: '.($definition->isSynchronized() ? 'yes' : 'no');
190+
}
191+
192+
$output .= "\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no');
188193

189194
if ($definition->getFile()) {
190195
$output .= "\n".'- File: `'.$definition->getFile().'`';

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ protected function describeContainerDefinition(Definition $definition, array $op
265265
$description[] = sprintf('<comment>Public</comment> %s', $definition->isPublic() ? 'yes' : 'no');
266266
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
267267
$description[] = sprintf('<comment>Lazy</comment> %s', $definition->isLazy() ? 'yes' : 'no');
268-
$description[] = sprintf('<comment>Synchronized</comment> %s', $definition->isSynchronized() ? 'yes' : 'no');
268+
if (method_exists($definition, 'isSynchronized')) {
269+
$description[] = sprintf('<comment>Synchronized</comment> %s', $definition->isSynchronized() ? 'yes' : 'no');
270+
}
269271
$description[] = sprintf('<comment>Abstract</comment> %s', $definition->isAbstract() ? 'yes' : 'no');
270272

271273
if ($definition->getFile()) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
366366
$serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
367367
$serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');
368368
$serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false');
369-
$serviceXML->setAttribute('synchronized', $definition->isSynchronized() ? 'true' : 'false');
369+
if (method_exists($definition, 'isSynchronized')) {
370+
$serviceXML->setAttribute('synchronized', $definition->isSynchronized(false) ? 'true' : 'false');
371+
}
370372
$serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false');
371373
$serviceXML->setAttribute('file', $definition->getFile());
372374

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: 7 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,15 @@ 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+
if ('request' !== $id) {
1130+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
1131+
}
1132+
11271133
foreach ($this->definitions as $definitionId => $definition) {
11281134
// only check initialized services
11291135
if (!$this->initialized($definitionId)) {

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,15 @@ public function isPublic()
661661
* @return Definition The current instance
662662
*
663663
* @api
664+
*
665+
* @deprecated since version 2.7, will be removed in 3.0.
664666
*/
665-
public function setSynchronized($boolean)
667+
public function setSynchronized($boolean, $triggerDeprecationError = true)
666668
{
669+
if ($triggerDeprecationError) {
670+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
671+
}
672+
667673
$this->synchronized = (bool) $boolean;
668674

669675
return $this;
@@ -675,9 +681,15 @@ public function setSynchronized($boolean)
675681
* @return bool
676682
*
677683
* @api
684+
*
685+
* @deprecated since version 2.7, will be removed in 3.0.
678686
*/
679-
public function isSynchronized()
687+
public function isSynchronized($triggerDeprecationError = true)
680688
{
689+
if ($triggerDeprecationError) {
690+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
691+
}
692+
681693
return $this->synchronized;
682694
}
683695

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,19 @@ 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+
if ('request' !== $id) {
708+
trigger_error('Synchronized services were deprecated in version 2.7 and won\'t work anymore in 3.0.', E_USER_DEPRECATED);
709+
}
710+
705711
$code = '';
706712
foreach ($this->container->getDefinitions() as $definitionId => $definition) {
707713
foreach ($definition->getMethodCalls() as $call) {

0 commit comments

Comments
 (0)
0