Open troccoli opened 7 years ago
The helper methods only operate against the request body (that is, the contents of php://input
). I see how it would be useful to be able to apply them against other data, too, though. The trick is to figure out how to make that work. PRs are welcome, of course. A mechanism that doesn't break BC would probably be preferred, I imagine.
I've been trying to use the mask method as it looks really useful but couldn't figure it out using the readme. I guess you're saying it's designed to use an uploaded file and doesn't accept data directly?
Would it be difficult to allow the mask method to accept extra data?
$parser->mask($mask, $data);
Sorry if I'm way off the mark here, still loving this package without the mask!
That is correct, yes. (Essentially. The "uploaded file" is actually the request body, but close enough.)
One thing to note is that Laravel (via illuminate/support
) includes helpers for doing much more advanced operations on arrays and similar, so the helper methods here are largely superfluous for Laravel (and Lumen) users. While they are by no means the only target users, Laravel/Lumen users are the primary contributors, so we sometimes overlook uses like these.
A second argument would probably work. There are other approaches that could work, too. Not sure which approach @nathanmac would prefer in this case, though, so it certainly warrants further conversation.
I'm writing an API that calls an external API. The external API returns data as XML, and my API needs to return data as JSON. I have the following code that works fine
I then include this data into my JSON response like the following
This, as I said, works fine.
Now, however, I want to filter the XML response from the external API as I'm not interested in all the fields that it returns. I thought I could use the mask() method but I don't know how.
Since the methods are not fluent I thought I set the mask before parsing the payload, thinking that would apply the mask
But that doesn't work.
This is one reason I want to use this package, the ability to filter the output, but how to do it?