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

Skip to content

Commit a800e12

Browse files
committed
Deprecated passing Parameter instances as class name to Definition.
1 parent 09e3cef commit a800e12

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

UPGRADE-4.4.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ DependencyInjection
4141
arguments: [!tagged_iterator app.handler]
4242
```
4343

44+
* Passing an instance of `Symfony\Component\DependencyInjection\Parameter` as class name to `Symfony\Component\DependencyInjection\Definition` is now deprecated.
45+
46+
Before:
47+
```php
48+
new Definition(new Parameter('my_class'));
49+
```
50+
51+
After:
52+
```php
53+
new Definition('%my_class%');
54+
```
55+
4456
Filesystem
4557
----------
4658

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* deprecated support for short factories and short configurators in Yaml
88
* deprecated `tagged` in favor of `tagged_iterator`
9+
* deprecated passing an instance of `Symfony\Component\DependencyInjection\Parameter` as class name to `Symfony\Component\DependencyInjection\Definition`
910

1011
4.3.0
1112
-----

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ public function getDecoratedService()
171171
*/
172172
public function setClass($class)
173173
{
174+
if ($class instanceof Parameter) {
175+
@trigger_error(sprintf('Passing an instance of %s as class name to %s in deprecated in Symfony 4.4 and will result in a TypeError in 5.0. Please pass the string "%%%s%%" instead.', Parameter::class, __CLASS__, (string) $class), E_USER_DEPRECATED);
176+
}
177+
174178
$this->changes['class'] = true;
175179

176180
$this->class = $class;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Parameter;
1617
use Symfony\Component\DependencyInjection\Reference;
1718

1819
class DefinitionTest extends TestCase
@@ -49,6 +50,18 @@ public function testSetGetClass()
4950
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
5051
}
5152

53+
/**
54+
* @group legacy
55+
* @expectedDeprecation Passing an instance of Symfony\Component\DependencyInjection\Parameter as class name to Symfony\Component\DependencyInjection\Definition in deprecated in Symfony 4.4 and will result in a TypeError in 5.0. Please pass the string "%parameter%" instead.
56+
*/
57+
public function testSetGetClassWithParameter()
58+
{
59+
$def = new Definition('stdClass');
60+
$parameter = new Parameter('parameter');
61+
$this->assertSame($def, $def->setClass($parameter), '->setClass() implements a fluent interface');
62+
$this->assertSame($parameter, $def->getClass(), '->getClass() returns the parameterized class name');
63+
}
64+
5265
public function testSetGetDecoratedService()
5366
{
5467
$def = new Definition('stdClass');

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ public function testDumpHandlesObjectClassNames()
10821082
'class' => 'stdClass',
10831083
]));
10841084

1085-
$container->setDefinition('foo', new Definition(new Parameter('class')));
1085+
$container->setDefinition('foo', new Definition('%class%'));
10861086
$container->setDefinition('bar', new Definition('stdClass', [
10871087
new Reference('foo'),
10881088
]))->setPublic(true);

0 commit comments

Comments
 (0)