Skip to content

Commit c7939aa

Browse files
Merge pull request #43 from plesk/task-lbinde-add-operator-phphandler
Add new operator: PhpHandler
2 parents 9902d6f + 8e6201e commit c7939aa

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

src/PleskX/Api/Client.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,12 @@ public function site()
555555
{
556556
return $this->_getOperator('Site');
557557
}
558+
559+
/**
560+
* @return Operator\PhpHandler
561+
*/
562+
public function phpHandler()
563+
{
564+
return $this->_getOperator('PhpHandler');
565+
}
558566
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
// Copyright 1999-2018. Parallels IP Holdings GmbH.
3+
4+
namespace PleskX\Api\Operator;
5+
6+
use PleskX\Api\Client;
7+
use PleskX\Api\Operator;
8+
use PleskX\Api\Struct\PhpHandler\Info;
9+
10+
class PhpHandler extends Operator
11+
{
12+
/**
13+
* @param string $field
14+
* @param integer|string $value
15+
* @return Info
16+
*/
17+
public function get($field, $value)
18+
{
19+
$packet = $this->_client->getPacket();
20+
$getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
21+
$filterTag = $getTag->addChild('filter');
22+
23+
if (!is_null($field)) {
24+
$filterTag->addChild($field, $value);
25+
}
26+
27+
$response = $this->_client->request($packet, Client::RESPONSE_FULL);
28+
$xmlResult = $response->xpath('//result')[0];
29+
30+
return new Info($xmlResult);
31+
}
32+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
// Copyright 1999-2018. Parallels IP Holdings GmbH.
3+
4+
namespace PleskX\Api\Struct\PhpHandler;
5+
6+
use PleskX\Api\Struct;
7+
8+
class Info extends Struct
9+
{
10+
/** @var string */
11+
public $id;
12+
13+
/** @var string */
14+
public $displayName;
15+
16+
/** @var string */
17+
public $fullVersion;
18+
19+
/** @var string */
20+
public $version;
21+
22+
/** @var string */
23+
public $type;
24+
25+
/** @var string */
26+
public $path;
27+
28+
/** @var string */
29+
public $clipath;
30+
31+
/** @var string */
32+
public $phpini;
33+
34+
/** @var string */
35+
public $custom;
36+
37+
/** @var string */
38+
public $handlerStatus;
39+
40+
public function __construct($apiResponse)
41+
{
42+
$this->_initScalarProperties($apiResponse, [
43+
'id',
44+
'display-name',
45+
'full-version',
46+
'version',
47+
'type',
48+
'path',
49+
'clipath',
50+
'phpini',
51+
'custom',
52+
'handler-status',
53+
]);
54+
}
55+
}

tests/PhpHandlerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
// Copyright 1999-2018. Parallels IP Holdings GmbH.
3+
4+
class PhpHandlerTest extends TestCase
5+
{
6+
const PHP_HANDLER_ID = 'fpm';
7+
8+
public function testGet()
9+
{
10+
$handler = static::$_client->phpHandler()->get('id', self::PHP_HANDLER_ID);
11+
12+
$this->assertSame(self::PHP_HANDLER_ID, $handler->id);
13+
}
14+
15+
/**
16+
* @expectedException \PleskX\Api\Exception
17+
* @expectedExceptionMessage Php handler does not exists
18+
*/
19+
public function testGetUnknownHandlerThrowsException()
20+
{
21+
static::$_client->phpHandler()->get('id', 'this-handler-does-not-exist');
22+
}
23+
}

0 commit comments

Comments
 (0)