1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
| <?php
class SoftlayerApiCall
{
/**** Properties ****/
protected $_service = "SoftLayer_Account";
protected $_method = "getObject";
protected $_init = null;
protected $_wsdl = "https://api.softlayer.com/soap/v3/SoftLayer_Account?wsdl";
protected $_typeNameSpace = "http://api.softlayer.com/soap/v3/SLTypes/";
protected $_username;
protected $_password;
protected $_clientOptions = Array("trace"=>true);
protected $_client;
protected $_response;
/**** Methods ****/
/**** Constructors ****/
public function __construct(array $Setup = null)
{
If ( is_array($Setup) ){
$this->setOptions($Setup);
}
}
public function setOptions(array $setup)
{
$methods=get_class_methods($this);
foreach($setup as $key => $value){
$method = 'set'.ucfirst($key);
if (null != $value && "" != $value){
if( in_array($method,$methods) ){
$this->$method($value);
}else{ throw new Exception($method.' not found in methods and '.$value.' not saved'); }
}
}
return $this;
}
public function __set($name, $value)
{
$method = 'set'. ucfirst($name);
if( !method_exists($this,$method) ){
throw new Exception('Tried to set an unrecognised Property');
}
if (null != $value && "" != $value){ return $this->$method($value); }
}
public function __get($name)
{
$method = 'get'. ucfirst($name);
if( !method_exists($this,$method) ){
throw new Exception('Tried to get an unrecognised Property');
}
return $this->$method();
}
/**** Actions ****/
public function Response()
{
$Wsdl = $this->getWsdl();
$Options = $this->getClientOptions();
$this->setClient($Wsdl,$Options);
$this->createHeaders();
$Method = $this->getMethod();
try {$Response = $this->getClient()->$Method();}
Catch(Exception $e){$error=$e->getMessage(); $Response=array("Error:"=>$error);}
return $Response;
}
public function createHeaders(){
$Headers = Array();
$Username=$this->getUsername();
$ApiKey=$this->getPassword();
$TypeNameSpace=$this->getTypeNameSpace();
$Service=$this->getService();
$InitId=$this->getInit();
$AuthUser=new SoapVar($Username,XSD_STRING,null,null,'username');
$AuthKey=new SoapVar($ApiKey,XSD_STRING,null,null,'apiKey');
$Auth=array($AuthUser,$AuthKey);
$AuthHeader=new SoapVar($Auth,SOAP_ENC_OBJECT,'slt:authenticate',$TypeNameSpace,'authenticate');
$Headers[]=new SoapHeader("http://api.softlayer.com/soap/v3/SLTypes/","authenticate",$AuthHeader);
If (null!=$InitId){
$Init = new SoapVar($InitId,XSD_INT,null,null,"id");
$Init = array($Init);
$InitHeader=new SoapVar($Init,SOAP_ENC_OBJECT,'v3:'.$Service.'InitParameters',$TypeNameSpace,$Service.'InitParameters');
$Headers[]=new SoapHeader("http://api.softlayer.com/soap/v3/SLTypes/",$Service."InitParameters",$InitHeader);
}
$this->getClient()->__setSoapHeaders($Headers);
}
/**** Methods For Setting and Getting Properties ****/
/**** Sets ****/
public function setService($Service){ $this->_service = $Service; }
public function setMethod($Method){ $this->_method = $Method; }
public function setInit($Init){ $this->_init = $Init; }
public function setWsdl($Service){ $this->_wsdl="https://api.softlayer.com/soap/v3/".$Service."?wsdl"; }
public function setTypeNameSpace($typeNameSpace){ $this->_typeNameSpace = $typeNameSpace; }
public function setUsername($username){ $this->_username=$username; }
public function setPassword($password){ $this->_password=$password; }
public function setClientOptions($Options){ $this->_clientOptions=$Options; }
public function setClient($Wsdl, $Options){
if (null!=$Wsdl){
$Client = new SoapClient($Wsdl,$Options);
$this->_client = $Client;
}else{ throw new Exception( 'Tried to set Client without specifying a Web Service Definition Language' ); }
}
public function setResponse($Response){ $this->_response=$Response; }
/**** Gets ****/
public function getService(){ return $this->_service; }
public function getMethod(){ return $this->_method; }
public function getInit(){ return $this->_init; }
public function getWsdl(){ return $this->_wsdl; }
public function getTypeNameSpace(){ return $this->_typeNameSpace; }
public function getPassword(){ return $this->_password; }
public function getUsername(){ return $this->_username; }
public function getClientOptions(){ return $this->_clientOptions; }
public function getClient(){ return $this->_client; }
public function getResponse(){ return $this->_response; }
} |