xml-string-streamer-guzzle icon indicating copy to clipboard operation
xml-string-streamer-guzzle copied to clipboard

Created Guzzle response handling

Open elite6adger opened this issue 4 years ago • 7 comments

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

elite6adger avatar Apr 02 '21 04:04 elite6adger

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.

prewk avatar Apr 04 '21 20:04 prewk

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.

prewk avatar Apr 05 '21 18:04 prewk

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 avatar Apr 05 '21 18:04 prewk

@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?

elite6adger avatar Apr 10 '21 17:04 elite6adger

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?

prewk avatar Apr 11 '21 09:04 prewk

@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.

vtuz avatar Apr 25 '22 14:04 vtuz

Since this had an interaction, I'll just say: I'm happy to merge this years old thing, but it needs some documentation. :)

prewk avatar Nov 22 '23 12:11 prewk