Skip to content

Commit e5ffcec

Browse files
authored
Merge pull request #9 from inwx/psr3_loggeraware_interface
Let Domrobot implement PSR3 LoggerAwareInterface
2 parents 00934d9 + 79fec31 commit e5ffcec

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

composer.json

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
{
2-
"name": "inwx/domrobot",
3-
"description": "PHP Client to easily use the Domrobot API of INWX",
4-
"license": "MIT",
5-
"homepage": "https://www.inwx.com/en/",
6-
"support": {
7-
"docs": "https://www.inwx.com/en/help/apidoc",
8-
"email": "support@inwx.de",
9-
"source": "https://github.com/inwx/php-client"
10-
},
11-
"authors": [
12-
{
13-
"name": "INWX",
14-
"email": "support@inwx.de"
15-
}
16-
],
17-
"require": {
18-
"php": ">=7.2",
19-
"ext-curl": "*"
20-
},
21-
"autoload": {
22-
"psr-4": {
23-
"INWX\\": "src/"
24-
}
25-
},
26-
"suggest": {
27-
"ext-xmlrpc": "Needed to use the XML-RPC API",
28-
"ext-json": "Needed to use the JSON-RPC API"
29-
}
30-
}
1+
{
2+
"name": "inwx/domrobot",
3+
"description": "PHP Client to easily use the Domrobot API of INWX",
4+
"license": "MIT",
5+
"homepage": "https://www.inwx.com/en/",
6+
"support": {
7+
"docs": "https://www.inwx.com/en/help/apidoc",
8+
"email": "support@inwx.de",
9+
"source": "https://github.com/inwx/php-client"
10+
},
11+
"authors": [
12+
{
13+
"name": "INWX",
14+
"email": "support@inwx.de"
15+
}
16+
],
17+
"require": {
18+
"php": ">=7.2",
19+
"ext-curl": "*",
20+
"monolog/monolog": ">= 2.0.0"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"INWX\\": "src/"
25+
}
26+
},
27+
"suggest": {
28+
"ext-xmlrpc": "Needed to use the XML-RPC API",
29+
"ext-json": "Needed to use the JSON-RPC API"
30+
}
31+
}

src/Domrobot.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace INWX;
44

5+
use Monolog\Handler\StreamHandler;
6+
use Monolog\Logger;
7+
use Psr\Log\LoggerAwareInterface;
8+
use Psr\Log\LoggerInterface;
59
use RuntimeException;
610

7-
class Domrobot
11+
class Domrobot implements LoggerAwareInterface
812
{
913
private const VERSION = '3.0';
1014
private const LIVE_URL = 'https://api.domrobot.com/';
@@ -21,13 +25,20 @@ class Domrobot
2125
private $url = self::OTE_URL;
2226
private $api = self::JSONRPC;
2327

28+
/**
29+
* @var LoggerInterface
30+
*/
31+
private $logger;
32+
2433
/**
2534
* Domrobot constructor.
2635
*
2736
* @param string|null $cookieFile You can overwrite the standard cookieFile path by setting a full path here
2837
*/
2938
public function __construct(?string $cookieFile = null)
3039
{
40+
$this->logger = new Logger('domrobot_default_logger');
41+
$this->logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
3142
$this->cookieFile = $cookieFile ?? tempnam(sys_get_temp_dir(), 'INWX');
3243
}
3344

@@ -286,8 +297,8 @@ public function call(string $object, string $method, array $params = []): array
286297
$response = curl_exec($ch);
287298
curl_close($ch);
288299
if ($this->debug) {
289-
echo "Request:\n" . $request . "\n";
290-
echo "Response:\n" . $response . "\n";
300+
$this->logger->debug("Request:\n" . $request . "\n");
301+
$this->logger->debug("Response:\n" . $response . "\n");
291302
}
292303

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

355366
return $ret;
356367
}
368+
369+
/**
370+
* @inheritDoc
371+
*/
372+
public function setLogger(LoggerInterface $logger)
373+
{
374+
$this->logger = $logger;
375+
}
357376
}

0 commit comments

Comments
 (0)