gpt4 book ai didi

php - 在第三方库中记录 SOAP 信封

转载 作者:搜寻专家 更新时间:2023-10-31 21:05:59 25 4
gpt4 key购买 nike

我正在尝试为第三方库生成的信封添加日志记录。我正在修改下面的 updateMetadataField() 方法。

我正在像这样创建 $client:

$client = new UpdateClient($UPDATE_END_POINT, $USER_AUTH_ARRAY);

我已经尝试了 $this->client->__getLastRequest()$this->__getLastRequest() 结果都是同样的错误。

当 SoapClient 实例化时,trace 设置为 true

错误是

Fatal error:  Call to undefined method UpdateClient::__getLastRequest() 

那么如何正确访问__getLastRequest()方法呢?

$USER_AUTH_ARRAY = array(
'login'=>"foo",
'password'=>"bar",
'exceptions'=>0,
'trace'=>true,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
);

class UpdateClient {
private $client;

public function __construct($endpoint, $auth_array) {
$this->client = new SoapClient($endpoint, $auth_array);
}

public function updateMetadataField($uuid, $key, $value) {
$result = $this->client->updateMetadataField(array(
'assetUuid' => $uuid,
'key' => $key,
'value' => $value)
);

if(is_soap_fault($result)) {
return $result;
}

return $result->return . "\n\n" . $this->client->__getLastRequest();

} // updateMetadataField()

} // UpdateClient

更新 - 添加调用代码此代码迭代一个数组,该数组将我们的数据映射到远程字段。

我希望做的是开始存储我们发送来帮助调试的信封。

    $client = new UpdateClient($UPDATE_END_POINT, $USER_AUTH_ARRAY);
foreach ($widen_to_nool_meta_map as $widen => $nool) { // array defined in widen.php
if ($nool != '') {
// handle exceptions
if ($nool == 'asset_created') { // validate as date - note that Widen pulls exif data so we don't need to pass this
if (!strtotime($sa->$nool)) {
continue;
}
} else if ($nool == 'people_in_photo' || $nool == 'allow_sublicensing' || $nool == 'allowed_use_pr_gallery') {
// we store as 0/1 but GUI at Widen wants Yes/No
$sa->$nool = ($sa->$nool == '1') ? 'Yes' : 'No';
} else if ($nool == 'credit_requirements') {
$sa->$nool = $sa->credit_requirements()->label;
}

$result = $client->updateMetadataField($sa->widen_id, $widen, $sa->$nool);
if(is_soap_fault($result)) {
$sync_result = $sync_result . "\n" . $result->getMessage();
} else {
$sync_result = $sync_result . "\n" . print_r($result, 1);
}
} // nool field set
} // foreach mapped field

最佳答案

如果您想访问 UpdateClient::__getLastRequest(),您必须在 UpdateClient 类上公开该方法,因为 $client 是私有(private)变量。正确的调用方式是$this->client->__getLastRequest()

看看这个工作示例,您可以看到我正在使用免费网络服务进行测试。

<?php
$USER_AUTH_ARRAY = array(
'exceptions'=>0,
'trace'=>true,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
);

class TestClient {
private $client;

public function __construct($endpoint, $auth_array) {
$this->client = new SoapClient($endpoint, $auth_array);
}

public function CelsiusToFahrenheit( $celsius ) {
$result = $this->client->CelsiusToFahrenheit(array(
'Celsius' => $celsius
)
);

if(is_soap_fault($result)) {
return $result;
}

return $result;

}

public function __getLastRequest() {
return $this->client->__getLastRequest();
}

}

try
{
$test = new TestClient( "http://www.w3schools.com/webservices/tempconvert.asmx?wsdl", $USER_AUTH_ARRAY);
echo "<pre>";
var_dump($test->CelsiusToFahrenheit( 0 ));
var_dump($test->__getLastRequest());
var_dump($test->CelsiusToFahrenheit( 20 ));
var_dump($test->__getLastRequest());
echo "</pre>";
}
catch (SoapFault $fault)
{
echo $fault->faultcode;
}
?>

关于php - 在第三方库中记录 SOAP 信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32343019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com