Skip to content

Commit a9068c6

Browse files
[DependencyInjection] Deprecate ContainerAwareInterface, ContainerAwareTrait and ContainerAwareLoader
1 parent d97f920 commit a9068c6

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Deprecate `ContainerAwareInterface` and `ContainerAwareTrait`, use dependency injection instead
8+
49
6.3
510
---
611

ContainerAwareInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* ContainerAwareInterface should be implemented by classes that depends on a Container.
1616
*
1717
* @author Fabien Potencier <fabien@symfony.com>
18+
*
19+
* @deprecated since Symfony 6.4, use dependency injection instead
1820
*/
1921
interface ContainerAwareInterface
2022
{

ContainerAwareTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Component\DependencyInjection;
1313

14+
trigger_deprecation('symfony/dependency-injection', '6.4', '"%s" is deprecated, use dependency injection instead.', ContainerAwareTrait::class);
15+
1416
/**
1517
* ContainerAware trait.
1618
*
1719
* @author Fabien Potencier <fabien@symfony.com>
20+
*
21+
* @deprecated since Symfony 6.4, use dependency injection instead
1822
*/
1923
trait ContainerAwareTrait
2024
{

Tests/ContainerAwareTraitTest.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
16-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
17-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1816
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
use Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerAwareDummy;
1918

19+
/**
20+
* @group legacy
21+
*/
2022
class ContainerAwareTraitTest extends TestCase
2123
{
2224
use ExpectDeprecationTrait;
2325

24-
/**
25-
* @group legacy
26-
*/
2726
public function testSetContainerLegacy()
2827
{
2928
$container = $this->createMock(ContainerInterface::class);
@@ -33,7 +32,7 @@ public function testSetContainerLegacy()
3332

3433
self::assertSame($container, $dummy->getContainer());
3534

36-
$this->expectDeprecation('Since symfony/dependency-injection 6.2: Calling "Symfony\Component\DependencyInjection\Tests\ContainerAwareDummy::setContainer()" without any arguments is deprecated, pass null explicitly instead.');
35+
$this->expectDeprecation('Since symfony/dependency-injection 6.2: Calling "Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerAwareDummy::setContainer()" without any arguments is deprecated, pass null explicitly instead.');
3736

3837
$dummy->setContainer();
3938
self::assertNull($dummy->getContainer());
@@ -52,13 +51,3 @@ public function testSetContainer()
5251
self::assertNull($dummy->getContainer());
5352
}
5453
}
55-
56-
class ContainerAwareDummy implements ContainerAwareInterface
57-
{
58-
use ContainerAwareTrait;
59-
60-
public function getContainer(): ?ContainerInterface
61-
{
62-
return $this->container;
63-
}
64-
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15+
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
16+
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
18+
/**
19+
* @deprecated since Symfony 6.4, to be removed in 7.0
20+
*/
21+
class ContainerAwareDummy implements ContainerAwareInterface
22+
{
23+
use ContainerAwareTrait;
24+
25+
public function getContainer(): ?ContainerInterface
26+
{
27+
return $this->container;
28+
}
29+
}
30+

0 commit comments

Comments
 (0)