Skip to content

Commit 4e334b9

Browse files
Leverage trigger_deprecation() from symfony/deprecation-contracts
1 parent 444f928 commit 4e334b9

10 files changed

+18
-17
lines changed

Compiler/ResolveReferencesToAliasesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function getDefinitionId(string $id, ContainerBuilder $container): strin
6262
$alias = $container->getAlias($id);
6363

6464
if ($alias->isDeprecated()) {
65-
@trigger_error(sprintf('%s. It is being referenced by the "%s" %s.', rtrim($alias->getDeprecationMessage($id), '. '), $this->currentId, $container->hasDefinition($this->currentId) ? 'service' : 'alias'), E_USER_DEPRECATED);
65+
trigger_deprecation('', '', '%s. It is being referenced by the "%s" %s.', rtrim($alias->getDeprecationMessage($id), '. '), $this->currentId, $container->hasDefinition($this->currentId) ? 'service' : 'alias');
6666
}
6767

6868
$seen = [];

ContainerBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ private function doGet(string $id, int $invalidBehavior = ContainerInterface::EX
568568
$alias = $this->aliasDefinitions[$id];
569569

570570
if ($alias->isDeprecated()) {
571-
@trigger_error($alias->getDeprecationMessage($id), E_USER_DEPRECATED);
571+
trigger_deprecation('', '', $alias->getDeprecationMessage($id));
572572
}
573573

574574
return $this->doGet((string) $alias, $invalidBehavior, $inlineServices, $isConstructorArgument);
@@ -1037,7 +1037,7 @@ private function createService(Definition $definition, array &$inlineServices, b
10371037
}
10381038

10391039
if ($definition->isDeprecated()) {
1040-
@trigger_error($definition->getDeprecationMessage($id), E_USER_DEPRECATED);
1040+
trigger_deprecation('', '', $definition->getDeprecationMessage($id));
10411041
}
10421042

10431043
if ($tryProxy && $definition->isLazy() && !$tryProxy = !($proxy = $this->proxyInstantiator) || $proxy instanceof RealServiceInstantiator) {
@@ -1080,7 +1080,7 @@ private function createService(Definition $definition, array &$inlineServices, b
10801080
$r = new \ReflectionClass($factory[0]);
10811081

10821082
if (0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
1083-
@trigger_error(sprintf('The "%s" service relies on the deprecated "%s" factory class. It should either be deprecated or its factory upgraded.', $id, $r->name), E_USER_DEPRECATED);
1083+
trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" factory class. It should either be deprecated or its factory upgraded.', $id, $r->name);
10841084
}
10851085
}
10861086
} else {
@@ -1089,7 +1089,7 @@ private function createService(Definition $definition, array &$inlineServices, b
10891089
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
10901090

10911091
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
1092-
@trigger_error(sprintf('The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name), E_USER_DEPRECATED);
1092+
trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name);
10931093
}
10941094
}
10951095

Dumper/PhpDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ protected function {$methodName}($lazyInitialization)
803803
$this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls);
804804

805805
if ($definition->isDeprecated()) {
806-
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
806+
$code .= sprintf(" trigger_deprecation('', '', %s);\n\n", $this->export($definition->getDeprecationMessage($id)));
807807
}
808808

809809
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
@@ -1312,7 +1312,7 @@ private function addDeprecatedAliases(): string
13121312
*/
13131313
protected function {$methodNameAlias}()
13141314
{
1315-
@trigger_error($messageExported, E_USER_DEPRECATED);
1315+
trigger_deprecation('', '', $messageExported);
13161316
13171317
return \$this->get($idExported);
13181318
}

Tests/Fixtures/DeprecatedClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
1313

14-
@trigger_error('deprecated', E_USER_DEPRECATED);
14+
trigger_deprecation('', '', 'deprecated');
1515

1616
class DeprecatedClass
1717
{

Tests/Fixtures/php/container_alias_deprecation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function getFooService()
6666
*/
6767
protected function getAliasForFooDeprecatedService()
6868
{
69-
@trigger_error('The "alias_for_foo_deprecated" service alias is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
69+
trigger_deprecation('', '', 'The "alias_for_foo_deprecated" service alias is deprecated. You should stop using it, as it will be removed in the future.');
7070

7171
return $this->get('foo');
7272
}

Tests/Fixtures/php/services9_as_files.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
124124
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
125125
// Returns the public 'deprecated_service' shared service.
126126

127-
@trigger_error('The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
127+
trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.');
128128

129129
return $this->services['deprecated_service'] = new \stdClass();
130130

@@ -156,7 +156,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
156156
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
157157
// Returns the private 'factory_simple' shared service.
158158

159-
@trigger_error('The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
159+
trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.');
160160

161161
return new \SimpleFactoryClass('foo');
162162

Tests/Fixtures/php/services9_compiled.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protected function getDecoratorServiceWithNameService()
210210
*/
211211
protected function getDeprecatedServiceService()
212212
{
213-
@trigger_error('The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
213+
trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.');
214214

215215
return $this->services['deprecated_service'] = new \stdClass();
216216
}
@@ -404,7 +404,7 @@ protected function getTaggedIteratorService()
404404
*/
405405
protected function getFactorySimpleService()
406406
{
407-
@trigger_error('The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
407+
trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.');
408408

409409
return new \SimpleFactoryClass('foo');
410410
}

Tests/Fixtures/php/services9_inlined_factories.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class ProjectServiceContainer extends Container
231231
*/
232232
protected function getDeprecatedServiceService()
233233
{
234-
@trigger_error('The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
234+
trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.');
235235

236236
return $this->services['deprecated_service'] = new \stdClass();
237237
}
@@ -453,7 +453,7 @@ class ProjectServiceContainer extends Container
453453
*/
454454
protected function getFactorySimpleService()
455455
{
456-
@trigger_error('The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
456+
trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.');
457457

458458
return new \SimpleFactoryClass('foo');
459459
}

Tests/Fixtures/php/services_errored_definition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protected function getDecoratorServiceWithNameService()
210210
*/
211211
protected function getDeprecatedServiceService()
212212
{
213-
@trigger_error('The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
213+
trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.');
214214

215215
return $this->services['deprecated_service'] = new \stdClass();
216216
}
@@ -404,7 +404,7 @@ protected function getTaggedIteratorService()
404404
*/
405405
protected function getFactorySimpleService()
406406
{
407-
@trigger_error('The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
407+
trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.');
408408

409409
return new \SimpleFactoryClass('foo');
410410
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"require": {
1919
"php": "^7.2.5",
2020
"psr/container": "^1.0",
21+
"symfony/deprecation-contracts": "^2.1",
2122
"symfony/service-contracts": "^1.1.6|^2"
2223
},
2324
"require-dev": {

0 commit comments

Comments
 (0)