Completed
Push — master ( 7671cb...b4a464 )
by Alexei
01:55
created

DatabaseServer::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\DatabaseServer as Struct;
6
7
8
class DatabaseServer extends \PleskX\Api\Operator
9
{
10
11
    protected $_wrapperTag = 'db_server';
12
13
    /**
14
     * @return array
15
     */
16
    public function getSupportedTypes()
17
    {
18
        $response = $this->request('get-supported-types');
19
        return (array)$response->type;
20
    }
21
22
    /**
23
     * @param string $field
24
     * @param integer|string $value
25
     * @return Struct\Info
26
     */
27
    public function get($field, $value)
28
    {
29
        $customers = $this->_get($field, $value);
30
        return reset($customers);
31
    }
32
33
    /**
34
     * @return Struct\Info[]
35
     */
36
    public function getAll()
37
    {
38
        return $this->_get();
39
    }
40
41
    /**
42
     * @param string|null $field
43
     * @param integer|string|null $value
44
     * @return Struct\Info|Struct\Info[]
45
     */
46
    private function _get($field = null, $value = null)
47
    {
48
        $packet = $this->_client->getPacket();
49
        $getTag = $packet->addChild('db_server')->addChild('get');
50
51
        $filterTag = $getTag->addChild('filter');
52
        if (!is_null($field)) {
53
            $filterTag->addChild($field, $value);
54
        }
55
56
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
57
58
        $items = [];
59
        foreach ($response->xpath('//result') as $xmlResult) {
60
            $items[] = new Struct\Info($xmlResult->data);
61
        }
62
63
        return $items;
64
    }
65
66
}
67