Skip to content

Commit 22850bf

Browse files
Merge branch '5.4' into 6.0
* 5.4: Revert "bug #45813 [HttpClient] Move Content-Type after Content-Length (nicolas-grekas)" [FrameworkBundle] Fix exit codes in debug:translation command [Cache] Declaratively declare/hide DoctrineProvider to avoid breaking static analysis [HttpClient] Let curl handle Content-Length headers Improve testsuite [HttpClient] Move Content-Type after Content-Length [HttpClient] minor cs fix [Config] Fix using null values with config builders
2 parents c14f32a + 05624c3 commit 22850bf

File tree

26 files changed

+253
-110
lines changed

26 files changed

+253
-110
lines changed

Builder/ClassBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function build(): string
9090
USE
9191
9292
/**
93-
* This class is automatically generated to help creating config.
93+
* This class is automatically generated to help in creating a config.
9494
*/
9595
class CLASS IMPLEMENTS
9696
{
@@ -121,14 +121,15 @@ public function addMethod(string $name, string $body, array $params = []): void
121121
$this->methods[] = new Method(strtr($body, ['NAME' => $this->camelCase($name)] + $params));
122122
}
123123

124-
public function addProperty(string $name, string $classType = null): Property
124+
public function addProperty(string $name, string $classType = null, string $defaultValue = null): Property
125125
{
126126
$property = new Property($name, '_' !== $name[0] ? $this->camelCase($name) : $name);
127127
if (null !== $classType) {
128128
$property->setType($classType);
129129
}
130130
$this->properties[] = $property;
131-
$property->setContent(sprintf('private $%s;', $property->getName()));
131+
$defaultValue = null !== $defaultValue ? sprintf(' = %s', $defaultValue) : '';
132+
$property->setContent(sprintf('private $%s%s;', $property->getName(), $defaultValue));
132133

133134
return $property;
134135
}

