2020use Symfony \Component \Console \Style \SymfonyStyle ;
2121use Symfony \Component \Finder \Finder ;
2222use Symfony \UX \LiveComponent \Attribute \AsLiveComponent ;
23+ use Symfony \UX \LiveComponent \Attribute \LiveAction ;
2324use Symfony \UX \LiveComponent \Attribute \LiveProp ;
2425use Symfony \UX \TwigComponent \Attribute \AsTwigComponent ;
26+ use Symfony \UX \TwigComponent \Attribute \PostMount ;
27+ use Symfony \UX \TwigComponent \Attribute \PreMount ;
2528use Symfony \UX \TwigComponent \ComponentFactory ;
2629use Symfony \UX \TwigComponent \Twig \PropsNode ;
2730use Twig \Environment ;
@@ -55,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5558 $ io = new SymfonyStyle ($ input , $ output );
5659 $ name = $ input ->getArgument ('name ' );
5760
58- if ($ name ) {
61+ if (null !== $ name ) {
5962 try {
6063 $ metadata = $ this ->componentFactory ->metadataFor ($ name );
6164 } catch (\Exception $ e ) {
@@ -69,7 +72,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6972 $ allProperties = [];
7073
7174 if ($ class ) {
72- $ propertyLabel = 'Properties (type / name / default value if exist) ' ;
7375 $ type = 'AsTwigComponent ' ;
7476
7577 if ($ metadata ->get ('live ' )) {
@@ -90,21 +92,40 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9092 $ propertyDisplay = $ visibility .' $ ' .$ propertyName .(null !== $ value ? ' = ' .$ value : '' );
9193
9294 if (\count ($ propertyAttributes ) > 0 ) {
93- $ allLiveProperties = [
94- ...$ allLiveProperties ,
95- $ propertyDisplay ,
96- ];
95+ $ allLiveProperties [] = $ propertyDisplay ;
9796 } else {
98- $ allProperties = [
99- ...$ allProperties ,
100- $ propertyDisplay ,
101- ];
97+ $ allProperties [] = $ propertyDisplay ;
10298 }
10399 }
104100 }
105- } else {
106- $ propertyLabel = 'Properties (name / default value if exist) ' ;
107101
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 {
108129 $ source = $ this ->twigEnvironment ->load ($ metadata ->getTemplate ())->getSourceContext ();
109130 $ tokenStream = $ this ->twigEnvironment ->tokenize ($ source );
110131 $ bodyNode = $ this ->twigEnvironment ->parse ($ tokenStream )->getNode ('body ' )->getNode (0 );
@@ -134,10 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134155 $ property = $ variable ;
135156 }
136157
137- $ allProperties = [
138- ...$ allProperties ,
139- $ property ,
140- ];
158+ $ allProperties [] = $ property ;
141159 }
142160 }
143161 }
@@ -147,20 +165,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
147165 ['Type ' , $ type ],
148166 ['Class ' , $ class ?? 'Anonymous component ' ],
149167 ['Template ' , $ metadata ->getTemplate ()],
150- [$ propertyLabel , \count ($ allProperties ) > 0 ? implode ("\n" , $ allProperties ) : null ],
168+ [' Properties ' , \count ($ allProperties ) > 0 ? implode ("\n" , $ allProperties ) : null ],
151169 ];
152170
153171 if (isset ($ allLiveProperties ) && \count ($ allLiveProperties ) > 0 ) {
154172 $ componentInfos [] = ['Live Properties ' , implode ("\n" , $ allLiveProperties )];
155173 }
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 )];
162179 }
163180
181+ $ table = new Table ($ output );
182+ $ table ->setHeaders (['Property ' , 'Value ' ])->setRows ($ componentInfos );
164183 $ table ->render ();
165184
166185 return Command::SUCCESS ;
@@ -226,23 +245,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
226245 foreach ($ allComponents as $ component ) {
227246 $ metadata = $ this ->componentFactory ->metadataFor ($ component ['name ' ]);
228247
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 ' ],
236253 ];
237254 }
238255
239256 $ 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 );
246258 $ table ->render ();
247259
248260 return Command::SUCCESS ;
0 commit comments