Skip to content

Commit dccaf56

Browse files
committed
Add ability to fetch all available customers.
1 parent 67906d4 commit dccaf56

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/PleskX/Api/Operator/Customer.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,23 @@ public function get($field, $value)
5252
return new Struct\GeneralInfo($response->data->gen_info);
5353
}
5454

55+
/**
56+
* @return Struct\GeneralInfo[]
57+
*/
58+
public function find()
59+
{
60+
$packet = $this->_client->getPacket();
61+
$getTag = $packet->addChild('customer')->addChild('get');
62+
$getTag->addChild('filter');
63+
$getTag->addChild('dataset')->addChild('gen_info');
64+
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
65+
66+
$customers = [];
67+
foreach ($response->xpath('//result') as $xmlResult) {
68+
$customers[] = new Struct\GeneralInfo($xmlResult->data->gen_info);
69+
}
70+
71+
return $customers;
72+
}
73+
5574
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ class GeneralInfo extends \PleskX\Api\Struct
1111
/** @var string */
1212
public $login;
1313

14+
/** @var string */
15+
public $guid;
16+
1417
public function __construct($apiResponse)
1518
{
1619
$this->_initScalarProperties($apiResponse, [
1720
['pname' => 'personalName'],
1821
'login',
22+
'guid',
1923
]);
2024
}
2125
}

tests/CustomerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,26 @@ public function testGet()
3636
$this->_client->customer()->delete('id', $customer->id);
3737
}
3838

39+
public function testFind()
40+
{
41+
$this->_client->customer()->create([
42+
'pname' => 'John Smith',
43+
'login' => 'customer-a',
44+
'passwd' => 'simple-password',
45+
]);
46+
$this->_client->customer()->create([
47+
'pname' => 'Mike Black',
48+
'login' => 'customer-b',
49+
'passwd' => 'simple-password',
50+
]);
51+
52+
$customersInfo = $this->_client->customer()->find();
53+
$this->assertCount(2, $customersInfo);
54+
$this->assertEquals('John Smith', $customersInfo[0]->personalName);
55+
$this->assertEquals('customer-a', $customersInfo[0]->login);
56+
57+
$this->_client->customer()->delete('login', 'customer-a');
58+
$this->_client->customer()->delete('login', 'customer-b');
59+
}
60+
3961
}

0 commit comments

Comments
 (0)