Skip to content

Commit e6b923d

Browse files
Updates to support php8.1.12
1 parent 307b045 commit e6b923d

File tree

7 files changed

+73
-79
lines changed

7 files changed

+73
-79
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,37 @@ The latest version 1.x is not backwards-compatible.
77
It is necessary to update scripts to function properly with the new version.
88
```
99

10+
Use [v1.2.0](https://github.com/softlayer/softlayer-api-php-client/releases/tag/v1.2) for older PHP versions. [v2.0.0](https://github.com/softlayer/softlayer-api-php-client/releases/tag/v2.0.0) for php 8.1 or higher.
11+
12+
[PHP 8.0 removed XMLRPC](https://php.watch/versions/8.0/xmlrpc) as a built in extension. As such, it is no longer required as part of the composer file in this project. The XmlRpcClient still exists here if you need it, but we assume most users are using the SoapClient. If there are any issues with this [Let us know on github](https://github.com/softlayer/softlayer-api-php-client/issues)
13+
1014
## Overview
1115

1216
The SoftLayer API PHP client classes provide a simple method for connecting to and making calls from the SoftLayer API and provides support for many of the SoftLayer API's features. Method calls and client management are handled by the PHP SOAP and XML-RPC extensions.
1317

14-
Making API calls using the `\SoftLayer\SoapClient` or `\SoftLayer\XmlRpcClient` classes is done in the following steps:
18+
Making API calls using the `\SoftLayer\SoapClient` is done in the following steps:
1519

16-
1. Instantiate a new `\SoftLayer\SoapClient` or `\SoftLayer\XmlRpcClient` object using the `\SoftLayer\SoapClient::getClient()` or `\SoftLayer\XmlRpcClient::getClient()` methods. Provide the name of the service that you wish to query, an optional id number of the object that you wish to instantiate, your SoftLayer API username, your SoftLayer API key, and an optional API endpoint base URL. The client classes default to connect over the public Internet. Enter `\SoftLayer\SoapClient::API_PRIVATE_ENDPOINT` or `\SoftLayer\XmlRpcClient::API_PRIVATE_ENDPOINT` to connect to the API over SoftLayer's private network. The system making API calls must be connected to SoftLayer's private network (eg. purchased from SoftLayer or connected via VPN) in order to use the private network API endpoints.
17-
2. Define and add optional headers to the client, such as object masks and result limits.
18-
3. Call the API method you wish to call as if it were local to your client object. This class throws exceptions if it's unable to execute a query, so it's best to place API method calls in try / catch statements for proper error handling.
20+
1. Instantiate a new `\SoftLayer\SoapClient` object using the `\SoftLayer\SoapClient::getClient()` method. Provide the name of the service that you wish to query, an optional id number of the object that you wish to instantiate, your SoftLayer API username, your SoftLayer API key, and an optional API endpoint base URL. The client classes default to connect over the public Internet.
21+
2. Use `\SoftLayer\SoapClient::API_PRIVATE_ENDPOINT` to connect to the API over SoftLayer's private network. The system making API calls must be connected to SoftLayer's private network (eg. purchased from SoftLayer or connected via VPN) in order to use the private network API endpoints.
22+
3. Define and add optional headers to the client, such as object masks and result limits.
23+
4. Call the API method you wish to call as if it were local to your client object. This class throws exceptions if it's unable to execute a query, so it's best to place API method calls in try / catch statements for proper error handling.
1924

2025
Once your method is executed you may continue using the same client if you need to connect to the same service or define another client object if you wish to work with multiple services at once.
2126

22-
The most up to date version of this library can be found on the SoftLayer github public repositories: [http://github.com/softlayer/](http://github.com/softlayer/) . Please post to the SoftLayer forums [Stack Overflow](https://stackoverflow.com) or open a support ticket in the SoftLayer customer portal if you have any questions regarding use of this library. If you use Stack Overflow please tag your posts with “SoftLayer” so our team can easily find your post.
27+
The most up to date version of this library can be found on the SoftLayer github public repositories: [https://github.com/softlayer/softlayer-api-php-client](https://github.com/softlayer/softlayer-api-php-client) . Any issues using this library, please open a [Github Issue](https://github.com/softlayer/softlayer-api-php-client/issues)
2328

2429
## System Requirements
2530

26-
The `\SoftLayer\SoapClient` class requires at least PHP 5.3.0 and the PHP SOAP enxtension installed. The `\SoftLayer\XmlRpcClient` class requires PHP at least PHP 5 and the PHP XML-RPC extension installed.
31+
The `\SoftLayer\SoapClient` class requires at least PHP 8.0.0 and the PHP SOAP enxtension installed and enabled (`extension=soap` in the php.ini file).
32+
Since [php 8.0 has removed xmlrpc extension](https://php.watch/versions/8.0/xmlrpc) you will need to manually install this library to use the `\SoftLayer\XmlRpcClient`. If you are using an earlier version of php that still includes ext-xml, please use v1.2.0 of this library.
2733

28-
A valid API username and key are required to call the SoftLayer API. A connection to the SoftLayer private network is required to connect to SoftLayer's private network API endpopints.
34+
A valid API username and key are required to call the SoftLayer API. A connection to the SoftLayer private network is required to connect to SoftLayer's private network API endpopints. See [Authenticating to the SoftLayer API](https://sldn.softlayer.com/article/authenticating-softlayer-api/) for how to get these API keys.
2935

3036
## Installation
3137

3238
Install the SoftLayer API client using [Composer](https://getcomposer.org/).
3339
```bash
34-
composer require softlayer/softlayer-api-php-client:~1.0@dev
40+
composer require softlayer/softlayer-api-php-client:~2.0.0@master
3541
```
3642

3743
## Usage
@@ -105,4 +111,4 @@ This software is written by the SoftLayer Development Team <[[email protected]]
105111

106112
## Copyright
107113

108-
This software is Copyright &copy; 2009 – 2010 [SoftLayer Technologies, Inc](http://www.softlayer.com/). See the bundled LICENSE.textile file for more information.
114+
This software is Copyright &copy; 2009 – 2022 [SoftLayer Technologies, Inc](http://www.softlayer.com/). See the bundled LICENSE.textile file for more information.

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=5.3",
15-
"ext-xmlrpc": "*",
14+
"php": ">=8.0",
1615
"ext-soap": "*"
1716
},
1817
"autoload": {
@@ -22,7 +21,7 @@
2221
},
2322
"extra": {
2423
"branch-alias": {
25-
"dev-master": "1.0-dev"
24+
"dev-master": "2.0.0"
2625
}
2726
}
2827
}

composer.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example.php

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@
6565
}
6666

6767
/**
68-
* It's possible to define your SoftLayer API username and key diredtly in the
69-
* class file, but it's far easier to define them before creating your API
70-
* client.
68+
* It's possible to define your SoftLayer API username and key directly in the
69+
* class file, but it's far easier to define them before creating your API client.
7170
*/
72-
$apiUsername = 'set me';
73-
$apiKey = 'set me too';
71+
$apiUsername = getenv('SL_USER');
72+
$apiKey = getenv('SL_APIKEY');
7473

7574
/**
7675
* Usage:
@@ -84,6 +83,8 @@
8483
* API key: Your SoftLayer API key,
8584
*/
8685
$client = SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
86+
$objectMask = "mask[id,companyName]";
87+
$client->setObjectMask($objectMask);
8788

8889
/**
8990
* Once your client object is created you can call API methods for that service
@@ -95,45 +96,36 @@
9596
* It retrieves basic account information, and is a great way to test your API
9697
* account and connectivity.
9798
*/
99+
98100
try {
99-
print_r($client->getObject());
101+
$result = $client->getObject();
102+
print_r($result);
100103
} catch (\Exception $e) {
101104
die($e->getMessage());
102105
}
103106

104107
/**
105-
* For a more complex example we’ll retrieve a support ticket with id 123456
106-
* along with the ticket’s updates, the user it’s assigned to, the servers
107-
* attached to it, and the datacenter those servers are in. We’ll retrieve our
108-
* extra information using a nested object mask. After we have the ticket we’ll
109-
* update it with the text ‘Hello!’.
108+
* In this example we will get all of the VirtualGuests on our account. And for each guest we will print out
109+
* some basic information about them, along with make another API call to get its primaryIpAddress.
110110
*/
111111

112112
// Declare an API client to connect to the SoftLayer_Ticket API service.
113-
$client = SoapClient::getClient('SoftLayer_Ticket', 123456, $apiUsername, $apiKey);
113+
$client = SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
114+
114115

115116
// Assign an object mask to our API client:
116-
$objectMask = new ObjectMask();
117-
$objectMask->updates;
118-
$objectMask->assignedUser;
119-
$objectMask->attachedHardware->datacenter;
117+
$objectMask = "mask[id, hostname, datacenter[longName]]";
120118
$client->setObjectMask($objectMask);
121119

122-
// Retrieve the ticket record.
123120
try {
124-
$ticket = $client->getObject();
125-
print_r($ticket);
126-
} catch (\Exception $e) {
127-
die('Unable to retrieve ticket record: ' . $e->getMessage());
128-
}
129-
130-
// Now update the ticket.
131-
$update = new \stdClass();
132-
$update->entry = 'Hello!';
133-
134-
try {
135-
$update = $client->addUpdate($update);
136-
echo "Updated ticket 123456. The new update's id is " . $update[0]->id . '.';
121+
$virtualGuests = $client->getVirtualGuests();
122+
print("Id, Hostname, Datacenter, Ip Address\n");
123+
foreach ($virtualGuests as $guest) {
124+
$guestClient = SoapClient::getClient('SoftLayer_Virtual_Guest', $guest->id, $apiUsername, $apiKey);
125+
$ipAddress = $guestClient->getPrimaryIpAddress();
126+
print($guest->id . ", " . $guest->hostname . ", " . $guest->datacenter->longName . ", " . $ipAddress . "\n");
127+
break;
128+
}
137129
} catch (\Exception $e) {
138-
die('Unable to update ticket: ' . $e->getMessage());
130+
die('Unable to retrieve virtual guests: ' . $e->getMessage());
139131
}

src/Common/ObjectMask.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@
5656
* making your SoftLayer API calls.
5757
*
5858
* For more on object mask usage in the SoftLayer API please see
59-
* http://sldn.softlayer.com/article/Using_Object_Masks_in_the_SoftLayer_API .
59+
* https://sldn.softlayer.com/article/object-masks/ .
6060
*
6161
* The most up to date version of this library can be found on the SoftLayer
62-
* github public repositories: http://github.com/softlayer/ . Please post to
63-
* the SoftLayer forums <http://forums.softlayer.com/> or open a support ticket
64-
* in the SoftLayer customer portal if you have any questions regarding use of
65-
* this library.
62+
* github public repositories: http://github.com/softlayer/ .
6663
*
6764
* @author SoftLayer Technologies, Inc. <[email protected]>
68-
* @copyright Copyright (c) 2009 - 2010, Softlayer Technologies, Inc
65+
* @copyright Copyright (c) 2009 - 2022, Softlayer Technologies, Inc
6966
* @license http://sldn.softlayer.com/article/License
7067
* @see SoapClient::setObjectMask()
7168
* @see XmlRpcClient::setObjectMask()

src/SoapClient.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright (c) 2009 - 2010, SoftLayer Technologies, Inc. All rights reserved.
3+
* Copyright (c) 2009 - 2022, SoftLayer Technologies, Inc. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions are met:
@@ -35,24 +35,20 @@
3535
/**
3636
* A SoftLayer API SOAP Client
3737
*
38-
* Please see the bundled README.textile file for more details and usage
39-
* information.
38+
* Please see the bundled README file for more details and usage information.
4039
*
41-
* This client supports sending multiple calls in parallel to the SoftLayer
42-
* API. Please see the documentation in the
43-
* AsynchronousAction class in
40+
* This client supports sending multiple calls in parallel to the SoftLaye API.
41+
* Please see the documentation in the AsynchronousAction class in
4442
* SoapClient/AsynchronousAction.php for details.
4543
*
4644
* The most up to date version of this library can be found on the SoftLayer
47-
* github public repositories: http://github.com/softlayer/ . Please post to
48-
* the SoftLayer forums <http://forums.softlayer.com/> or open a support ticket
49-
* in the SoftLayer customer portal if you have any questions regarding use of
50-
* this library.
45+
* github public repositories: https://github.com/softlayer/softlayer-api-php-client .
46+
* For any issues with this library, please open a github issue
5147
*
5248
* @author SoftLayer Technologies, Inc. <[email protected]>
53-
* @copyright Copyright (c) 2009 - 2010, Softlayer Technologies, Inc
49+
* @copyright Copyright (c) 2009 - 2022, Softlayer Technologies, Inc
5450
* @license http://sldn.softlayer.com/article/License
55-
* @link http://sldn.softlayer.com/article/The_SoftLayer_API The SoftLayer API
51+
* @link https://sldn.softlayer.com/article/php/ The SoftLayer API
5652
* @see AsynchronousAction
5753
*/
5854
class SoapClient extends \SoapClient
@@ -69,7 +65,7 @@ class SoapClient extends \SoapClient
6965
* Your SoftLayer API user's authentication key. You may overide this value
7066
* when calling getClient().
7167
*
72-
* @link https://manage.softlayer.com/Administrative/apiKeychain API key management in the SoftLayer customer portal
68+
* @link https://sldn.softlayer.com/article/authenticating-softlayer-api/ API key management in the SoftLayer customer portal
7369
* @var string
7470
*/
7571
const API_KEY = 'set me';
@@ -80,22 +76,22 @@ class SoapClient extends \SoapClient
8076
*
8177
* @var string
8278
*/
83-
const API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/soap/v3/';
79+
const API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/soap/v3.1/';
8480

8581
/**
8682
* The base URL of the SoftLayer SOAP API's WSDL files over SoftLayer's
8783
* private network.
8884
*
8985
* @var string
9086
*/
91-
const API_PRIVATE_ENDPOINT = 'http://api.service.softlayer.com/soap/v3/';
87+
const API_PRIVATE_ENDPOINT = 'http://api.service.softlayer.com/soap/v3.1/';
9288

9389
/**
9490
* The namespace to use for calls to the API
9591
*
9692
* $var string
9793
*/
98-
const DEFAULT_NAMESPACE = 'http://api.service.softlayer.com/soap/v3/';
94+
const DEFAULT_NAMESPACE = 'http://api.service.softlayer.com/soap/v3.1/';
9995

10096

10197
/**
@@ -175,6 +171,7 @@ class SoapClient extends \SoapClient
175171
*/
176172
public $oneWay;
177173

174+
178175
/**
179176
* Execute a SoftLayer API method
180177
*
@@ -197,7 +194,7 @@ public function __call($functionName, $arguments = null)
197194
}
198195

199196
try {
200-
$result = parent::__call($functionName, $arguments, null, $this->_headers, null);
197+
$result = parent::__soapCall($functionName, $arguments, null, $this->_headers);
201198
} catch (SoapFault $e) {
202199
throw new \Exception('There was an error querying the SoftLayer API: ' . $e->getMessage());
203200
}
@@ -225,9 +222,10 @@ public function __call($functionName, $arguments = null)
225222
* @param string $username An optional API username if you wish to bypass SoapClient's built-in username.
226223
* @param string $username An optional API key if you wish to bypass SoapClient's built-in API key.
227224
* @param string $endpointUrl The API endpoint base URL you wish to connect to. Set this to SoapClient::API_PRIVATE_ENDPOINT to connect via SoftLayer's private network.
225+
* @param bool $trace Enabled SOAP trace in the client object.
228226
* @return SoapClient
229227
*/
230-
public static function getClient($serviceName, $id = null, $username = null, $apiKey = null, $endpointUrl = null)
228+
public static function getClient($serviceName, $id = null, $username = null, $apiKey = null, $endpointUrl = null, $trace=false)
231229
{
232230
$serviceName = trim($serviceName);
233231

@@ -252,12 +250,14 @@ public static function getClient($serviceName, $id = null, $username = null, $ap
252250
$endpointUrl = self::API_PUBLIC_ENDPOINT;
253251
}
254252

255-
if (is_null(self::SOAP_TIMEOUT)) {
256-
$soapClient = new self($endpointUrl . $serviceName . '?wsdl');
257-
} else {
258-
$soapClient = new self($endpointUrl . $serviceName . '?wsdl', array('connection_timeout' => self::SOAP_TIMEOUT));
253+
$soapOptions = ['trace' => $trace];
254+
if (is_null(self::SOAP_TIMEOUT) == false) {
255+
$soapOptions['connection_timeout'] = self::SOAP_TIMEOUT;
259256
}
260257

258+
$soapClient = new self($endpointUrl . $serviceName . '?wsdl', $soapOptions);
259+
260+
261261
$soapClient->_serviceName = $serviceName;
262262
$soapClient->_endpointUrl = $endpointUrl;
263263

@@ -350,7 +350,7 @@ public function setAuthentication($username, $apiKey)
350350
* 1234 in the SoftLayer_Hardware_Server Service instructs the API to act on
351351
* server record 1234 in your method calls.
352352
*
353-
* @link http://sldn.softlayer.com/article/Using_Initialization_Parameters_in_the_SoftLayer_API Using Initialization Parameters in the SoftLayer API
353+
* @link https://sldn.softlayer.com/article/using-initialization-parameters-softlayer-api/ Using Initialization Parameters in the SoftLayer API
354354
* @param int $id The ID number of the SoftLayer API object you wish to instantiate.
355355
* @return SoapClient
356356
*/
@@ -421,7 +421,7 @@ public function setObjectFilter($objectFilter)
421421
* support a way to limit the number of results retrieved from the SoftLayer
422422
* API in a way akin to an SQL LIMIT statement.
423423
*
424-
* @link http://sldn.softlayer.com/article/Using_Result_Limits_in_the_SoftLayer_API Using Result Limits in the SoftLayer API
424+
* @link https://sldn.softlayer.com/article/using-result-limits-softlayer-api/ Using Result Limits in the SoftLayer API
425425
* @param int $limit The number of results to limit your SoftLayer API call to.
426426
* @param int $offset An optional offset to begin your SoftLayer API call's returned result set at.
427427
* @return SoapClient

src/SoapClient/AsynchronousAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class AsynchronousAction
139139
protected $_socket;
140140

141141
/**
142-
* Perform an asynchgronous SoftLayer SOAP call
142+
* Perform an asynchronous SoftLayer SOAP call
143143
*
144144
* Create a raw socket connection to the URL specified by the
145145
* SoapClient class and send SOAP HTTP headers and request XML to

0 commit comments

Comments
 (0)