Skip to content

Commit 0bc44f4

Browse files
committed
* Added the ability to get siteAliases
- Not implemented in the API. * Turned the siteAlias info object into an object implementing the Iterator interface to fix an oversight in the php plesk api. - API hardcoded 0 as the element in the returned response, then the rest of the api assumes there is only one result. -- This fails in the event of the API returning more than one result, such as site aliases. causing it to only return the first result found.
1 parent a5e6e7c commit 0bc44f4

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

src/PleskX/Api/Client.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function request($request, $mode = self::RESPONSE_SHORT)
163163
? call_user_func($this->_verifyResponseCallback, $xml)
164164
: $this->_verifyResponse($xml);
165165

166-
return (self::RESPONSE_FULL == $mode) ? $xml : $xml->xpath('//result')[0];
166+
return (self::RESPONSE_FULL == $mode) ? $xml : $xml->xpath('//result');
167167
}
168168

169169
/**
@@ -200,7 +200,6 @@ private function _performHttpRequest($request)
200200
}
201201

202202
curl_close($curl);
203-
204203
$xml = new XmlResponse($result);
205204
return $xml;
206205
}

src/PleskX/Api/Operator/SiteAlias.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class SiteAlias extends \PleskX\Api\Operator
99
{
10+
11+
1012
/**
1113
* @param array $properties
1214
* @param array $preferences
@@ -34,4 +36,19 @@ public function create(array $properties, array $preferences = [])
3436
return new Struct\Info($response);
3537
}
3638

39+
public function get($site_id)
40+
{
41+
$packet = $this->_client->getPacket();
42+
43+
$get = $packet->addChild($this->_wrapperTag)->addChild('get');
44+
45+
$filter = $get->addChild('filter');
46+
$filter->addChild('site-id',$site_id);
47+
$response = $this->_client->request($packet);
48+
49+
return new Struct\Info($response);
50+
//$packet->saveXML('/var/www/vagrant/ataama_development/application/logs/ataama/development/portal/xml');
51+
return $response;
52+
}
53+
3754
}

src/PleskX/Api/Struct/SiteAlias/Info.php

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,47 @@
33

44
namespace PleskX\Api\Struct\SiteAlias;
55

6-
class Info extends \PleskX\Api\Struct
6+
class Info extends \PleskX\Api\Struct implements \Iterator
77
{
8-
/** @var string */
9-
public $status;
108

11-
/** @var integer */
12-
public $id;
9+
public $site_id;
10+
11+
private $array = array();
12+
13+
private $position = 0;
1314

1415
public function __construct($apiResponse)
1516
{
16-
$this->_initScalarProperties($apiResponse, [
17-
'id',
18-
'status',
19-
]);
17+
$json = json_encode($apiResponse);
18+
$responses = json_decode($json);
19+
20+
$this->site_id = $responses[0]->id;
21+
22+
foreach($responses as $response) {
23+
$this->array[] = array(
24+
'site-name' => $response->info->name,
25+
'ascii-name' => $response->info->{'ascii-name'}
26+
);
27+
}
28+
}
29+
30+
public function rewind() {
31+
$this->position = 0;
32+
}
33+
34+
public function current() {
35+
return $this->array[$this->position];
36+
}
37+
38+
public function key() {
39+
return $this->position;
40+
}
41+
42+
public function next() {
43+
++$this->position;
44+
}
45+
46+
public function valid() {
47+
return isset($this->array[$this->position]);
2048
}
2149
}

0 commit comments

Comments
 (0)