Completed
Pull Request — master (#56)
by
unknown
01:36
created

Webspace::getPhpSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
// Copyright 1999-2019. Plesk International GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\Webspace as Struct;
6
7
class Webspace extends \PleskX\Api\Operator
8
{
9
10
    public function getPermissionDescriptor()
11
    {
12
        $response = $this->request('get-permission-descriptor.filter');
13
        return new Struct\PermissionDescriptor($response);
14
    }
15
16
    public function getLimitDescriptor()
17
    {
18
        $response = $this->request('get-limit-descriptor.filter');
19
        return new Struct\LimitDescriptor($response);
20
    }
21
22
    public function getPhysicalHostingDescriptor()
23
    {
24
        $response = $this->request('get-physical-hosting-descriptor.filter');
25
        return new Struct\PhysicalHostingDescriptor($response);
26
    }
27
28
    /**
29
     * @param int $webspaceId
30
     * @return Struct\PhpSettings
31
     */
32
    public function getPhpSettings($webspaceId)
33
    {
34
        $packet = $this->_client->getPacket();
35
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
36
37
        $getTag->addChild('filter')->addChild('id', $webspaceId);
38
        $getTag->addChild('dataset')->addChild('php-settings');
39
40
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
41
42
        return new Struct\PhpSettings($response);
43
    }
44
45
    /**
46
     * @param array $properties
47
     * @param array|null $hostingProperties
48
     * @param $planName
49
     * @return Struct\Info
50
     */
51
    public function create(array $properties, array $hostingProperties = null, $planName = null)
52
    {
53
        $packet = $this->_client->getPacket();
54
        $info = $packet->addChild($this->_wrapperTag)->addChild('add');
55
56
        $infoGeneral = $info->addChild('gen_setup');
57
        foreach ($properties as $name => $value) {
58
            $infoGeneral->addChild($name, $value);
59
        }
60
61
        if ($hostingProperties) {
62
            $infoHosting = $info->addChild('hosting')->addChild('vrt_hst');
63
            foreach ($hostingProperties as $name => $value) {
64
                $property = $infoHosting->addChild('property');
65
                $property->addChild('name', $name);
66
                $property->addChild('value', $value);
67
            }
68
69
            if (isset($properties['ip_address'])) {
70
                $infoHosting->addChild("ip_address", $properties['ip_address']);
71
            }
72
        }
73
74
        if ($planName) {
75
            $info->addChild('plan-name', $planName);
76
        }
77
78
        $response = $this->_client->request($packet);
79
        return new Struct\Info($response);
80
    }
81
82
    /**
83
     * @param string $field
84
     * @param integer|string $value
85
     * @return bool
86
     */
87
    public function delete($field, $value)
88
    {
89
        return $this->_delete($field, $value);
90
    }
91
92
    /**
93
     * @param string $field
94
     * @param integer|string $value
95
     * @return Struct\GeneralInfo
96
     */
97
    public function get($field, $value)
98
    {
99
        $items = $this->_getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value);
100
        return reset($items);
101
    }
102
103
    /**
104
     * @return Struct\GeneralInfo[]
105
     */
106
    public function getAll()
107
    {
108
        return $this->_getItems(Struct\GeneralInfo::class, 'gen_info');
109
    }
110
111
    /**
112
     * @param string $field
113
     * @param integer|string $value
114
     * @return Struct\DiskUsage
115
     */
116
    public function getDiskUsage($field, $value)
117
    {
118
        $items = $this->_getItems(Struct\DiskUsage::class, 'disk_usage', $field, $value);
119
        return reset($items);
120
    }
121
122
}
123