Closed faustbrian closed 1 year ago
This requires quite some regex voodoo to get it working. It's almost working but there seems to be something somewhere that causes duplication, for example when you run vendor/bin/phpunit --filter="output_writes_events"
you'll get duplicated events. Not sure yet what causes that but I assume the multiple calls to the controller lexer.
I can take a stab if you want to leave it for the weekend.
I'll continue tomorrow on it but feel free to poke around, probably something obvious that causes the array items to get duplicated 😅
Cool. You on Twitter? I'll give you a shout out.
I think parsing out the controller
section via regex will prove challenging and likely have edge cases. If you wanted to produce the dashed array syntax, then you'd might be better off going line by line through the controller section.
However, thinking about it more, these statements may not be sequential. And moving them into a single array, may not generate the code the user intended.
For example:
validate: title, content
save: ticket
send: ReviewNotification to:ticket.reviewer with:ticket
dispatch: SyncMedia with:ticket
send: TicketOpened to:ticket.author with:ticket
As such, I think simply finding these indented properties and giving them a numerical suffix is the way to go. Then update the lexer to handle numbered properties when creating the statement. If so, you could likely revert #619.
@jasonmccreary updated the OP with the (I think) final changes
I foresee a lot of bugs, but here we go...
This new approach preprocesses the YAML content and transforms duplicate keys into keys that are suffixed with their line number to avoid key collisions. This also reverts https://github.com/laravel-shift/blueprint/pull/619.
Input https://github.com/laravel-shift/blueprint/pull/623/files#diff-a4f4e06b3fdb4a8424880f544fca3c75a0ecf2ebb5158feba4963f7066e2d265
Output https://github.com/laravel-shift/blueprint/pull/623/files#diff-72d9e08bf23239b5487ea8767fe78e8f3e9be1b14e5bd64e1ae2c4848da167f1