diff --git a/src/Endpoints/CustomHostnames.php b/src/Endpoints/CustomHostnames.php index a7f09b0..8846c06 100644 --- a/src/Endpoints/CustomHostnames.php +++ b/src/Endpoints/CustomHostnames.php @@ -14,7 +14,7 @@ use Cloudflare\API\Traits\BodyAccessorTrait; class CustomHostnames implements API { use BodyAccessorTrait; - + private $adapter; public function __construct(Adapter $adapter) @@ -30,12 +30,15 @@ class CustomHostnames implements API * @param string $hostname * @param string $sslMethod * @param string $sslType - * @param array $sslSettings + * @param array $sslSettings * @param string $customOriginServer - * @param bool $wildcard + * @param bool $wildcard + * @param string $bundleMethod + * @param string $customKey + * @param string $customCertificate * @return \stdClass */ - public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv', array $sslSettings = [], string $customOriginServer = '', bool $wildcard = false): \stdClass + public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv', array $sslSettings = [], string $customOriginServer = '', bool $wildcard = false, string $bundleMethod = '', string $customKey = '', string $customCertificate = ''): \stdClass { $options = [ 'hostname' => $hostname, @@ -51,6 +54,18 @@ class CustomHostnames implements API $options['custom_origin_server'] = $customOriginServer; } + if (empty($bundleMethod) === false) { + $options['bundle_method'] = $bundleMethod; + } + + if (empty($customKey) === false) { + $options['custom_key'] = $customKey; + } + + if (empty($customCertificate) === false) { + $options['custom_certificate'] = $customCertificate; + } + $zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options); $this->body = json_decode($zone->getBody()); return $this->body->result; diff --git a/tests/Endpoints/CustomHostnamesTest.php b/tests/Endpoints/CustomHostnamesTest.php index 7298d86..4cfd971 100644 --- a/tests/Endpoints/CustomHostnamesTest.php +++ b/tests/Endpoints/CustomHostnamesTest.php @@ -17,6 +17,61 @@ class CustomHostnamesTest extends TestCase $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); $mock->method('post')->willReturn($response); + $customKey = <<expects($this->once()) ->method('post') ->with( @@ -33,6 +88,9 @@ class CustomHostnamesTest extends TestCase 'min_tls_version' => '1.2' ] ], + 'bundle_method' => 'optimal', + 'custom_key' => $customKey, + 'custom_certificate' => $customCertificate, 'wildcard' => true, ]) ); @@ -43,7 +101,7 @@ class CustomHostnamesTest extends TestCase 'http3' => 'on', 'min_tls_version' => '1.2' ]; - $hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv', $sslSettings, 'origin.example.com', true); + $hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv', $sslSettings, 'origin.example.com', true, 'optimal', $customKey, $customCertificate); $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id); }