Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GuzzleStreamFactory and guzzle/psr7:^2.0 #140

Closed
staabm opened this issue Aug 2, 2021 · 1 comment · Fixed by #141
Closed

GuzzleStreamFactory and guzzle/psr7:^2.0 #140

staabm opened this issue Aug 2, 2021 · 1 comment · Fixed by #141

Comments

@staabm
Copy link
Contributor

staabm commented Aug 2, 2021

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 phpro/soap-client#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
Copy link
Contributor

dbu commented Aug 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants