From f5a4e22fb8770e4bbac40c8f651cc3d3b6a34f8d Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Mon, 18 Oct 2021 16:30:22 +0200 Subject: [PATCH] Http::unserialize - centralise debug logging of response --- src/Wikipedia/Api.php | 15 +-------------- src/Wikipedia/Http.php | 4 ++++ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Wikipedia/Api.php b/src/Wikipedia/Api.php index 7c459cd..a3fe301 100644 --- a/src/Wikipedia/Api.php +++ b/src/Wikipedia/Api.php @@ -476,10 +476,6 @@ public function edit( } $x = $this->http->post($this->apiurl, $params); - if ($this->logger !== null) { - $this->logger->addDebug($x); - } - $x = $this->http->unserialize($x); if ($x['edit']['result'] == 'Success') { @@ -523,7 +519,7 @@ public function gettoken($title) public function getLoginToken() { $x = $this->http->get($this->apiurl . '?rawcontinue=1&format=php' . - '?action=query&meta=tokens&type=login'); + '&meta=tokens&type=login'); $x = $this->http->unserialize($x); return $x['query']['tokens']['logintoken']; @@ -547,10 +543,6 @@ public function login($user, $pass) 'lgtoken' => $this->getLoginToken()) ); - if ($this->logger !== null) { - $this->logger->addDebug($x); - } - $x = $this->http->unserialize($x); return $x['login']['result'] == 'Success'; @@ -584,11 +576,6 @@ public function move($old, $new, $reason, $checkrun = true) ); $x = $this->http->post($this->apiurl, $params); - - if ($this->logger !== null) { - $this->logger->addDebug($x); - } - $this->http->unserialize($x); // this emits warnings if needed } diff --git a/src/Wikipedia/Http.php b/src/Wikipedia/Http.php index 0409dac..286a6d5 100644 --- a/src/Wikipedia/Http.php +++ b/src/Wikipedia/Http.php @@ -136,6 +136,10 @@ public function get($url) **/ public function unserialize($response) { + if ($this->logger !== null) { + $this->logger->addDebug('Decoding response: ' . $response); + } + $response = unserialize($response); if ($this->logger !== null) {