PHP SoapClient classmap的优势

Mar*_*ger 5 php soap soap-client

谁能告诉我在 PHP Soapclient 中使用 classmap 选项的好处?也许有一些实际的例子?

hoa*_*nan 6

classmap 选项可用于将某些 WSDL 类型映射到 PHP 类。

例子,

class MyLoginResult {
    protected $serverUrl;
    protected $sessionId;

    public function getServerUrl()
    {
         return $this->serverUrl;
    }

    public function getSessionId()
    {
        return $this->sessionId;
    }

    public function getServerInstance()
    {
        $match = preg_match(
            '/https:\/\/(?<instance>[^-]+)\.example\.com/',
            $this->serverUrl,
            $matches
        );

        return $matches['instance'];
    }
}

$client = new SoapClient("books.wsdl", 
                 array('classmap' => array('LoginResult' => "MyLoginResult")));

$loginResult = $client->getLoginResult();
$instance = $loginResult->getServerInstance();
Run Code Online (Sandbox Code Playgroud)