Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/Api/Operator/ServicePlanAddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,73 @@

namespace PleskX\Api\Operator;

use PleskX\Api\Struct\ServicePlanAddon as Struct;

class ServicePlanAddon extends \PleskX\Api\Operator
{

public function create(array $properties): Struct\Info
{
$response = $this->request(['add' => $properties]);

return new Struct\Info($response);
}

/**
* @param string $field
* @param int|string $value
*
* @return bool
*/
public function delete(string $field, $value): bool
{
return $this->deleteBy($field, $value);
}

/**
* @param string $field
* @param int|string $value
*
* @return Struct\Info
*/
public function get(string $field, $value): Struct\Info
{
$items = $this->getBy($field, $value);

return reset($items);
}

/**
* @return Struct\Info[]
*/
public function getAll(): array
{
return $this->getBy();
}

/**
* @param string|null $field
* @param int|string|null $value
*
* @return Struct\Info[]
*/
private function getBy($field = null, $value = null): array
{
$packet = $this->client->getPacket();
$getTag = $packet->addChild($this->wrapperTag)->addChild('get');

$filterTag = $getTag->addChild('filter');
if (!is_null($field)) {
$filterTag->addChild($field, (string) $value);
}

$response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);

$items = [];
foreach ($response->xpath('//result') as $xmlResult) {
$items[] = new Struct\Info($xmlResult);
}

return $items;
}
}
24 changes: 24 additions & 0 deletions src/Api/Struct/ServicePlanAddon/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
// Copyright 1999-2022. Plesk International GmbH.

namespace PleskX\Api\Struct\ServicePlanAddon;

use PleskX\Api\AbstractStruct;

class Info extends AbstractStruct
{
public int $id;
public string $name;
public string $guid;
public string $externalId;

public function __construct(\SimpleXMLElement $apiResponse)
{
$this->initScalarProperties($apiResponse, [
'id',
'name',
'guid',
'external-id',
]);
}
}