请对此问题提出建议。是否可以使本机phpSoapClient在初始化时不连接到主机,直到没有调用某个soap方法?或者我如何扩展它来实现这种行为。
例如,我现在拥有的:
$this->client=new SoapClient($this->host,$this->params); //now it connects to host to load wsdl
$this->client->Add(123); //it performs some action
$this->client->Remove(123); //performs another
我想要什么:
$this->client=new SoapClient($this->host,$this->params); //just initializing do not connect to host
$this->client->Add(123); //it connects to host to load or check cached wsdl and performs some action
$this->client->Remove(123); //again checks wsdl and perfoms action
或者:
class Someklass{
static protected $host=null;
static protected $params=null;
static protected $client=null;
public function __construct() {
$this->params=array("connect_on_init"=>false);
$this->client=new SoapClient($this->host,$this->params); // just wraps the model
}
public function doSomeAction(){
$this->client->connect(); //it actually connects to host and checks wsdl provided
$action=$this->client->Add(123); //making some action
return $action;
}
我不明白你到底想要什么(以及为什么)。也许你需要这样的包装:
class someClass extends somethingElse
{
private $isConnected = false;
private $soapConnection;
private $soapHost;
private $soapParam;
public soapConnect($host, $param)
{
$this->soapHost = $host;
$this->soapParam = $param;
}
private doSoapConnect()
{
$this->soapConnection = new SoapClient($this->soapHost, $this->soapParams);
$this->isConnected = true;
}
public wrappedAdd($val)
{
if (!$this->isConnected)
$this->doSoapConnect();
$this->soapConnection->Add($val);
}
}