You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was merged into the 5.4 branch.
Discussion
----------
[Config] Allow scalar configuration in PHP Configuration
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fixsymfony/monolog-bundle#417 (comment)
| License | MIT
| Doc PR | -
Fixes passing scalar values to array nodes that have a `beforeNormalization` hook, eg:
```php
return static function (MonologConfig $config): void {
$config->handler('console')
// ...
->processPsr3Messages()
->enabled(true)
;
};
```
can be shortened thanks to a [`beforeNormalization` hook](https://github.com/symfony/monolog-bundle/blob/a41bbcdc1105603b6d73a7d9a43a3788f8e0fb7d/DependencyInjection/Configuration.php#L453):
```php
return static function (MonologConfig $config): void {
$config->handler('console')
// ...
->processPsr3Messages(true)
;
};
```
I've used some of the code from #44166 by `@jderusse`. Since his PR is a feature it can't go on 5.4, but it still helped a lot.
Commits
-------
2d81a3a [Config] Allow scalar configuration in PHP Configuration
1c176e1 [Config] Allow scalar configuration in PHP Configuration
throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\');
162
+
}
163
+
164
+
return $this->PROPERTY;
165
+
}' : '
141
166
public function NAME(array $value = []): CLASS
142
167
{
143
168
if (null === $this->PROPERTY) {
144
169
$this->_usedProperties[\'PROPERTY\'] = true;
145
170
$this->PROPERTY = new CLASS($value);
146
-
} elseif ([] !== $value) {
171
+
} elseif (0 < \func_num_args()) {
147
172
throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\');
148
173
}
149
174
@@ -227,10 +252,29 @@ public function NAME(string $VAR, $VALUE): self
public function NAME(string $VAR, array $VALUE = []): CLASS
286
+
$body = $hasNormalizationClosures ? '
287
+
/**
288
+
* @return CLASS|$this
289
+
*/
290
+
public function NAME(string $VAR, $VALUE = [])
244
291
{
245
-
if (!isset($this->PROPERTY[$VAR])) {
292
+
if (!\is_array($VALUE)) {
246
293
$this->_usedProperties[\'PROPERTY\'] = true;
294
+
$this->PROPERTY[$VAR] = $VALUE;
247
295
248
-
return $this->PROPERTY[$VAR] = new CLASS($VALUE);
296
+
return $this;
249
297
}
250
-
if ([] === $VALUE) {
251
-
return $this->PROPERTY[$VAR];
298
+
299
+
if (!isset($this->PROPERTY[$VAR]) || !$this->PROPERTY[$VAR] instanceof CLASS) {
300
+
$this->_usedProperties[\'PROPERTY\'] = true;
301
+
$this->PROPERTY[$VAR] = new CLASS($VALUE);
302
+
} elseif (1 < \func_num_args()) {
303
+
throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\');
252
304
}
253
305
254
-
throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\');
306
+
return $this->PROPERTY[$VAR];
307
+
}' : '
308
+
public function NAME(string $VAR, array $VALUE = []): CLASS
309
+
{
310
+
if (!isset($this->PROPERTY[$VAR])) {
311
+
$this->_usedProperties[\'PROPERTY\'] = true;
312
+
$this->PROPERTY[$VAR] = new CLASS($VALUE);
313
+
} elseif (1 < \func_num_args()) {
314
+
throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\');
Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php
0 commit comments