Skip to content

Commit fd55a52

Browse files
committed
Merge branch '179-missing-support-for-custom-hostname-update-properties' of github.com:phily245/cloudflare-php into 179-missing-support-for-custom-hostname-update-properties
2 parents 3b167ba + bfb2420 commit fd55a52

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/Endpoints/CustomHostnames.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,50 @@ public function __construct(Adapter $adapter)
3030
* @param string $hostname
3131
* @param string $sslMethod
3232
* @param string $sslType
33-
* @param array $sslSettings
33+
* @param array $sslSettings
3434
* @param string $customOriginServer
35-
* @param bool $wildcard
35+
* @param bool $wildcard
36+
* @param string $bundleMethod
37+
* @param array $customSsl
3638
* @return \stdClass
3739
*/
38-
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv', array $sslSettings = [], string $customOriginServer = '', bool $wildcard = false): \stdClass
39-
{
40+
public function addHostname(
41+
string $zoneID,
42+
string $hostname,
43+
string $sslMethod = 'http',
44+
string $sslType = 'dv',
45+
array $sslSettings = [],
46+
string $customOriginServer = '',
47+
bool $wildcard = false,
48+
string $bundleMethod = '',
49+
array $customSsl = []
50+
): \stdClass {
4051
$options = [
4152
'hostname' => $hostname,
4253
'ssl' => [
4354
'method' => $sslMethod,
4455
'type' => $sslType,
45-
'settings' => $sslSettings
56+
'settings' => $sslSettings,
57+
'wildcard' => $wildcard,
4658
],
47-
'wildcard' => $wildcard,
4859
];
4960

5061
if (!empty($customOriginServer)) {
5162
$options['custom_origin_server'] = $customOriginServer;
5263
}
5364

65+
if (!empty($bundleMethod)) {
66+
$options['ssl']['bundle_method'] = $bundleMethod;
67+
}
68+
69+
if (!empty($customSsl['key'])) {
70+
$options['ssl']['custom_key'] = $customSsl['key'];
71+
}
72+
73+
if (!empty($customSsl['certificate'])) {
74+
$options['ssl']['custom_certificate'] = $customSsl['certificate'];
75+
}
76+
5477
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
5578
$this->body = json_decode($zone->getBody());
5679
return $this->body->result;

tests/Endpoints/CustomHostnamesTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public function testAddHostname()
1414
{
1515
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json');
1616

17+
$customSsl = $this->getCustomSsl();
18+
1719
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
1820
$mock->method('post')->willReturn($response);
1921

@@ -30,10 +32,13 @@ public function testAddHostname()
3032
'settings' => [
3133
'http2' => 'on',
3234
'http3' => 'on',
33-
'min_tls_version' => '1.2'
34-
]
35+
'min_tls_version' => '1.2',
36+
],
37+
'bundle_method' => 'optimal',
38+
'custom_key' => $customSsl['key'],
39+
'custom_certificate' => $customSsl['certificate'],
40+
'wildcard' => true,
3541
],
36-
'wildcard' => true,
3742
])
3843
);
3944

@@ -43,7 +48,18 @@ public function testAddHostname()
4348
'http3' => 'on',
4449
'min_tls_version' => '1.2'
4550
];
46-
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv', $sslSettings, 'origin.example.com', true);
51+
52+
$hostname->addHostname(
53+
'023e105f4ecef8ad9ca31a8372d0c353',
54+
'app.example.com',
55+
'http',
56+
'dv',
57+
$sslSettings,
58+
'origin.example.com',
59+
true,
60+
'optimal',
61+
$customSsl
62+
);
4763
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id);
4864
}
4965

0 commit comments

Comments
 (0)