35
35
use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \NullDumper ;
36
36
use Symfony \Component \DependencyInjection \Loader \FileLoader ;
37
37
use Symfony \Component \DependencyInjection \Parameter ;
38
+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
38
39
use Symfony \Component \DependencyInjection \Reference ;
39
40
use Symfony \Component \DependencyInjection \ServiceLocator as BaseServiceLocator ;
40
41
use Symfony \Component \DependencyInjection \TypedReference ;
@@ -1232,6 +1233,8 @@ private function startClass(string $class, string $baseClass, bool $hasProxyClas
1232
1233
*/
1233
1234
class $ class extends $ baseClass
1234
1235
{
1236
+ private const DEPRECATED_PARAMETERS = [];
1237
+
1235
1238
protected \$parameters = [];
1236
1239
protected readonly \WeakReference \$ref;
1237
1240
@@ -1240,11 +1243,9 @@ public function __construct()
1240
1243
\$this->ref = \WeakReference::create( \$this);
1241
1244
1242
1245
EOF ;
1246
+ $ code = str_replace (" private const DEPRECATED_PARAMETERS = []; \n\n" , $ this ->addDeprecatedParameters (), $ code );
1243
1247
if ($ this ->asFiles ) {
1244
- $ code = str_replace ('$parameters = [] ' , "\$containerDir; \n protected \$parameters = []; \n private \$buildParameters " , $ code );
1245
- $ code = str_replace ('__construct() ' , '__construct(array $buildParameters = [], $containerDir = __DIR__) ' , $ code );
1246
- $ code .= " \$this->buildParameters = \$buildParameters; \n" ;
1247
- $ code .= " \$this->containerDir = \$containerDir; \n" ;
1248
+ $ code = str_replace ('__construct() ' , '__construct(private array $buildParameters = [], protected string $containerDir = __DIR__) ' , $ code );
1248
1249
1249
1250
if (null !== $ this ->targetDirRegex ) {
1250
1251
$ code = str_replace ('$parameters = [] ' , "\$targetDir; \n protected \$parameters = [] " , $ code );
@@ -1389,6 +1390,24 @@ public function getRemovedIds(): array
1389
1390
EOF ;
1390
1391
}
1391
1392
1393
+ private function addDeprecatedParameters (): string
1394
+ {
1395
+ if (!($ bag = $ this ->container ->getParameterBag ()) instanceof ParameterBag) {
1396
+ return '' ;
1397
+ }
1398
+
1399
+ if (!$ deprecated = $ bag ->allDeprecated ()) {
1400
+ return '' ;
1401
+ }
1402
+ $ code = '' ;
1403
+ ksort ($ deprecated );
1404
+ foreach ($ deprecated as $ param => $ deprecation ) {
1405
+ $ code .= ' ' .$ this ->doExport ($ param ).' => [ ' .implode (', ' , array_map ($ this ->doExport (...), $ deprecation ))."], \n" ;
1406
+ }
1407
+
1408
+ return " private const DEPRECATED_PARAMETERS = [ \n{$ code } ]; \n\n" ;
1409
+ }
1410
+
1392
1411
private function addMethodMap (): string
1393
1412
{
1394
1413
$ code = '' ;
@@ -1550,6 +1569,10 @@ private function addDefaultParametersMethod(): string
1550
1569
1551
1570
public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
1552
1571
{
1572
+ if (isset(self::DEPRECATED_PARAMETERS[$name])) {
1573
+ trigger_deprecation(...self::DEPRECATED_PARAMETERS[$name]);
1574
+ }
1575
+
1553
1576
if (isset($this->buildParameters[$name])) {
1554
1577
return $this->buildParameters[$name];
1555
1578
}
@@ -1588,17 +1611,23 @@ public function getParameterBag(): ParameterBagInterface
1588
1611
foreach ($this->buildParameters as $name => $value) {
1589
1612
$parameters[$name] = $value;
1590
1613
}
1591
- $this->parameterBag = new FrozenParameterBag($parameters);
1614
+ $this->parameterBag = new FrozenParameterBag($parameters, self::DEPRECATED_PARAMETERS );
1592
1615
}
1593
1616
1594
1617
return $this->parameterBag;
1595
1618
}
1596
1619
1597
1620
EOF;
1621
+
1598
1622
if (!$ this ->asFiles ) {
1599
1623
$ code = preg_replace ('/^.*buildParameters.*\n.*\n.*\n\n?/m ' , '' , $ code );
1600
1624
}
1601
1625
1626
+ if (!($ bag = $ this ->container ->getParameterBag ()) instanceof ParameterBag || !$ bag ->allDeprecated ()) {
1627
+ $ code = preg_replace ("/ \n.*DEPRECATED_PARAMETERS.* \n.* \n.* \n/m " , '' , $ code , 1 );
1628
+ $ code = str_replace (', self::DEPRECATED_PARAMETERS ' , '' , $ code );
1629
+ }
1630
+
1602
1631
if ($ dynamicPhp ) {
1603
1632
$ loadedDynamicParameters = $ this ->exportParameters (array_combine (array_keys ($ dynamicPhp ), array_fill (0 , \count ($ dynamicPhp ), false )), '' , 8 );
1604
1633
$ getDynamicParameter = <<<'EOF'
0 commit comments