Skip to content

Commit 115511a

Browse files
committed
Add an ability to enable/disable webspace and set other properties
1 parent 8d45955 commit 115511a

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

src/Api/Operator/Webspace.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,48 @@ public function getDiskUsage(string $field, $value): Struct\DiskUsage
144144

145145
return reset($items);
146146
}
147+
148+
/**
149+
* @param string $field
150+
* @param int|string $value
151+
*
152+
* @return bool
153+
*/
154+
public function enable(string $field, $value): bool
155+
{
156+
return $this->setProperties($field, $value, ['status' => 0]);
157+
}
158+
159+
/**
160+
* @param string $field
161+
* @param int|string $value
162+
*
163+
* @return bool
164+
*/
165+
public function disable(string $field, $value): bool
166+
{
167+
return $this->setProperties($field, $value, ['status' => 1]);
168+
}
169+
170+
/**
171+
* @param string $field
172+
* @param int|string $value
173+
* @param array $properties
174+
*
175+
* @return bool
176+
*/
177+
public function setProperties(string $field, $value, array $properties): bool
178+
{
179+
$packet = $this->_client->getPacket();
180+
$setTag = $packet->addChild($this->_wrapperTag)->addChild('set');
181+
$setTag->addChild('filter')->addChild($field, (string) $value);
182+
$genInfoTag = $setTag->addChild('values')->addChild('gen_setup');
183+
foreach ($properties as $property => $propertyValue) {
184+
$genInfoTag->addChild($property, (string) $propertyValue);
185+
}
186+
187+
$response = $this->_client->request($packet);
188+
189+
return 'ok' === (string) $response->status;
190+
}
147191
}

src/Api/Struct/Webspace/GeneralInfo.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class GeneralInfo extends Struct
1818
public string $guid;
1919
public string $vendorGuid;
2020
public string $description;
21-
22-
/** @var string */
2321
public string $adminDescription;
22+
public bool $enabled;
2423

2524
public function __construct(\SimpleXMLElement $apiResponse)
2625
{
@@ -40,5 +39,7 @@ public function __construct(\SimpleXMLElement $apiResponse)
4039
foreach ($apiResponse->dns_ip_address as $ip) {
4140
$this->ipAddresses[] = (string) $ip;
4241
}
42+
43+
$this->enabled = '0' === (string) $apiResponse->status;
4344
}
4445
}

tests/WebspaceTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,39 @@ public function testGet()
187187

188188
static::$_client->webspace()->delete('id', $webspace->id);
189189
}
190+
191+
public function testEnable()
192+
{
193+
$webspace = static::_createWebspace();
194+
195+
static::$_client->webspace()->disable('id', $webspace->id);
196+
static::$_client->webspace()->enable('id', $webspace->id);
197+
$webspaceInfo = static::$_client->webspace()->get('id', $webspace->id);
198+
$this->assertTrue($webspaceInfo->enabled);
199+
200+
static::$_client->webspace()->delete('id', $webspace->id);
201+
}
202+
203+
public function testDisable()
204+
{
205+
$webspace = static::_createWebspace();
206+
207+
static::$_client->webspace()->disable('id', $webspace->id);
208+
$webspaceInfo = static::$_client->webspace()->get('id', $webspace->id);
209+
$this->assertFalse($webspaceInfo->enabled);
210+
211+
static::$_client->webspace()->delete('id', $webspace->id);
212+
}
213+
214+
public function testSetProperties()
215+
{
216+
$webspace = static::_createWebspace();
217+
static::$_client->webspace()->setProperties('id', $webspace->id, [
218+
'description' => 'Test Description',
219+
]);
220+
$webspaceInfo = static::$_client->webspace()->get('id', $webspace->id);
221+
$this->assertEquals('Test Description', $webspaceInfo->description);
222+
223+
static::$_client->webspace()->delete('id', $webspace->id);
224+
}
190225
}

0 commit comments

Comments
 (0)