File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -255,9 +255,14 @@ private function getComponentProperties(ComponentMetadata $metadata): array
255
255
$ propertyName = $ property ->getName ();
256
256
257
257
if ($ metadata ->isPublicPropsExposed () && $ property ->isPublic ()) {
258
- $ visibility = $ property ->getType ()?->getName();
258
+ $ type = $ property ->getType ();
259
+ if ($ type instanceof \ReflectionNamedType) {
260
+ $ typeName = $ type ->getName ();
261
+ } else {
262
+ $ typeName = (string ) $ type ;
263
+ }
259
264
$ value = $ property ->getDefaultValue ();
260
- $ propertyDisplay = $ visibility .' $ ' .$ propertyName .(null !== $ value ? ' = ' .json_encode ($ value ) : '' );
265
+ $ propertyDisplay = $ typeName .' $ ' .$ propertyName .(null !== $ value ? ' = ' .json_encode ($ value ) : '' );
261
266
$ properties [$ property ->name ] = $ propertyDisplay ;
262
267
}
263
268
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \UX \TwigComponent \Tests \Fixtures \Component ;
4
+
5
+ use Symfony \UX \TwigComponent \Attribute \AsTwigComponent ;
6
+
7
+ #[AsTwigComponent(name: 'union_type_props ' , exposePublicProps: true )]
8
+ final class UnionTypeProps
9
+ {
10
+ public string |bool $ prop1 ;
11
+ }
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ public function testWithAnonymousComponent(): void
141
141
$ this ->assertStringContainsString ('primary = true ' , $ display );
142
142
}
143
143
144
- public function testWithoutPublicPros (): void
144
+ public function testWithoutPublicProps (): void
145
145
{
146
146
$ commandTester = $ this ->createCommandTester ();
147
147
$ commandTester ->execute (['name ' => 'no_public_props ' ]);
@@ -173,6 +173,20 @@ public function testWithExposedVariables(): void
173
173
$ this ->assertStringNotContainsString ('prop3 ' , $ display );
174
174
}
175
175
176
+ public function testWithUnionTypeProps (): void
177
+ {
178
+ $ commandTester = $ this ->createCommandTester ();
179
+ $ commandTester ->execute (['name ' => 'union_type_props ' ]);
180
+
181
+ $ commandTester ->assertCommandIsSuccessful ();
182
+
183
+ $ display = $ commandTester ->getDisplay ();
184
+
185
+ $ this ->tableDisplayCheck ($ display );
186
+ $ this ->assertStringContainsString ('string|bool ' , $ display );
187
+ $ this ->assertStringContainsString ('prop1 ' , $ display );
188
+ }
189
+
176
190
private function createCommandTester (): CommandTester
177
191
{
178
192
$ kernel = self ::bootKernel ();
You can’t perform that action at this time.
0 commit comments