xml-string-streamer-guzzle
xml-string-streamer-guzzle copied to clipboard
Created Guzzle response handling
There can be edge cases where there is need to leverage the Guzzle\Response. More specifically for situations where there is a need to create custom clients.
Examples
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Prewk\XmlStringStreamer;
use Prewk\XmlStringStreamer\Stream;
use Prewk\XmlStringStreamer\Parser;
$client = new GuzzleHttp\Client( );
$response = $client->request( 'GET', 'https://some-bigdata-xml-service/user', [
'auth' => [ 'username', 'password', 'digest' ],
]);
$CHUNK_SIZE = 1024;
$stream = new Stream\Guzzle\Response( $response, $CHUNK_SIZE );
$parser = new Parser\StringWalker( );
$streamer = new XmlStringStreamer( $parser, $stream );
while ( $node = $streamer->getNode() )
{
// ...
}```
fixes https://github.com/prewk/xml-string-streamer-guzzle/issues/8
Thank you, cool stuff! I'm a bit slow moving at the moment due to the Easter holidays, visiting family etc. I'll have a look as soon as possible.
Looks good, am I right to assume that your version could replace the original, could a Guzzle response be created with a url without much fuzz as well?
Because I'd love to replace the original one if that's the case rather than add another one on the side like this.
Re-read your comment, it makes sense to replace.
Could you replace the original file for me and update the readme with your example? Would be great!
@prewk, sure but there could be people that suffer a bit of a breaking change if I replace. Maybe what I can do is give the Guzzle class some intelligence to check for a "string" in its constructor. if a string then it just leverage the fopen like you have. If not then it will assume it is a Guzzle response and leverage it slightly different?
I think that would probably save a people that use this library some headaches. Thoughts?
Well I mean, I'd just bump the major version and call it a day. People should pin dependencies.
But, you're suggesting a great middle way here, could you try it out?
@elite6adger many thanks! I used your class from PR. I was getting "SSL: Connection reset by peer" error while parsed big xml and access to 'verify' => false solved my problem.
Since this had an interaction, I'll just say: I'm happy to merge this years old thing, but it needs some documentation. :)