Ben ikinci Aleksanders ve Stefans öneri ama SoapClient alt sınıf olmaz. Günlük SoapClient doğrudan bir endişe değildir çünkü onun yerine ben, bir dekoratör düzenli SoapClient sarın ediyorum. Buna ek olarak, gevşek bağlama kolayca unittests bir mock ile SoapClient yerine sağlar, böylece günlük işlevselliğini test konsantre olabilirsiniz. Eğer sadece belirli çağrıları oturum açmak istiyorsanız, size $ eylem veya uygun gördüğünüz herhangi bir şey tarafından istekleri ve yanıtları filtreler bazı mantık ekleyebilirsiniz.
Stefan bazı kod eklemek için önerilen beri __ çağrısı hakkında emin değilim ancak Edit, dekoratör (muhtemelen, böyle bir şey olmazdı) yöntemi (Stefans yorumlara bakınız)
class SoapClientLogger
{
protected $soapClient;
// wrapping the SoapClient instance with the decorator
public function __construct(SoapClient $client)
{
$this->soapClient = $client;
}
// Overloading __doRequest with your logging code
function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$this->log($request, $location, $action, $version);
$response = $this->soapClient->__doRequest($request, $location,
$action, $version,
$one_way);
$this->log($response, $location, $action, $version);
return $response;
}
public function log($request, $location, $action, $version)
{
// here you could add filterings to log only items, e.g.
if($action === 'foo') {
// code to log item
}
}
// route all other method calls directly to soapClient
public function __call($method, $args)
{
// you could also add method_exists check here
return call_user_func_array(array($this->soapClient, $method), $args);
}
}