Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2a6d2d4

Browse filesBrowse files
committed
Add support for displaying nested options in DebugCommand
1 parent c0c0a8f commit 2a6d2d4
Copy full SHA for 2a6d2d4

17 files changed

+104
-9
lines changed

‎src/Symfony/Component/Form/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add support for displaying nested options in DebugCommand
8+
49
7.2
510
---
611

‎src/Symfony/Component/Form/Console/Descriptor/Descriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Console/Descriptor/Descriptor.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ protected function getOptionDefinition(OptionsResolver $optionsResolver, string
118118
'allowedValues' => 'getAllowedValues',
119119
'normalizers' => 'getNormalizers',
120120
'deprecation' => 'getDeprecation',
121+
'nestedOptions' => 'getNestedOptions',
121122
];
122123

123124
foreach ($map as $key => $method) {

‎src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ protected function describeResolvedFormType(ResolvedFormTypeInterface $resolvedF
6262
}
6363

6464
protected function describeOption(OptionsResolver $optionsResolver, array $options): void
65+
{
66+
$data = $this->getOptionDescription($optionsResolver, $options);
67+
$this->writeData($data, $options);
68+
}
69+
70+
private function getOptionDescription(OptionsResolver $optionsResolver, array $options): array
6571
{
6672
$definition = $this->getOptionDefinition($optionsResolver, $options['option']);
6773

@@ -90,7 +96,17 @@ protected function describeOption(OptionsResolver $optionsResolver, array $optio
9096
}
9197
$data['has_normalizer'] = isset($definition['normalizers']);
9298

93-
$this->writeData($data, $options);
99+
if ($data['has_nested_options'] = isset($definition['nestedOptions'])) {
100+
$nestedResolver = new OptionsResolver();
101+
foreach ($definition['nestedOptions'] as $nestedOption) {
102+
$nestedOption($nestedResolver, $optionsResolver);
103+
}
104+
foreach ($nestedResolver->getDefinedOptions() as $option) {
105+
$data['nested_options'][$option] = $this->getOptionDescription($nestedResolver, ['option' => $option]);
106+
}
107+
}
108+
109+
return $data;
94110
}
95111

96112
private function writeData(array $data, array $options): void

‎src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,19 @@ protected function describeOption(OptionsResolver $optionsResolver, array $optio
118118
'Allowed types' => 'allowedTypes',
119119
'Allowed values' => 'allowedValues',
120120
'Normalizers' => 'normalizers',
121+
'Nested Options' => 'nestedOptions',
121122
];
122123
$rows = [];
123124
foreach ($map as $label => $name) {
124125
$value = \array_key_exists($name, $definition) ? $dump($definition[$name]) : '-';
125126
if ('default' === $name && isset($definition['lazy'])) {
126127
$value = "Value: $value\n\nClosure(s): ".$dump($definition['lazy']);
128+
} elseif ('nestedOptions' === $name && isset($definition['nestedOptions'])) {
129+
$nestedResolver = new OptionsResolver();
130+
foreach ($definition['nestedOptions'] as $nestedOption) {
131+
$nestedOption($nestedResolver, $optionsResolver);
132+
}
133+
$value = $dump($nestedResolver->getDefinedOptions());
127134
}
128135

129136
$rows[] = ["<info>$label</info>", $value];

‎src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ class:%s
179179
} %s
180180
] %s
181181
---------------- -----------%s
182+
Nested Options - %s
183+
---------------- -----------%s
182184

183185
TXT
184186
, $tester->getDisplay(true));

‎src/Symfony/Component/Form/Tests/Console/Descriptor/AbstractDescriptorTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Console/Descriptor/AbstractDescriptorTestCase.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public static function getDescribeOptionTestData()
130130
$options['option'] = 'bar';
131131
$options['show_deprecated'] = true;
132132
yield [$resolvedType->getOptionsResolver(), $options, 'deprecated_option'];
133+
134+
$resolvedType = new ResolvedFormType(new FooType(), [], $parent);
135+
$options['type'] = $resolvedType->getInnerType();
136+
$options['option'] = 'baz';
137+
yield [$resolvedType->getOptionsResolver(), $options, 'nested_option'];
133138
}
134139

