-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Config] Generated php configs incorrectly using list param types #61533
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
Draft
KevinVanSonsbeek
wants to merge
10
commits into
symfony:6.4
Choose a base branch
from
KevinVanSonsbeek:bugfix/61136-php-configs-incorrectly-using-list-param-types
base: 6.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dc9b9fe
bugfix(61136): Expose the normalizeKeys option to the public api
KevinVanSonsbeek 6e91127
bugfix(61136): Add tests that fail without the fix
KevinVanSonsbeek 33a0729
bugfix(61136): Base the iterable type on the normalizeKeys config option
KevinVanSonsbeek 10f8b3a
bugfix(61136): Add whitespace back
KevinVanSonsbeek d3eaf2b
bugfix(61136): Roll back previous changes
KevinVanSonsbeek e209ae6
bugfix(61136): Add the config to use the attribute as key
KevinVanSonsbeek ad7af98
bugfix(61136): Roll back missed changes
KevinVanSonsbeek 3487963
bugfix(61136): Add test case that reflects the metadata from the work…
KevinVanSonsbeek db29d51
bugfix(61136): Add expected config and output
KevinVanSonsbeek 95a31e0
bugfix(61136): Generate new test files
KevinVanSonsbeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ent/Config/Tests/Builder/Fixtures/ArrayValues/Symfony/Config/ArrayValues/PlacesConfig.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Symfony\Config\ArrayValues; | ||
|
||
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 PlacesConfig | ||
{ | ||
private $name; | ||
private $metadata; | ||
private $_usedProperties = []; | ||
|
||
/** | ||
* @default null | ||
* @param ParamConfigurator|mixed $value | ||
* @return $this | ||
*/ | ||
public function name($value): static | ||
{ | ||
$this->_usedProperties['name'] = true; | ||
$this->name = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function metadata(string $key, mixed $value): static | ||
{ | ||
$this->_usedProperties['metadata'] = true; | ||
$this->metadata[$key] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function __construct(array $value = []) | ||
{ | ||
if (array_key_exists('name', $value)) { | ||
$this->_usedProperties['name'] = true; | ||
$this->name = $value['name']; | ||
unset($value['name']); | ||
} | ||
|
||
if (array_key_exists('metadata', $value)) { | ||
$this->_usedProperties['metadata'] = true; | ||
$this->metadata = $value['metadata']; | ||
unset($value['metadata']); | ||
} | ||
|
||
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['name'])) { | ||
$output['name'] = $this->name; | ||
} | ||
if (isset($this->_usedProperties['metadata'])) { | ||
$output['metadata'] = $this->metadata; | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@stof Adding the
useAttributeAsKey
would allow us to set specific metadata by key when using the config builder.But we'd lose out on the ability to set all metadata in 1 call if we already created an instance of the parent node builder.
This is due to the generated config changing from
To
Would a breaking change like this be a problem for a bugfix? (cc @nicolas-grekas )
As a sidenote, a update to the workflow docs would also be required in the case we would want to perform these changes.
As it shows some examples for the php configs setting the metadata as an array. And we would lose this option.
The XML config in general seems to be broken when parsing though. The example showed on the doc page shows nodes, that should actually be attributes.
But having a combination of place nodes, with and without metadata seems to actually break when using XML config, due to the callbacks used in the
beforeNormalization
possibly not accounting properly for the differences in data structure of the passed$places
var, depending on the type of config used :(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.
Small example of the data contained in the
$places
argument of the normalization callback, when using the example configs from the docs: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.
it would yes, since that'd break existing configs
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.
Mhm, that does create an issue then tbh. As i'm not really sure how to fix the return type, if we cannot add the
useAttributeAsKey
, seeing how the normalizeKeys was not a preferable way to detect the difference.Adding a new option we could set to indicate a list or array kinda feels like a bandaid fix, tiptoeing around the problem that the config might just be incorrectly defined to begin with.
I also don't see a clear way to mark methods generated by the builder as deprecated. So we could replace it in the next major. Atleast not without deprecating the entire node, which i don't want, as we still want the node, but differently configured :/