-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Config] Fix generating PHP config for keyed list of scalars #60316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Config\ScalarNormalizedTypes\KeyedListScalarConfig; | ||
use Symfony\Config\ScalarNormalizedTypesConfig; | ||
|
||
return static function (ScalarNormalizedTypesConfig $config) { | ||
|
@@ -28,4 +29,10 @@ | |
'nested_object' => true, | ||
'nested_list_object' => ['one', 'two'], | ||
]); | ||
|
||
$config->keyedListScalar('Foo\\Bar')->list(['one', 'two']); | ||
$config->keyedListScalar('Foo\\Baz', ['list' => ['one', 'two']]); | ||
$keyedListScalarConfig = new KeyedListScalarConfig(); | ||
$keyedListScalarConfig->list(['one', 'two']); | ||
$config->keyedListScalar('Foo\\Foo', $keyedListScalarConfig); | ||
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really how configuration classes are meant to be used. They should never be manually instantiated. The main issue I see is that in some cases, public function transport(string $name, string|array $value = []): \Symfony\Config\Framework\Messenger\TransportConfig|static
{
// ...
} In other cases, it can only be an array. The proper fix would be to avoid including the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok got it, maybe then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, not sure about that one 🤔 |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Symfony\Config\ScalarNormalizedTypes; | ||
|
||
use Symfony\Component\Config\Loader\ParamConfigurator; | ||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; | ||
|
||
/** | ||
* This class is automatically generated to help in creating a config. | ||
*/ | ||
class KeyedListScalarConfig | ||
{ | ||
private $list; | ||
private $_usedProperties = []; | ||
|
||
/** | ||
* @param ParamConfigurator|list<ParamConfigurator|mixed> $value | ||
* | ||
* @return $this | ||
*/ | ||
public function list(ParamConfigurator|array $value): static | ||
{ | ||
$this->_usedProperties['list'] = true; | ||
$this->list = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function __construct(array $value = []) | ||
{ | ||
if (array_key_exists('list', $value)) { | ||
$this->_usedProperties['list'] = true; | ||
$this->list = $value['list']; | ||
unset($value['list']); | ||
} | ||
|
||
if ([] !== $value) { | ||
throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); | ||
} | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$output = []; | ||
if (isset($this->_usedProperties['list'])) { | ||
$output['list'] = $this->list; | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improvements like this don't qualify as bug fixes, so this should be a separate PR for 7.3 (or more likely 7.4, since 7.3 is now in feature freeze).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was searching for for some guide lines on what qualifies as bug, but I'm not sure, this seem to me like a bug, currently it's not possible to use some php configs with strict PHPStan, that said, I'm going to change the target to 7.3 or 7.4 (when branch is available)
Outside of target branch, do you think this is acceptable fix/improvement? Or do I need to do it in any other way?