用常规的SoapClient不可能做你想要的.你最好的办法是扩展SoapClient类并抽出这个要求来获取版本.
请注意,file_get_contents没有被缓存,所以它将始终加载WSDL文件.另一方面,SoapClient缓存WSDL,因此您将不得不自己处理它.
也许看看NuSOAP.您将能够修改代码以适合您的目的,而无需加载WSDL两次(当然您也可以修改SoapClient,但这是另一个冠军))
namespace Application;
use DOMDocument;
class SoapClient extends \SoapClient {
private $version = null;
function __construct($wsdl, $options = array()) {
$data = file_get_contents($wsdl);
$xml = new DOMDocument();
$xml->loadXML($data);
$this->version = $xml->getElementsByTagName('Version')->item(0)->nodeValue;
// or just use $wsdl :P
// this is just to reuse the already loaded WSDL
$data = "data://text/plain;base64,".base64_encode($data);
parent::__construct($data, $options);
}
public function getVersion() {
return is_null($this->version) ? "Uknown" : $this->version;
}
}
$client = new SoapClient("/webservices/latest/ebaysvc.wsdl");
var_dump($client->getVersion());