Skip to content

Commit

Permalink
Merge pull request #72 from frankvanhest/71-added_interfaces_for_conn…
Browse files Browse the repository at this point in the history
…ector_and_powerdns

Added interfaces for Connector and Powerdns
  • Loading branch information
trizz authored Jun 7, 2021
2 parents 1b0d718 + aa75e83 commit 1ea298f
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/AbstractZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ abstract class AbstractZone
protected $zoneResource;

/**
* @var Connector The PowerDNS Connector to make calls.
* @var ConnectorInterface The PowerDNS Connector to make calls.
*/
protected $connector;

/**
* The class constructor.
*
* @param Connector $connector The zone to use.
* @param null|string $canonicalDomain The PowerDNS Connector to make calls.
* @param ConnectorInterface $connector The zone to use.
* @param null|string $canonicalDomain The PowerDNS Connector to make calls.
*/
public function __construct(Connector $connector, ?string $canonicalDomain = null)
public function __construct(ConnectorInterface $connector, ?string $canonicalDomain = null)
{
$this->connector = $connector;

Expand Down
2 changes: 1 addition & 1 deletion src/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response as PsrResponse;

class Connector
class Connector implements ConnectorInterface
{
/**
* @var GuzzleClient The Guzzle client.
Expand Down
58 changes: 58 additions & 0 deletions src/ConnectorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Exonet\Powerdns;

use Exonet\Powerdns\Transformers\Transformer;

interface ConnectorInterface
{
/**
* Perform a GET request and return the parsed body as response.
*
* @param string $urlPath The URL path.
*
* @return mixed[] The response body.
*/
public function get(string $urlPath): array;

/**
* Perform a POST request and return the parsed body as response.
*
* @param string $urlPath The URL path.
* @param Transformer $payload The payload to post.
*
* @return mixed[] The response body.
*/
public function post(string $urlPath, Transformer $payload): array;

/**
* Perform a PATCH request and return the parsed body as response.
*
* @param string $urlPath The URL path.
* @param Transformer $payload The payload to patch.
*
* @return mixed[] The response body.
*/
public function patch(string $urlPath, Transformer $payload): array;

/**
* Perform a PUT request and return the parsed body as response.
*
* @param string $urlPath The URL path.
* @param Transformer|null $payload The payload to put.
*
* @return mixed[] The response body.
*/
public function put(string $urlPath, Transformer $payload = null): array;

/**
* Perform a DELETE request and return the parsed body as response.
*
* @param string $urlPath The URL path.
*
* @return mixed[] The response body.
*/
public function delete(string $urlPath): array;
}
4 changes: 2 additions & 2 deletions src/Cryptokey.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class Cryptokey extends AbstractZone
/**
* Crypto Key constructor.
*
* @param Connector $connector The zone to use.
* @param ConnectorInterface $connector The zone to use.
* @param null|string $canonicalDomain The Powerdns Connector to make calls.
* @param CryptokeyResource|null $cryptoKeyResource The cryptokey resource class to use for API responses.
*/
public function __construct(
Connector $connector,
ConnectorInterface $connector,
?string $canonicalDomain = null,
?CryptokeyResource $cryptoKeyResource = null
) {
Expand Down
28 changes: 14 additions & 14 deletions src/Powerdns.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

class Powerdns
class Powerdns implements PowerdnsInterface
{
/**
* The version of this package. This is being used for the user-agent header.
Expand Down Expand Up @@ -48,25 +48,25 @@ class Powerdns
private $server = 'localhost';

/**
* @var Connector The PowerDNS Connector to make calls.
* @var ConnectorInterface The PowerDNS Connector to make calls.
*/
private $connector;

/**
* PowerDNS Client constructor.
*
* @param null|string $host (optional) The PowerDNS host. Must include protocol (http, https, etc.).
* @param null|string $apiKey (optional) The PowerDNS API key.
* @param int|null $port (optional) The PowerDNS API Port.
* @param null|string $server (optional) The PowerDNS server to use.
* @param Connector|null $connector (optional) The Connector to make calls.
* @param null|string $host (optional) The PowerDNS host. Must include protocol (http, https, etc.).
* @param null|string $apiKey (optional) The PowerDNS API key.
* @param int|null $port (optional) The PowerDNS API Port.
* @param null|string $server (optional) The PowerDNS server to use.
* @param ConnectorInterface|null $connector (optional) The Connector to make calls.
*/
public function __construct(
?string $host = null,
?string $apiKey = null,
?int $port = null,
?string $server = null,
?Connector $connector = null
?ConnectorInterface $connector = null
) {
if (self::$_instance === null) {
self::$_instance = $this;
Expand Down Expand Up @@ -98,9 +98,9 @@ public function __construct(
* @param int $port The PowerDNS API Port.
* @param string $server The PowerDNS server to use.
*
* @return Powerdns The created PowerDNS client.
* @return PowerdnsInterface The created PowerDNS client.
*/
public function connect(string $host, int $port = 8001, string $server = 'localhost'): self
public function connect(string $host, int $port = 8001, string $server = 'localhost'): PowerdnsInterface
{
$this->host = $host;
$this->port = $port;
Expand All @@ -114,9 +114,9 @@ public function connect(string $host, int $port = 8001, string $server = 'localh
*
* @param string $key The key to use.
*
* @return $this The current client.
* @return PowerdnsInterface The current client.
*/
public function useKey(string $key): self
public function useKey(string $key): PowerdnsInterface
{
$this->apiKey = $key;

Expand Down Expand Up @@ -313,9 +313,9 @@ public function log(): LoggerInterface
*
* @param LoggerInterface $log The log instance to use.
*
* @return self The current client instance.
* @return PowerdnsInterface The current client instance.
*/
public function setLogger(LoggerInterface $log): self
public function setLogger(LoggerInterface $log): PowerdnsInterface
{
$this->logger = $log;

Expand Down
146 changes: 146 additions & 0 deletions src/PowerdnsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

declare(strict_types=1);

namespace Exonet\Powerdns;

use Exonet\Powerdns\Resources\SearchResultSet;
use Exonet\Powerdns\Resources\Zone as ZoneResource;
use Psr\Log\LoggerInterface;

interface PowerdnsInterface
{
/**
* Configure a new connection to a PowerDNS server.
*
* @param string $host The PowerDNS host. Must include protocol (http, https, etc.).
* @param int $port The PowerDNS API Port.
* @param string $server The PowerDNS server to use.
*
* @return Powerdns The created PowerDNS client.
*/
public function connect(string $host, int $port = 8001, string $server = 'localhost'): self;

/**
* Set the authorization key to use for each request.
*
* @param string $key The key to use.
*
* @return PowerdnsInterface The current client.
*/
public function useKey(string $key): self;

/**
* Create a new zone.
*
* @param string $canonicalDomain The canonical domain name.
* @param array $nameservers The name servers.
* @param bool $useDnssec (Default: false) When true use DNSSEC for this zone.
*
* @return Zone The created Zone.
*/
public function createZone(string $canonicalDomain, array $nameservers, bool $useDnssec = false): Zone;

/**
* Create a new zone based on a zone resource.
*
* @param ZoneResource $zoneResource The zone resource.
*
* @return Zone The created zone.
*/
public function createZoneFromResource(ZoneResource $zoneResource): Zone;

/**
* Get a zone instance to work with.
*
* @param string $canonicalDomain The canonical domain name of the zone.
*
* @return Zone The zone.
*/
public function zone(string $canonicalDomain): Zone;

/**
* Remove a zone.
*
* @param string $canonicalDomain The canonical domain name of the zone to remove.
*
* @return bool True that the zone was removed.
*/
public function deleteZone(string $canonicalDomain): bool;

/**
* Retrieve all zones.
*
* @param bool $omitDnssecAndEditedSerialFields When set to true dnssec and edited_serial are omitted
*
* @return Zone[] Array containing the zones
*
* @link https://doc.powerdns.com/authoritative/http-api/zone.html#get--servers-server_id-zones
*/
public function listZones(bool $omitDnssecAndEditedSerialFields = false): array;

/**
* Get a cryptokey instance to work with.
*
* @param string $canonicalDomain The canonical domain name of the zone.
*
* @return Cryptokey The cryptokey instance.
*/
public function cryptokeys(string $canonicalDomain): Cryptokey;

/**
* Query PowerDNS internal statistics.
* The ring statistics are disabled by default to speedup the request and reduce the response size.
*
* The $statistics and $includeRings parameters are supported in PowerDNS 4.3 and newer.
* On older PowerDNS instances these parameters are ignored.
*
* @param null|string $statistic Optional name of a specific statistic to get.
* @param bool $includeRings Include ring statistics or not.
*
* @return array An array with statistics.
*/
public function statistics($statistic = null, $includeRings = false): array;

/**
* Search for the specified string in zones, records, comments or in all three. The * character can be used in the
* query as a wildcard character and the ? character can be used as a wildcard for a single character.
*
* @param string $query The string to search for.
* @param int $size The maximum number of returned results.
* @param string $type The search type. Can be 'all', 'zone', 'record' or 'comment'.
*
* @return SearchResultSet A collection with search results.
*/
public function search(string $query, int $size = 100, string $type = 'all'): SearchResultSet;

/**
* Get the PowerDNS server version.
*
* @return string The server version.
*/
public function serverVersion(): string;

/**
* Get the logger instance.
*
* @return LoggerInterface The log instance.
*/
public function log(): LoggerInterface;

/**
* Set the logger instance to use.
*
* @param LoggerInterface $log The log instance to use.
*
* @return PowerdnsInterface The current client instance.
*/
public function setLogger(LoggerInterface $log): PowerdnsInterface;

/**
* Get the client config items.
*
* @return mixed[] Array containing the client config items.
*/
public function getConfig(): array;
}

0 comments on commit 1ea298f

Please sign in to comment.