20
20
use Symfony \Component \Console \Style \SymfonyStyle ;
21
21
use Symfony \Component \Finder \Finder ;
22
22
use Symfony \UX \LiveComponent \Attribute \AsLiveComponent ;
23
+ use Symfony \UX \LiveComponent \Attribute \LiveAction ;
23
24
use Symfony \UX \LiveComponent \Attribute \LiveProp ;
24
25
use Symfony \UX \TwigComponent \Attribute \AsTwigComponent ;
26
+ use Symfony \UX \TwigComponent \Attribute \PostMount ;
27
+ use Symfony \UX \TwigComponent \Attribute \PreMount ;
25
28
use Symfony \UX \TwigComponent \ComponentFactory ;
26
29
use Symfony \UX \TwigComponent \Twig \PropsNode ;
27
30
use Twig \Environment ;
@@ -55,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
55
58
$ io = new SymfonyStyle ($ input , $ output );
56
59
$ name = $ input ->getArgument ('name ' );
57
60
58
- if ($ name ) {
61
+ if (null !== $ name ) {
59
62
try {
60
63
$ metadata = $ this ->componentFactory ->metadataFor ($ name );
61
64
} catch (\Exception $ e ) {
@@ -69,7 +72,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
69
72
$ allProperties = [];
70
73
71
74
if ($ class ) {
72
- $ propertyLabel = 'Properties (type / name / default value if exist) ' ;
73
75
$ type = 'AsTwigComponent ' ;
74
76
75
77
if ($ metadata ->get ('live ' )) {
@@ -90,21 +92,40 @@ protected function execute(InputInterface $input, OutputInterface $output): int
90
92
$ propertyDisplay = $ visibility .' $ ' .$ propertyName .(null !== $ value ? ' = ' .$ value : '' );
91
93
92
94
if (\count ($ propertyAttributes ) > 0 ) {
93
- $ allLiveProperties = [
94
- ...$ allLiveProperties ,
95
- $ propertyDisplay ,
96
- ];
95
+ $ allLiveProperties [] = $ propertyDisplay ;
97
96
} else {
98
- $ allProperties = [
99
- ...$ allProperties ,
100
- $ propertyDisplay ,
101
- ];
97
+ $ allProperties [] = $ propertyDisplay ;
102
98
}
103
99
}
104
100
}
105
- } else {
106
- $ propertyLabel = 'Properties (name / default value if exist) ' ;
107
101
102
+ $ methods = $ reflectionClass ->getMethods ();
103
+ $ allEvents = [];
104
+ $ allActions = [];
105
+
106
+ foreach ($ methods as $ method ) {
107
+ if ('mount ' === $ method ->getName ()) {
108
+ $ allEvents [] = 'Mount ' ;
109
+ }
110
+
111
+ foreach ($ method ->getAttributes () as $ attribute ) {
112
+ if (PreMount::class === $ attribute ->getName ()) {
113
+ $ allEvents [] = 'PreMount ' ;
114
+ break ;
115
+ }
116
+
117
+ if (PostMount::class === $ attribute ->getName ()) {
118
+ $ allEvents [] = 'PostMount ' ;
119
+ break ;
120
+ }
121
+
122
+ if (LiveAction::class === $ attribute ->getName ()) {
123
+ $ allActions [] = $ method ->getName ();
124
+ break ;
125
+ }
126
+ }
127
+ }
128
+ } else {
108
129
$ source = $ this ->twigEnvironment ->load ($ metadata ->getTemplate ())->getSourceContext ();
109
130
$ tokenStream = $ this ->twigEnvironment ->tokenize ($ source );
110
131
$ bodyNode = $ this ->twigEnvironment ->parse ($ tokenStream )->getNode ('body ' )->getNode (0 );
@@ -134,10 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134
155
$ property = $ variable ;
135
156
}
136
157
137
- $ allProperties = [
138
- ...$ allProperties ,
139
- $ property ,
140
- ];
158
+ $ allProperties [] = $ property ;
141
159
}
142
160
}
143
161
}
@@ -147,20 +165,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
147
165
['Type ' , $ type ],
148
166
['Class ' , $ class ?? 'Anonymous component ' ],
149
167
['Template ' , $ metadata ->getTemplate ()],
150
- [$ propertyLabel , \count ($ allProperties ) > 0 ? implode ("\n" , $ allProperties ) : null ],
168
+ [' Properties ' , \count ($ allProperties ) > 0 ? implode ("\n" , $ allProperties ) : null ],
151
169
];
152
170
153
171
if (isset ($ allLiveProperties ) && \count ($ allLiveProperties ) > 0 ) {
154
172
$ componentInfos [] = ['Live Properties ' , implode ("\n" , $ allLiveProperties )];
155
173
}
156
-
157
- $ table = new Table ($ output );
158
- $ table ->setHeaders (['Property ' , 'Value ' ]);
159
-
160
- foreach ($ componentInfos as $ info ) {
161
- $ table ->addRow ($ info );
174
+ if (isset ($ allEvents ) && \count ($ allEvents ) > 0 ) {
175
+ $ componentInfos [] = ['Events ' , implode ("\n" , $ allEvents )];
176
+ }
177
+ if (isset ($ allActions ) && \count ($ allActions ) > 0 ) {
178
+ $ componentInfos [] = ['LiveAction Methods ' , implode ("\n" , $ allActions )];
162
179
}
163
180
181
+ $ table = new Table ($ output );
182
+ $ table ->setHeaders (['Property ' , 'Value ' ])->setRows ($ componentInfos );
164
183
$ table ->render ();
165
184
166
185
return Command::SUCCESS ;
@@ -226,23 +245,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
226
245
foreach ($ allComponents as $ component ) {
227
246
$ metadata = $ this ->componentFactory ->metadataFor ($ component ['name ' ]);
228
247
229
- $ dataToRender = [...$ dataToRender ,
230
- [
231
- $ metadata ->getName (),
232
- $ metadata ->get ('class ' ) ?? 'Anonymous component ' ,
233
- $ metadata ->getTemplate (),
234
- $ component ['type ' ],
235
- ],
248
+ $ dataToRender [] = [
249
+ $ metadata ->getName (),
250
+ $ metadata ->get ('class ' ) ?? 'Anonymous component ' ,
251
+ $ metadata ->getTemplate (),
252
+ $ component ['type ' ],
236
253
];
237
254
}
238
255
239
256
$ table = new Table ($ output );
240
- $ table ->setHeaders (['Component ' , 'Class ' , 'Template ' , 'Type ' ]);
241
-
242
- foreach ($ dataToRender as $ data ) {
243
- $ table ->addRow ($ data );
244
- }
245
-
257
+ $ table ->setHeaders (['Component ' , 'Class ' , 'Template ' , 'Type ' ])->setRows ($ dataToRender );
246
258
$ table ->render ();
247
259
248
260
return Command::SUCCESS ;
0 commit comments