Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantage of PHP SoapClient classmap

Can anyone tell me the advantage of using the classmap option within PHP Soapclient? Maybe with some practical examples?

like image 614
Mart Blegger Avatar asked Apr 22 '15 14:04

Mart Blegger


Video Answer


1 Answers

The classmap option can be used to map some WSDL types to PHP classes.

Example,

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();
like image 132
hoangthienan Avatar answered Sep 23 '22 02:09

hoangthienan