Skip to content

[DependencyInjection] The class of a service definition might be passed as parameter #32279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Definition
private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.';

/**
* @param string|null $class The service class
* @param array $arguments An array of arguments to pass to the service constructor
* @param string|Parameter|null $class The service class
* @param array $arguments An array of arguments to pass to the service constructor
*/
public function __construct($class = null, array $arguments = [])
{
Expand Down Expand Up @@ -157,7 +157,7 @@ public function getDecoratedService()
/**
* Sets the service class.
*
* @param string $class The service class
* @param string|Parameter|null $class The service class
*
* @return $this
*/
Expand All @@ -173,7 +173,7 @@ public function setClass($class)
/**
* Gets the service class.
*
* @return string|null The service class
* @return string|Parameter|null The service class
*/
public function getClass()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Parameter;

class DefinitionTest extends TestCase
{
Expand Down Expand Up @@ -45,6 +46,14 @@ public function testSetGetClass()
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
}

public function testSetGetClassWithParameter()
{
$def = new Definition('stdClass');
$parameter = new Parameter('foo');
$this->assertSame($def, $def->setClass($parameter), '->setClass() implements a fluent interface');
$this->assertSame($parameter, $def->getClass(), '->getClass() returns the parameterized class name');
}

public function testSetGetDecoratedService()
{
$def = new Definition('stdClass');
Expand Down