php-http / message

HTTP Message related tools
http://php-http.org
MIT License
1.29k stars 41 forks source link

GuzzleStreamFactory and guzzle/psr7:^2.0 #140

Closed staabm closed 3 years ago

staabm commented 3 years ago

PHP version: 8.0.6

Description updating a already working project setup to guzzle/psr7:^2.0 leads to confusion in combination with phppro/soap-client.

we see the php-soap client picking up the GuzzleStreamFactory and this one is not compatible with guzzle/psr7:^2.0.

see more details in https://github.com/phpro/soap-client/issues/385

any pointers in any direction would be helpful. stacking all these psr/http-plug etc. packages together is pretty confusing.

How to reproduce

our (simplified) composer.json looks like

    "require" : {
        "ext-json": "*",
        "ext-soap": "*",
        "ext-gettext": "*",
        "phpro/soap-client": "^1.4",
        "guzzlehttp/guzzle": "^7.2.0",
        "guzzlehttp/promises": "^1.4.0",
        "guzzlehttp/psr7": "2.0.0"
    },

and we are creating the soap client with this code:


    public static function getEngine(string $wsdl, ExtSoapOptions $options): Engine
    {

        $httpClient = new Client([
            'verify' => false /*disable ssl cert validation*/,
            'auth' => [SoapConfig::WEBCONNECTOR_USER, SoapConfig::WEBCONNECTOR_PW, 'ntlm'],
        ]);

        $handler = HttPlugHandle::createForClient($httpClient);
        $handler->addMiddleware(new \WebconnectorMiddleware());
        $handler->addMiddleware(new WsaMiddleware2005(WsaMiddleware2005::WSA_ADDRESS2005_ANONYMOUS));

        $wsdlProvider = new CachedWsdlProvider(new HttpWsdlLoader(
            $httpClient,
            Psr17FactoryDiscovery::findRequestFactory()
        ), new Filesystem(),sys_get_temp_dir().DIRECTORY_SEPARATOR.'soap-test-');

        $options->withWsdlProvider($wsdlProvider);
        return ExtSoapEngineFactory::fromOptionsWithHandler($options, $handler);
    }

and we get a exception:

Error thrown with message "Call to undefined function GuzzleHttp\Psr7\stream_for()"

Stacktrace:
#18 Error in /cluster/www/www/www/philipp/vendor/php-http/message/src/StreamFactory/GuzzleStreamFactory.php:23
#17 Http\Message\StreamFactory\GuzzleStreamFactory:createStream in /cluster/www/www/www/philipp/vendor/phpro/soap-client/src/Phpro/SoapClient/Soap/HttpBinding/Builder/Psr7RequestBuilder.php:130
#16 Phpro\SoapClient\Soap\HttpBinding\Builder\Psr7RequestBuilder:setSoapMessage in /cluster/www/www/www/philipp/vendor/phpro/soap-client/src/Phpro/SoapClient/Soap/HttpBinding/Converter/Psr7Converter.php:52
#15 Phpro\SoapClient\Soap\HttpBinding\Converter\Psr7Converter:convertSoapRequest in /cluster/www/www/www/philipp/vendor/phpro/soap-client/src/Phpro/SoapClient/Soap/Handler/HttPlugHandle.php:84
#14 Phpro\SoapClient\Soap\Handler\HttPlugHandle:request in /cluster/www/www/www/philipp/vendor/phpro/soap-client/src/Phpro/SoapClient/Soap/Engine/Engine.php:39
#13 Phpro\SoapClient\Soap\Engine\Engine:request in /cluster/www/www/www/philipp/vendor/phpro/soap-client/src/Phpro/SoapClient/Client.php:107
#12 Phpro\SoapClient\Client:call in /cluster/www/www/www/philipp/soap/customer/generated/CustomerClient.php:20
...

grafik

Possible Solution

basically I am wondering whether https://github.com/php-http/message/blob/master/src/StreamFactory/GuzzleStreamFactory.php would also needs a separate IF case for guzzle/psr7:^2.0 as was added in https://github.com/php-http/message/pull/139/files for the GuzzleUriFactory ?

dbu commented 3 years ago

hi, thanks for the clear report and analysis. looking at the code, i think your solution sounds correct. can you do a PR with that change to check for guzzle Utils class like we do for the uri factory? (to be sure it indeed fixes the problem, you could try that code in your project).