Builder/ConfigBuilderGenerator.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
*/
3232
class ConfigBuilderGenerator implements ConfigBuilderGeneratorInterface
3333
{
34+
/**
35+
* @var ClassBuilder[]
36+
*/
3437
private array $classes = [];
3538
private string $outputDir;
3639

@@ -89,6 +92,9 @@ private function writeClasses(): void
8992
foreach ($this->classes as $class) {
9093
$this->buildConstructor($class);
9194
$this->buildToArray($class);
95+
if ($class->getProperties()) {
96+
$class->addProperty('_usedProperties', null, '[]');
97+
}
9298
$this->buildSetExtraKey($class);
9399

94100
file_put_contents($this->getFullPath($class), $class->build());
@@ -135,6 +141,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
135141
public function NAME(array $value = []): CLASS
136142
{
137143
if (null === $this->PROPERTY) {
144+
$this->_usedProperties[\'PROPERTY\'] = true;
138145
$this->PROPERTY = new CLASS($value);
139146
} elseif ([] !== $value) {
140147
throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\');
@@ -161,6 +168,7 @@ private function handleVariableNode(VariableNode $node, ClassBuilder $class): vo
161168
*/
162169
public function NAME(mixed $valueDEFAULT): static
163170
{
171+
$this->_usedProperties[\'PROPERTY\'] = true;
164172
$this->PROPERTY = $value;
165173
166174
return $this;
@@ -188,6 +196,7 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild
188196
*/
189197
public function NAME(ParamConfigurator|array $value): static
190198
{
199+
$this->_usedProperties[\'PROPERTY\'] = true;
191200
$this->PROPERTY = $value;
192201
193202
return $this;
@@ -201,6 +210,7 @@ public function NAME(ParamConfigurator|array $value): static
201210
*/
202211
public function NAME(string $VAR, TYPE $VALUE): static
203212
{
213+
$this->_usedProperties[\'PROPERTY\'] = true;
204214
$this->PROPERTY[$VAR] = $VALUE;
205215
206216
return $this;
@@ -224,6 +234,8 @@ public function NAME(string $VAR, TYPE $VALUE): static
224234
$body = '
225235
public function NAME(array $value = []): CLASS
226236
{
237+
$this->_usedProperties[\'PROPERTY\'] = true;
238+
227239
return $this->PROPERTY[] = new CLASS($value);
228240
}';
229241
$class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn()]);
@@ -232,9 +244,11 @@ public function NAME(array $value = []): CLASS
232244
public function NAME(string $VAR, array $VALUE = []): CLASS
233245
{
234246
if (!isset($this->PROPERTY[$VAR])) {
235-
return $this->PROPERTY[$VAR] = new CLASS($value);
247+
$this->_usedProperties[\'PROPERTY\'] = true;
248+
249+
return $this->PROPERTY[$VAR] = new CLASS($VALUE);
236250
}
237-
if ([] === $value) {
251+
if ([] === $VALUE) {
238252
return $this->PROPERTY[$VAR];
239253
}
240254
@@ -259,6 +273,7 @@ private function handleScalarNode(ScalarNode $node, ClassBuilder $class): void
259273
*/
260274
public function NAME($value): static
261275
{
276+
$this->_usedProperties[\'PROPERTY\'] = true;
262277
$this->PROPERTY = $value;
263278
264279
return $this;
@@ -368,7 +383,7 @@ private function buildToArray(ClassBuilder $class): void
368383
}
369384

370385
$body .= strtr('
371-
if (null !== $this->PROPERTY) {
386+
if (isset($this->_usedProperties[\'PROPERTY\'])) {
372387
$output[\'ORG_NAME\'] = '.$code.';
373388
}', ['PROPERTY' => $p->getName(), 'ORG_NAME' => $p->getOriginalName()]);
374389
}
@@ -398,7 +413,8 @@ private function buildConstructor(ClassBuilder $class): void
398413
}
399414

400415
$body .= strtr('
401-
if (isset($value[\'ORG_NAME\'])) {
416+
if (array_key_exists(\'ORG_NAME\', $value)) {
417+
$this->_usedProperties[\'PROPERTY\'] = true;
402418
$this->PROPERTY = '.$code.';
403419
unset($value[\'ORG_NAME\']);
404420
}
@@ -443,11 +459,7 @@ private function buildSetExtraKey(ClassBuilder $class): void
443459
*/
444460
public function NAME(string $key, mixed $value): static
445461
{
446-
if (null === $value) {
447-
unset($this->_extraKeys[$key]);
448-
} else {
449-
$this->_extraKeys[$key] = $value;
450-
}
462+
$this->_extraKeys[$key] = $value;
451463
452464
return $this;
453465
}');

Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99

1010
/**
11-
* This class is automatically generated to help creating config.
11+
* This class is automatically generated to help in creating a config.
1212
*/
1313
class ReceivingConfig
1414
{
1515
private $priority;
1616
private $color;
17+
private $_usedProperties = [];
1718

1819
/**
1920
* @default null
@@ -22,6 +23,7 @@ class ReceivingConfig
2223
*/
2324
public function priority($value): static
2425
{
26+
$this->_usedProperties['priority'] = true;
2527
$this->priority = $value;
2628

2729
return $this;
@@ -34,6 +36,7 @@ public function priority($value): static
3436
*/
3537
public function color($value): static
3638
{
39+
$this->_usedProperties['color'] = true;
3740
$this->color = $value;
3841

3942
return $this;
@@ -42,12 +45,14 @@ public function color($value): static
4245
public function __construct(array $value = [])
4346
{
4447

45-
if (isset($value['priority'])) {
48+
if (array_key_exists('priority', $value)) {
49+
$this->_usedProperties['priority'] = true;
4650
$this->priority = $value['priority'];
4751
unset($value['priority']);
4852
}
4953

50-
if (isset($value['color'])) {
54+
if (array_key_exists('color', $value)) {
55+
$this->_usedProperties['color'] = true;
5156
$this->color = $value['color'];
5257
unset($value['color']);
5358
}
@@ -60,10 +65,10 @@ public function __construct(array $value = [])
6065
public function toArray(): array
6166
{
6267
$output = [];
63-
if (null !== $this->priority) {
68+
if (isset($this->_usedProperties['priority'])) {
6469
$output['priority'] = $this->priority;
6570
}
66-
if (null !== $this->color) {
71+
if (isset($this->_usedProperties['color'])) {
6772
$output['color'] = $this->color;
6873
}
6974

Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99

1010
/**
11-
* This class is automatically generated to help creating config.
11+
* This class is automatically generated to help in creating a config.
1212
*/
1313
class RoutingConfig
1414
{
1515
private $senders;
16+
private $_usedProperties = [];
1617

1718
/**
1819
* @param ParamConfigurator|list<ParamConfigurator|mixed> $value
@@ -21,6 +22,7 @@ class RoutingConfig
2122
*/
2223
public function senders(ParamConfigurator|array $value): static
2324
{
25+
$this->_usedProperties['senders'] = true;
2426
$this->senders = $value;
2527

2628
return $this;
@@ -29,7 +31,8 @@ public function senders(ParamConfigurator|array $value): static
2931
public function __construct(array $value = [])
3032
{
3133

32-
if (isset($value['senders'])) {
34+
if (array_key_exists('senders', $value)) {
35+
$this->_usedProperties['senders'] = true;
3336
$this->senders = $value['senders'];
3437
unset($value['senders']);
3538
}
@@ -42,7 +45,7 @@ public function __construct(array $value = [])
4245
public function toArray(): array
4346
{
4447
$output = [];
45-
if (null !== $this->senders) {
48+
if (isset($this->_usedProperties['senders'])) {
4649
$output['senders'] = $this->senders;
4750
}
4851

Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99

1010

1111
/**
12-
* This class is automatically generated to help creating config.
12+
* This class is automatically generated to help in creating a config.
1313
*/
1414
class MessengerConfig
1515
{
1616
private $routing;
1717
private $receiving;
18+
private $_usedProperties = [];
1819

1920
public function routing(string $message_class, array $value = []): \Symfony\Config\AddToList\Messenger\RoutingConfig
2021
{
2122
if (!isset($this->routing[$message_class])) {
23+
$this->_usedProperties['routing'] = true;
24+
2225
return $this->routing[$message_class] = new \Symfony\Config\AddToList\Messenger\RoutingConfig($value);
2326
}
2427
if ([] === $value) {
@@ -30,18 +33,22 @@ public function routing(string $message_class, array $value = []): \Symfony\Conf
3033

3134
public function receiving(array $value = []): \Symfony\Config\AddToList\Messenger\ReceivingConfig
3235
{
36+
$this->_usedProperties['receiving'] = true;
37+
3338
return $this->receiving[] = new \Symfony\Config\AddToList\Messenger\ReceivingConfig($value);
3439
}
3540

3641
public function __construct(array $value = [])
3742
{
3843

39-
if (isset($value['routing'])) {
44+
if (array_key_exists('routing', $value)) {
45+
$this->_usedProperties['routing'] = true;
4046
$this->routing = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\RoutingConfig($v); }, $value['routing']);
4147
unset($value['routing']);
4248
}
4349

44-
if (isset($value['receiving'])) {
50+
if (array_key_exists('receiving', $value)) {
51+
$this->_usedProperties['receiving'] = true;
4552
$this->receiving = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\ReceivingConfig($v); }, $value['receiving']);
4653
unset($value['receiving']);
4754
}
@@ -54,10 +61,10 @@ public function __construct(array $value = [])
5461
public function toArray(): array
5562
{
5663
$output = [];
57-
if (null !== $this->routing) {
64+
if (isset($this->_usedProperties['routing'])) {
5865
$output['routing'] = array_map(function ($v) { return $v->toArray(); }, $this->routing);
5966
}
60-
if (null !== $this->receiving) {
67+
if (isset($this->_usedProperties['receiving'])) {
6168
$output['receiving'] = array_map(function ($v) { return $v->toArray(); }, $this->receiving);
6269
}
6370

Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99

1010
/**
11-
* This class is automatically generated to help creating config.
11+
* This class is automatically generated to help in creating a config.
1212
*/
1313
class TranslatorConfig
1414
{
1515
private $fallbacks;
1616
private $sources;
17+
private $_usedProperties = [];
1718

1819
/**
1920
* @param ParamConfigurator|list<ParamConfigurator|mixed> $value
@@ -22,6 +23,7 @@ class TranslatorConfig
2223
*/
2324
public function fallbacks(ParamConfigurator|array $value): static
2425
{
26+
$this->_usedProperties['fallbacks'] = true;
2527
$this->fallbacks = $value;
2628

2729
return $this;
@@ -32,6 +34,7 @@ public function fallbacks(ParamConfigurator|array $value): static
3234
*/
3335
public function source(string $source_class, mixed $value): static
3436
{
37+
$this->_usedProperties['sources'] = true;
3538
$this->sources[$source_class] = $value;
3639

3740
return $this;
@@ -40,12 +43,14 @@ public function source(string $source_class, mixed $value): static
4043
public function __construct(array $value = [])
4144
{
4245

43-
if (isset($value['fallbacks'])) {
46+
if (array_key_exists('fallbacks', $value)) {
47+
$this->_usedProperties['fallbacks'] = true;
4448
$this->fallbacks = $value['fallbacks'];
4549
unset($value['fallbacks']);
4650
}
4751

48-
if (isset($value['sources'])) {
52+
if (array_key_exists('sources', $value)) {
53+
$this->_usedProperties['sources'] = true;
4954
$this->sources = $value['sources'];
5055
unset($value['sources']);
5156
}
@@ -58,10 +63,10 @@ public function __construct(array $value = [])
5863
public function toArray(): array
5964
{
6065
$output = [];
61-
if (null !== $this->fallbacks) {
66+
if (isset($this->_usedProperties['fallbacks'])) {
6267
$output['fallbacks'] = $this->fallbacks;
6368
}
64-
if (null !== $this->sources) {
69+
if (isset($this->_usedProperties['sources'])) {
6570
$output['sources'] = $this->sources;
6671
}
6772

0 commit comments

Comments
 (0)