135140
abstract protected function getDescriptor();
@@ -172,5 +177,9 @@ public function configureOptions(OptionsResolver $resolver): void
172177
$resolver->setAllowedTypes('foo', 'string');
173178
$resolver->setAllowedValues('foo', ['bar', 'baz']);
174179
$resolver->setNormalizer('foo', fn (Options $options, $value) => (string) $value);
180+
$resolver->setOptions('baz', function (OptionsResolver $baz) {
181+
$baz->setRequired('foo');
182+
$baz->setDefaults(['foo' => true, 'bar' => true]);
183+
});
175184
}
176185
}

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/default_option_with_normalizer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/default_option_with_normalizer.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"bool",
88
"string"
99
],
10-
"has_normalizer": true
10+
"has_normalizer": true,
11+
"has_nested_options": false
1112
}

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/default_option_with_normalizer.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/default_option_with_normalizer.txt
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (choice_translation_domain
2525
} %s
2626
] %s
2727
---------------- -----------%s
28+
Nested Options - %s
29+
---------------- -----------%s
2830

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/deprecated_option.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/deprecated_option.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"deprecated": true,
33
"deprecation_message": "The option \"bar\" is deprecated.",
44
"required": false,
5-
"has_normalizer": false
5+
"has_normalizer": false,
6+
"has_nested_options": false
67
}

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/deprecated_option.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/deprecated_option.txt
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ Symfony\Component\Form\Tests\Console\Descriptor\FooType (bar)
2121
Allowed values -
2222
--------------------- -----------------------------------
2323
Normalizers -
24-
--------------------- -----------------------------------
24+
--------------------- -----------------------------------
25+
Nested Options -
26+
--------------------- -----------------------------------
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"required": false,
3+
"default": [],
4+
"is_lazy": false,
5+
"has_normalizer": false,
6+
"has_nested_options": true,
7+
"nested_options": {
8+
"foo": {
9+
"required": true,
10+
"default": true,
11+
"is_lazy": false,
12+
"has_normalizer": false,
13+
"has_nested_options": false
14+
},
15+
"bar": {
16+
"required": false,
17+
"default": true,
18+
"is_lazy": false,
19+
"has_normalizer": false,
20+
"has_nested_options": false
21+
}
22+
}
23+
}
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Symfony\Component\Form\Tests\Console\Descriptor\FooType (baz)
2+
=============================================================
3+
4+
---------------- ----------
5+
Info -
6+
---------------- ----------
7+
Required false
8+
---------------- ----------
9+
Default []
10+
---------------- ----------
11+
Allowed types -
12+
---------------- ----------
13+
Allowed values -
14+
---------------- ----------
15+
Normalizers -
16+
---------------- ----------
17+
Nested Options [
18+
"foo",
19+
"bar"
20+
]
21+
---------------- ----------

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/overridden_option_with_default_closures.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/overridden_option_with_default_closures.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"required": false,
33
"default": null,
44
"is_lazy": true,
5-
"has_normalizer": false
5+
"has_normalizer": false,
6+
"has_nested_options": false
67
}

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/overridden_option_with_default_closures.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/overridden_option_with_default_closures.txt
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Symfony\Component\Form\Tests\Console\Descriptor\FooType (empty_data)
2323
---------------- ----------------------%s
2424
Allowed values - %s
2525
---------------- ----------------------%s
26-
Normalizers - %s
26+
Normalizers - %s
27+
---------------- ----------------------%s
28+
Nested Options - %s
2729
---------------- ----------------------%s
2830

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/required_option_with_allowed_values.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/required_option_with_allowed_values.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"bar",
88
"baz"
99
],
10-
"has_normalizer": true
10+
"has_normalizer": true,
11+
"has_nested_options": false
1112
}

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/required_option_with_allowed_values.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/required_option_with_allowed_values.txt
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ Symfony\Component\Form\Tests\Console\Descriptor\FooType (foo)
2727
} %s
2828
] %s
2929
---------------- -----------%s
30-
30+
Nested Options - %s
31+
---------------- -----------%s

‎src/Symfony/Component/Form/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=8.2",
2020
"symfony/deprecation-contracts": "^2.5|^3",
2121
"symfony/event-dispatcher": "^6.4|^7.0",
22-
"symfony/options-resolver": "^6.4|^7.0",
22+
"symfony/options-resolver": "^7.3",
2323
"symfony/polyfill-ctype": "~1.8",
2424
"symfony/polyfill-intl-icu": "^1.21",
2525
"symfony/polyfill-mbstring": "~1.0",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.