Json Support for all actions
hey Guys,
I am in Love with Phinx, but one thing is missing for me. I'd love to see a json output for all actions that can be taken via terminal/webapp.
Currently only the Status Method returns json on request, but it would be nice if you could call everything within php and get nice responses.
As Use Case i see an Api with Endpoints to migrate, rollback, getStatus, create Migrations etc etc.
If someone guides me in the right direction where to start such a feature, i'd love to send in pull requests.
Greets Marcus
Hi @derpoho - personally I also need this feature, but I wasn't thinking about it when I first designed Phinx. Over the years JSON support has kind of been hacked into Phinx and is far from ideal. For proper JSON output on all commands we really need to go back and refactor some of the core classes. Not an easy project. Happy to leave this open for now, but I can't give a timeline.
Thx for the reply.
I have already seen that as i tried to accomplish something. For now i have solved it by splitting the console output into lines and send back the array of lines. Not ideal, but works for now. Currently pretty busy, but once finished i'll try to dig into into it and maybe help you out as i really love phinx and will use it on nearly all of my future projects ;)
Greets Marcus
@robmorgan I took my chance on to this feature. I tried 2 Ideas.
The first one was to replace TextWrapper with a Custom JSON Wrapper (which doesn't differ too much) and forward a custom JsonOutput Class which directly extends the Symfony OutputInterface. This worked quite well until I came to the table views, which made me add a lot of unnecessary code, and that doesn't make sense.
The second idea I tried is to completely replace the dependency on the Symphony Output Interface and replace it with a custom Output Class. As far is I have seen you are using only the writeIn method, so this shouldn't be a problem to replace on all occurrences (62 times ;)). With this Output Class, we can basically do what we want, forward to Symfony, forward to a JSON Handler or whatever. Regarding the forwarding of messages I suggest just writing message keys with option arrays, so you can replace predefined strings (based on the message key) with the variables in the options array or do with the options array whatever you want.
What do you think?
Closing due to lack of activity or out of scope. If there is new interest, please open a PR.
@othercorey can you re-open this? This is something I've wanted in Phinx for a while, as having to do combinations of grep, head, tail, etc. is not the most friendly of things.
I am looking forward to this because I also hope that every operation will return JSON format information, and I will do my subsequent operations based on the results