Skip to content

Commit 24952ce

Browse files
Merge branch '6.4' into 7.0
* 6.4: (32 commits) [Validator] Add missing validator translations in Polish language [FrameworkBundle][Workflow] Add metadata dumping support for GraphvizDumper [HttpClient] Fix encoding some characters in query strings [HttpKernel] make RequestPayloadValueResolver:resolve() throw on variadic argument Fix typos Added redlink notifier [SecurityBundle] Remove last usages of tag `security.remember_me_aware` [VarDumper] Dumping DateTime throws error if getTimezone is false [DependencyInjection] Deprecate `ContainerAwareInterface`, `ContainerAwareTrait` and `ContainerAwareLoader` Only update autoload_runtime.php when it changed [Routing] Fix version in CHANGELOG [Console] Aligned multiline text in vertical table Fix README [Notifier] add Ntfy bridge [FrameworkBundle] Fix secrets:list not displaying local vars [Intl] Update the ICU data to 73.2 [DoctrineBridge] add missing UPGRADE notes for #50689 [HttpClient] Force int conversion for floated multiplier for GenericRetryStrategy [Security] Fix log message in OidcTokenHandler [Notifier] Add Novu bridge ...
2 parents edbc567 + 965d2e7 commit 24952ce

File tree

7 files changed

+109
-17
lines changed

7 files changed

+109
-17
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 <[email protected]>
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 <[email protected]>
20+
*
21+
* @deprecated since Symfony 6.4, use dependency injection instead
1822
*/
1923
trait ContainerAwareTrait
2024
{

EnvVarProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
146146
if (false !== $i || 'string' !== $prefix) {
147147
$env = $getEnv($name);
148148
} elseif ('' === ($env = $_ENV[$name] ?? (str_starts_with($name, 'HTTP_') ? null : ($_SERVER[$name] ?? null)))
149-
|| false === ($env = $env ?? getenv($name) ?? false) // null is a possible value because of thread safety issues
149+
|| (false !== $env && false === ($env = $env ?? getenv($name) ?? false)) // null is a possible value because of thread safety issues
150150
) {
151151
foreach ($this->loadedVars as $vars) {
152152
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {

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-
}

Tests/EnvVarProcessorTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,67 @@ public static function validStrings()
5959
];
6060
}
6161

62+
/**
63+
* @dataProvider validRealEnvValues
64+
*/
65+
public function testGetEnvRealEnv($value, $processed)
66+
{
67+
$_ENV['FOO'] = $value;
68+
69+
$processor = new EnvVarProcessor(new Container());
70+
71+
$result = $processor->getEnv('string', 'FOO', function () {
72+
$this->fail('Should not be called');
73+
});
74+
75+
$this->assertSame($processed, $result);
76+
77+
unset($_ENV['FOO']);
78+
}
79+
80+
public static function validRealEnvValues()
81+
{
82+
return [
83+
['hello', 'hello'],
84+
[true, '1'],
85+
[false, ''],
86+
[1, '1'],
87+
[0, '0'],
88+
[1.1, '1.1'],
89+
[10, '10'],
90+
];
91+
}
92+
93+
public function testGetEnvRealEnvInvalid()
94+
{
95+
$_ENV['FOO'] = null;
96+
$this->expectException(EnvNotFoundException::class);
97+
$this->expectExceptionMessage('Environment variable not found: "FOO".');
98+
99+
$processor = new EnvVarProcessor(new Container());
100+
101+
$processor->getEnv('string', 'FOO', function () {
102+
$this->fail('Should not be called');
103+
});
104+
105+
unset($_ENV['FOO']);
106+
}
107+
108+
public function testGetEnvRealEnvNonScalar()
109+
{
110+
$_ENV['FOO'] = [];
111+
$this->expectException(RuntimeException::class);
112+
$this->expectExceptionMessage('Non-scalar env var "FOO" cannot be cast to "string".');
113+
114+
$processor = new EnvVarProcessor(new Container());
115+
116+
$processor->getEnv('string', 'FOO', function () {
117+
$this->fail('Should not be called');
118+
});
119+
120+
unset($_ENV['FOO']);
121+
}
122+
62123
/**
63124
* @dataProvider validBools
64125
*/
@@ -97,6 +158,7 @@ public static function validBools()
97158
['true', true],
98159
['false', false],
99160
['null', false],
161+
['', false],
100162
['1', true],
101163
['0', false],
102164
['1.1', true],
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 <[email protected]>
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)