Skip to content

Commit 974d4b7

Browse files
authored
Merge pull request #2 from coderashed/site-alias
Site alias
2 parents f88b7d0 + 31822bf commit 974d4b7

File tree

5 files changed

+103
-12
lines changed

5 files changed

+103
-12
lines changed

src/PleskX/Api/Client.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 32 additions & 2 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
@@ -25,10 +27,38 @@ public function create(array $properties, array $preferences = [])
2527
}
2628
}
2729

28-
$info->addChild('site-id', $properties['site-id']);
29-
$info->addChild('name', $properties['name']);
30+
foreach($properties as $key => $val)
31+
{
32+
$info->addChild($key,$val);
33+
}
34+
35+
$response = $this->_client->request($packet);
36+
return new Struct\Info($response);
37+
}
38+
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,$this->_client::RESPONSE_FULL);
48+
49+
return new Struct\Info($response);
50+
}
51+
52+
public function delete($site_id)
53+
{
54+
$packet = $this->_client->getPacket();
3055

56+
$delete = $packet->addChild($this->_wrapperTag)->addChild('delete');
57+
58+
$filter = $delete->addChild('filter');
59+
$filter->addChild('site-id',$site_id);
3160
$response = $this->_client->request($packet);
61+
3262
return new Struct\Info($response);
3363
}
3464

src/PleskX/Api/Struct.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ protected function _initScalarProperties($apiResponse, array $properties)
3131

3232
$reflectionProperty = new \ReflectionProperty($this, $classPropertyName);
3333
$docBlock = $reflectionProperty->getDocComment();
34-
$propertyType = preg_replace('/^.+ @var ([a-z]+) .+$/', '\1', $docBlock);
3534

35+
/* There seems to be a bug in the api when it encounters a docBlock with a strlen of 0.
36+
* Continue if so.
37+
*/
38+
if(strlen($docBlock) == 0)
39+
continue;
40+
41+
$propertyType = preg_replace('/^.+ @var ([a-z]+) .+$/', '\1', $docBlock);
3642
if ('string' == $propertyType) {
3743
$value = (string)$value;
3844
} else if ('integer' == $propertyType) {

src/PleskX/Api/Struct/Site/GeneralInfo.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
class GeneralInfo extends \PleskX\Api\Struct
77
{
8+
/** @var string */
9+
public $id;
10+
811
/** @var string */
912
public $name;
1013

@@ -17,6 +20,8 @@ class GeneralInfo extends \PleskX\Api\Struct
1720
/** @var string */
1821
public $description;
1922

23+
24+
2025
public function __construct($apiResponse)
2126
{
2227
$this->_initScalarProperties($apiResponse, [
@@ -25,5 +30,10 @@ public function __construct($apiResponse)
2530
'guid',
2631
'description',
2732
]);
33+
34+
$encoded = json_encode($apiResponse);
35+
$decoded = json_decode($encoded);
36+
37+
$this->id = $decoded->{'webspace-id'};
2838
}
2939
}

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

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,65 @@
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 */
129
public $id;
10+
public $status;
11+
12+
public $site_id;
13+
14+
private $array = array();
15+
16+
private $position = 0;
1317

1418
public function __construct($apiResponse)
1519
{
16-
$this->_initScalarProperties($apiResponse, [
17-
'id',
18-
'status',
19-
]);
20+
$json = json_encode($apiResponse);
21+
$responses = json_decode($json);
22+
23+
if(isset($responses->{'site-alias'}->get->result) && count($responses->{'site-alias'}->get->result) > 1) {
24+
foreach ($responses->{'site-alias'}->get->result as $response) {
25+
if(isset($response->info)) {
26+
$this->array[] = array(
27+
'name' => $response->info->name,
28+
'ascii-name' => $response->info->{'ascii-name'}
29+
);
30+
}
31+
}
32+
}
33+
else {
34+
$this->_initScalarProperties($apiResponse, [
35+
'id',
36+
'status'
37+
]);
38+
}
39+
}
40+
41+
public function rewind() {
42+
$this->position = 0;
43+
}
44+
45+
public function current() {
46+
return $this->array[$this->position];
47+
}
48+
49+
public function key() {
50+
return $this->position;
51+
}
52+
53+
public function next()
54+
{
55+
++$this->position;
56+
}
57+
58+
public function valid()
59+
{
60+
return isset($this->array[$this->position]);
61+
}
62+
63+
public function name()
64+
{
65+
return $this->array[$this->position]['site-name'];
2066
}
2167
}

0 commit comments

Comments
 (0)