Overloading Zend_Soap_Client _doRequest()

I wrote a soap client a while ago using Zend Framework 1 that was consuming data, and needed to log each request for debugging purposes. Thought I’d share a couple of things that I learned.

class My_Test_Soap_Client extends Zend_Soap_Client
...

public function _doRequest()
{
$argList = func_get_args();
$options = $this->_getOptions();
if ($options['testsoapclient'] == true) {
$soapLogger = new Zend_Log();
$writer     = new Zend_Log_Writer_Stream($options['logginglocation']);
$soapLogger->addWriter($writer);
$soapLogger->info($argList[1]);
}

return call_user_func_array("parent::_doRequest", $argList);
}

/**
* Don't do this...just here for reference
*/
protected function _getOptions()
{
return array(
'testsoapclient'  => true,
'logginglocation' => '/some/path/to/log/'
);
}

I’m overloading the public function _doRequest() so that I can do the extra processing needed to do my logging. You’ll first notice func_get_args(). I’m using this for my own convenience. I don’t have to stay current with any new arguments that may come.

The other important bit is

call_user_func_array("parent::_doRequest", $argList)

This simply is calling the original parent _doRequest() with the $argList we obtained earlier.

Post a Comment

I promise not to publish your email address.

*
*