PHP-DI / Slim-Bridge

PHP-DI integration with the Slim framework
http://php-di.org/doc/frameworks/slim.html
MIT License
176 stars 38 forks source link

Method SoapClient::__construct() does not exist #64

Closed eebanos closed 3 years ago

eebanos commented 4 years ago

Hi everyone, I'm having issues trying to instantiate the SoapClient class from the 'services' definition as follows: services.php

return function (ContainerBuilder $containerBuilder) {
$containerBuilder->addDefinitions([
/**
* others definitions are included before, like 'LoggerInterface::class'....
*/
        SoapService::class => DI\create(SoapService::class)->constructor(
            get(LoggerInterface::class),
            DI\create(SoapClient::class)->constructor(get('wsxml.full')),
        )
]);
};

The parameter 'wsxml.full' is defined on config.php with the full WSDL Url and it is being resolved without problems. When I do a request to the endpoint that requires the SoapService, it returns the following error response:

{
  "error": {
    "type": "SERVER_ERROR",
    "description": "Method SoapClient::__construct() does not exist"
  }
}

The only way I get it to work is creating the instance with 'new':

return function (ContainerBuilder $containerBuilder) {
$containerBuilder->addDefinitions([
/**
* others definitions are included before, like 'LoggerInterface::class'....
*/
        SoapService::class => DI\create(SoapService::class)->constructor(
            get(LoggerInterface::class),
            new SoapClient('fullUrlParameter')
        )
]);
};

But this way I can't pass the resolved parameter inside the constructor.

I'm using the Slim framework v4, php-di/slim-bridge: 3.0.1 and PHP v7.4.9 with the ext-soap enabled. Any ideas why it is not working as expected?

mnapoli commented 4 years ago

I'm guessing the SoapService class is a built-in class in PHP and as such cannot really be used with PHP's reflection. I suggest you use factories with anonymous functions instead?