Skip to content

Commit af42a0f

Browse files
committed
The class of a service definition might be passed as parameter.
1 parent 6eeec65 commit af42a0f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class Definition
5151
private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.';
5252

5353
/**
54-
* @param string|null $class The service class
55-
* @param array $arguments An array of arguments to pass to the service constructor
54+
* @param string|Parameter|null $class The service class
55+
* @param array $arguments An array of arguments to pass to the service constructor
5656
*/
5757
public function __construct($class = null, array $arguments = [])
5858
{
@@ -157,7 +157,7 @@ public function getDecoratedService()
157157
/**
158158
* Sets the service class.
159159
*
160-
* @param string $class The service class
160+
* @param string|Parameter|null $class The service class
161161
*
162162
* @return $this
163163
*/
@@ -173,7 +173,7 @@ public function setClass($class)
173173
/**
174174
* Gets the service class.
175175
*
176-
* @return string|null The service class
176+
* @return string|Parameter|null The service class
177177
*/
178178
public function getClass()
179179
{

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

Lines changed: 9 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

1718
class DefinitionTest extends TestCase
1819
{
@@ -45,6 +46,14 @@ public function testSetGetClass()
4546
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
4647
}
4748

49+
public function testSetGetClassWithParameter()
50+
{
51+
$def = new Definition('stdClass');
52+
$parameter = new Parameter('foo');
53+
$this->assertSame($def, $def->setClass($parameter), '->setClass() implements a fluent interface');
54+
$this->assertSame($parameter, $def->getClass(), '->getClass() returns the parameterized class name');
55+
}
56+
4857
public function testSetGetDecoratedService()
4958
{
5059
$def = new Definition('stdClass');

0 commit comments

Comments
 (0)