Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"name": "inwx/domrobot",
"description": "PHP Client to easily use the Domrobot API of INWX",
"license": "MIT",
"homepage": "https://www.inwx.com/en/",
"support": {
"docs": "https://www.inwx.com/en/help/apidoc",
"email": "support@inwx.de",
"source": "https://github.com/inwx/php-client"
},
"authors": [
{
"name": "INWX",
"email": "support@inwx.de"
}
],
"require": {
"php": ">=7.2",
"ext-curl": "*"
},
"autoload": {
"psr-4": {
"INWX\\": "src/"
}
},
"suggest": {
"ext-xmlrpc": "Needed to use the XML-RPC API",
"ext-json": "Needed to use the JSON-RPC API"
}
}
{
"name": "inwx/domrobot",
"description": "PHP Client to easily use the Domrobot API of INWX",
"license": "MIT",
"homepage": "https://www.inwx.com/en/",
"support": {
"docs": "https://www.inwx.com/en/help/apidoc",
"email": "support@inwx.de",
"source": "https://github.com/inwx/php-client"
},
"authors": [
{
"name": "INWX",
"email": "support@inwx.de"
}
],
"require": {
"php": ">=7.2",
"ext-curl": "*",
"monolog/monolog": ">= 2.0.0"
},
"autoload": {
"psr-4": {
"INWX\\": "src/"
}
},
"suggest": {
"ext-xmlrpc": "Needed to use the XML-RPC API",
"ext-json": "Needed to use the JSON-RPC API"
}
}
25 changes: 22 additions & 3 deletions src/Domrobot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace INWX;

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use RuntimeException;

class Domrobot
class Domrobot implements LoggerAwareInterface
{
private const VERSION = '3.0';
private const LIVE_URL = 'https://api.domrobot.com/';
Expand All @@ -21,13 +25,20 @@ class Domrobot
private $url = self::OTE_URL;
private $api = self::JSONRPC;

/**
* @var LoggerInterface
*/
private $logger;

/**
* Domrobot constructor.
*
* @param string|null $cookieFile You can overwrite the standard cookieFile path by setting a full path here
*/
public function __construct(?string $cookieFile = null)
{
$this->logger = new Logger('domrobot_default_logger');
$this->logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
$this->cookieFile = $cookieFile ?? tempnam(sys_get_temp_dir(), 'INWX');
}

Expand Down Expand Up @@ -286,8 +297,8 @@ public function call(string $object, string $method, array $params = []): array
$response = curl_exec($ch);
curl_close($ch);
if ($this->debug) {
echo "Request:\n" . $request . "\n";
echo "Response:\n" . $response . "\n";
$this->logger->debug("Request:\n" . $request . "\n");
$this->logger->debug("Response:\n" . $response . "\n");
}

if ($this->isJson()) {
Expand Down Expand Up @@ -354,4 +365,12 @@ public function logout(): array

return $ret;
}

/**
* @inheritDoc
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
}