Fix overriding the custom SoapClient class #51
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey,
in general all services extending the
AbstractSoapClientBase
class use PHP's defaultSoapClient
class to handle requests, which is specified as a constant in theSoapClientInterface
:DEFAULT_SOAP_CLIENT_CLASS
.As per documentation, a custom SoapClient class can be used by overriding said constant:
However, simply overriding it does not work since the underlying SoapClient initialization method (
initSoapClient()
) relies on the value returned by thegetSoapClientClassName()
method which in turn reads the constant as aself::
, i.e. as defined in the actual abstract class (or the interface in this case). Kind of like reading a private property inside a parent class – overriding in the child class has no effect.If we use late static bindings on the other hand, it would read the constant's value from the extended class first, and then use the interface constant as a fallback:
static::
instead ofself::
. Like turning a private property protected.Currently, if my service extends the
AbstractSoapClientBase
class using all its functionality, but I decide to use a customSoapClient
, I would have to override thegetSoapClientClassName()
method in my service class. It would be easier if I could just specify it by overriding theDEFAULT_SOAP_CLIENT_CLASS
constant – like the documentation suggests I should do 😊