Skip to content
This repository was archived by the owner on Mar 20, 2022. It is now read-only.

Commit 048493a

Browse files
committed
added custom-port option via configuration-file
1 parent 4c48e26 commit 048493a

File tree

9 files changed

+129
-24
lines changed

9 files changed

+129
-24
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-plesk-xml` will be documented in this file
44

5+
## 0.5.1 - 2019-09-09
6+
7+
- Added support for custom port via configuration-file
8+
59
## 0.5.0 - 2019-09-04
610

711
- Added support for Laravel 6

composer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"spatie/array-to-xml": "^2.7"
1111
},
1212
"require-dev": {
13-
"phpunit/phpunit": "^7.5|^8.0"
13+
"orchestra/testbench": "^3.8|^4.0"
1414
},
1515
"autoload": {
1616
"psr-4": {
@@ -20,6 +20,11 @@
2020
"src/helpers.php"
2121
]
2222
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"nickurt\\PleskXml\\tests\\": "tests"
26+
}
27+
},
2328
"scripts": {
2429
"test": "vendor/bin/phpunit",
2530
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

src/Api/AbstractApi.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function post($parameters)
3131
$parameters = ArrayToXml::convert($parameters, [
3232
'rootElementName' => 'packet',
3333
'_attributes' => [
34-
'version' => $this->client->getHttpClient()->getOptions()['api_version'],
34+
'version' => $this->client->getHttpClient()->getOptions()['version'],
3535
],
3636
]);
3737

@@ -41,4 +41,4 @@ protected function post($parameters)
4141

4242
return $response;
4343
}
44-
}
44+
}

src/Client.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class Client implements ClientInterface
1515
* @var array
1616
*/
1717
private $options = [
18-
'api_port' => '8443',
19-
'api_version' => '1.6.9.1',
18+
'port' => '8443',
19+
'version' => '1.6.9.1',
2020
];
2121

2222
/**
@@ -106,12 +106,22 @@ public function getHttpClient()
106106
}
107107

108108
/**
109-
* @param $host
109+
* @param string $host
110110
*/
111111
public function setHost($host)
112112
{
113113
$this->getHttpClient()->setOptions([
114-
'base_url' => sprintf('https://%s:8443/enterprise/control/agent.php', $host)
114+
'host' => $host
115115
]);
116116
}
117-
}
117+
118+
/**
119+
* @param int $port
120+
*/
121+
public function setPort($port)
122+
{
123+
$this->getHttpClient()->setOptions([
124+
'port' => $port
125+
]);
126+
}
127+
}

src/HttpClient/HttpClient.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function request($body, $method)
4747
{
4848
$response = $this->client->request(
4949
$method,
50-
$this->getOptions()['base_url'],
50+
sprintf('https://%s:%s%s', $this->getOptions()['host'], $this->getOptions()['port'], '/enterprise/control/agent.php'),
5151
[
5252
'headers' => $this->getHeaders(),
5353
'body' => $body
@@ -88,4 +88,4 @@ public function setHeaders(array $headers)
8888
{
8989
$this->headers = array_merge($this->headers, $headers);
9090
}
91-
}
91+
}

src/Plesk.php

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ protected function resolve($name)
7676

7777
$this->client = new \nickurt\PleskXml\Client();
7878
$this->client->setHost($config['host']);
79+
$this->client->setPort($config['port'] ?? 8443);
7980
$this->client->setCredentials(
8081
$config['username'],
8182
$config['password']

tests/ExampleTest.php

-14
This file was deleted.

tests/PleskXmlTest.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace nickurt\PleskXml\tests;
4+
5+
use nickurt\PleskXml\Facade as Plesk;
6+
7+
class PleskXmlTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_can_use_a_custom_plesk_server()
11+
{
12+
config(['plesk-xml.default' => 'custom']);
13+
14+
$plesk = Plesk::getHttpClient();
15+
16+
$this->assertSame('https://xml-plesk-xml.tld:8444/enterprise/control/agent.php', sprintf(
17+
'https://%s:%s%s', $plesk->getOptions()['host'], $plesk->getOptions()['port'], '/enterprise/control/agent.php'
18+
));
19+
20+
$this->assertSame('xml-plesk-xml.tld', $plesk->getOptions()['host']);
21+
$this->assertSame(8444, $plesk->getOptions()['port']);
22+
23+
$this->assertSame('xml-plesk-xml', $plesk->getHeaders()['HTTP_AUTH_LOGIN']);
24+
$this->assertSame('plesk-xml-plesk', $plesk->getHeaders()['HTTP_AUTH_PASSWD']);
25+
}
26+
27+
/** @test */
28+
public function it_can_use_the_default_plesk_server()
29+
{
30+
$plesk = Plesk::getHttpClient();
31+
32+
$this->assertSame('https://plesk-xml.tld:8443/enterprise/control/agent.php', sprintf(
33+
'https://%s:%s%s', $plesk->getOptions()['host'], $plesk->getOptions()['port'], '/enterprise/control/agent.php'
34+
));
35+
36+
$this->assertSame('plesk-xml.tld', $plesk->getOptions()['host']);
37+
$this->assertSame(8443, $plesk->getOptions()['port']);
38+
39+
$this->assertSame('plesk-xml', $plesk->getHeaders()['HTTP_AUTH_LOGIN']);
40+
$this->assertSame('xml-plesk', $plesk->getHeaders()['HTTP_AUTH_PASSWD']);
41+
}
42+
}

tests/TestCase.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace nickurt\PleskXml\Tests;
4+
5+
use Orchestra\Testbench\TestCase as Orchestra;
6+
7+
class TestCase extends Orchestra
8+
{
9+
/**
10+
* Define environment setup.
11+
*
12+
* @param \Illuminate\Foundation\Application $app
13+
*
14+
* @return void
15+
*/
16+
protected function getEnvironmentSetUp($app)
17+
{
18+
config()->set('plesk-xml', [
19+
'default' => 'default',
20+
'servers' => [
21+
'default' => [
22+
'host' => 'plesk-xml.tld',
23+
'username' => 'plesk-xml',
24+
'password' => 'xml-plesk',
25+
],
26+
'custom' => [
27+
'host' => 'xml-plesk-xml.tld',
28+
'port' => 8444,
29+
'username' => 'xml-plesk-xml',
30+
'password' => 'plesk-xml-plesk',
31+
]
32+
],
33+
]);
34+
}
35+
36+
/**
37+
* @param \Illuminate\Foundation\Application $app
38+
* @return array
39+
*/
40+
protected function getPackageAliases($app)
41+
{
42+
return [
43+
'PleskXml' => \nickurt\PleskXml\Facade::class
44+
];
45+
}
46+
47+
/**
48+
* @param \Illuminate\Foundation\Application $app
49+
* @return array
50+
*/
51+
protected function getPackageProviders($app)
52+
{
53+
return [
54+
\nickurt\PleskXml\ServiceProvider::class
55+
];
56+
}
57+
}

0 commit comments

Comments
 (0)