Skip to content

Commit 7ea6669

Browse files
committed
Adding get() and getAll() to SiteAlias
1 parent fc561b2 commit 7ea6669

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/Api/Operator/SiteAlias.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,38 @@ public function create(array $properties, array $preferences = [])
3232
return new Struct\Info($response);
3333
}
3434

35+
/**
36+
* @param string $field
37+
* @param integer|string $value
38+
* @return Struct\Info
39+
*/
40+
public function get($field, $value)
41+
{
42+
$items = $this->getAll($field, $value);
43+
return reset($items);
44+
}
45+
46+
/**
47+
* @param string $field
48+
* @param integer|string $value
49+
* @return Struct\Info[]
50+
*/
51+
public function getAll($field = null, $value = null)
52+
{
53+
$packet = $this->_client->getPacket();
54+
$getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
55+
56+
$filterTag = $getTag->addChild('filter');
57+
if (!is_null($field)) {
58+
$filterTag->addChild($field, $value);
59+
}
60+
61+
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
62+
$items = [];
63+
foreach ($response->xpath('//result') as $xmlResult) {
64+
$item = new Struct\GeneralInfo($xmlResult->info);
65+
$items[] = $item;
66+
}
67+
return $items;
68+
}
3569
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
// Copyright 1999-2019. Plesk International GmbH.
3+
4+
namespace PleskX\Api\Struct\SiteAlias;
5+
6+
class GeneralInfo extends \PleskX\Api\Struct
7+
{
8+
/** @var string */
9+
public $name;
10+
11+
/** @var string */
12+
public $asciiName;
13+
14+
/** @var string */
15+
public $status;
16+
17+
public function __construct($apiResponse)
18+
{
19+
$this->_initScalarProperties($apiResponse, [
20+
'name',
21+
'ascii-name',
22+
'status',
23+
]);
24+
}
25+
}

0 commit comments

Comments
 (0)