Deprecated passing Parameter instances as class name to Definition.
This commit is contained in:
parent
09e3cef7a0
commit
edfc9d6f34
@ -41,6 +41,18 @@ DependencyInjection
|
|||||||
arguments: [!tagged_iterator app.handler]
|
arguments: [!tagged_iterator app.handler]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Passing an instance of `Symfony\Component\DependencyInjection\Parameter` as class name to `Symfony\Component\DependencyInjection\Definition` is deprecated.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
```php
|
||||||
|
new Definition(new Parameter('my_class'));
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
```php
|
||||||
|
new Definition('%my_class%');
|
||||||
|
```
|
||||||
|
|
||||||
Filesystem
|
Filesystem
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ CHANGELOG
|
|||||||
|
|
||||||
* deprecated support for short factories and short configurators in Yaml
|
* deprecated support for short factories and short configurators in Yaml
|
||||||
* deprecated `tagged` in favor of `tagged_iterator`
|
* deprecated `tagged` in favor of `tagged_iterator`
|
||||||
|
* deprecated passing an instance of `Symfony\Component\DependencyInjection\Parameter` as class name to `Symfony\Component\DependencyInjection\Definition`
|
||||||
|
|
||||||
4.3.0
|
4.3.0
|
||||||
-----
|
-----
|
||||||
|
@ -171,6 +171,13 @@ class Definition
|
|||||||
*/
|
*/
|
||||||
public function setClass($class)
|
public function setClass($class)
|
||||||
{
|
{
|
||||||
|
if ($class instanceof Parameter) {
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
if (null !== $class && !\is_string($class)) {
|
||||||
|
@trigger_error(sprintf('The class name passed to %s is expected to be a string. Passing a %s is deprecated in Symfony 4.4 and will result in a TypeError in 5.0.', __CLASS__, \is_object($class) ? \get_class($class) : \gettype($class)), E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
$this->changes['class'] = true;
|
$this->changes['class'] = true;
|
||||||
|
|
||||||
$this->class = $class;
|
$this->class = $class;
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Tests;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
use Symfony\Component\DependencyInjection\Parameter;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
class DefinitionTest extends TestCase
|
class DefinitionTest extends TestCase
|
||||||
@ -27,6 +28,18 @@ class DefinitionTest extends TestCase
|
|||||||
$this->assertEquals(['foo'], $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
|
$this->assertEquals(['foo'], $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
public function testConstructorWithParameter()
|
||||||
|
{
|
||||||
|
$parameter = new Parameter('parameter');
|
||||||
|
|
||||||
|
$def = new Definition($parameter);
|
||||||
|
$this->assertSame($parameter, $def->getClass(), '__construct() accepts Parameter instances');
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetGetFactory()
|
public function testSetGetFactory()
|
||||||
{
|
{
|
||||||
$def = new Definition();
|
$def = new Definition();
|
||||||
@ -49,6 +62,28 @@ class DefinitionTest extends TestCase
|
|||||||
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
|
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
public function testSetGetClassWithParameter()
|
||||||
|
{
|
||||||
|
$def = new Definition();
|
||||||
|
$parameter = new Parameter('parameter');
|
||||||
|
$this->assertSame($parameter, $def->setClass($parameter)->getClass(), '->getClass() returns the parameterized class name');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @expectedDeprecation The class name passed to Symfony\Component\DependencyInjection\Definition is expected to be a string. Passing a stdClass is deprecated in Symfony 4.4 and will result in a TypeError in 5.0.
|
||||||
|
*/
|
||||||
|
public function testSetGetClassWithObject()
|
||||||
|
{
|
||||||
|
$def = new Definition();
|
||||||
|
$classObject = new \stdClass();
|
||||||
|
$this->assertSame($classObject, $def->setClass($classObject)->getClass(), '->getClass() returns the parameterized class name');
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetGetDecoratedService()
|
public function testSetGetDecoratedService()
|
||||||
{
|
{
|
||||||
$def = new Definition('stdClass');
|
$def = new Definition('stdClass');
|
||||||
|
@ -1082,7 +1082,7 @@ class PhpDumperTest extends TestCase
|
|||||||
'class' => 'stdClass',
|
'class' => 'stdClass',
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$container->setDefinition('foo', new Definition(new Parameter('class')));
|
$container->setDefinition('foo', new Definition('%class%'));
|
||||||
$container->setDefinition('bar', new Definition('stdClass', [
|
$container->setDefinition('bar', new Definition('stdClass', [
|
||||||
new Reference('foo'),
|
new Reference('foo'),
|
||||||
]))->setPublic(true);
|
]))->setPublic(true);
|
||||||
|
@ -494,10 +494,8 @@ class MessengerPassTest extends TestCase
|
|||||||
|
|
||||||
public function testRegistersTraceableBusesToCollector()
|
public function testRegistersTraceableBusesToCollector()
|
||||||
{
|
{
|
||||||
$dataCollector = $this->getMockBuilder(MessengerDataCollector::class)->getMock();
|
|
||||||
|
|
||||||
$container = $this->getContainerBuilder($fooBusId = 'messenger.bus.foo');
|
$container = $this->getContainerBuilder($fooBusId = 'messenger.bus.foo');
|
||||||
$container->register('data_collector.messenger', $dataCollector);
|
$container->register('data_collector.messenger', MessengerDataCollector::class);
|
||||||
$container->setParameter('kernel.debug', true);
|
$container->setParameter('kernel.debug', true);
|
||||||
|
|
||||||
(new MessengerPass())->process($container);
|
(new MessengerPass())->process($container);
|
||||||
|
Reference in New Issue
Block a user