Skip to content

Commit e43e6cc

Browse files
authored
Merge pull request #32 from packbackbooks/add-set-debugging-mode
PODB-266 Add the ability to set debugging mode
2 parents 68e361b + b611ec8 commit e43e6cc

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/LtiServiceConnector.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ class LtiServiceConnector implements ILtiServiceConnector
1919

2020
private $cache;
2121
private $client;
22+
private $debuggingMode = false;
2223

2324
public function __construct(ICache $cache, Client $client)
2425
{
2526
$this->cache = $cache;
2627
$this->client = $client;
2728
}
2829

30+
public function setDebuggingMode($enable)
31+
{
32+
$this->debuggingMode = $enable;
33+
}
34+
2935
public function getAccessToken(ILtiRegistration $registration, array $scopes)
3036
{
3137
// Get a unique cache key for the access token
@@ -108,14 +114,16 @@ public function makeServiceRequest(
108114
});
109115
$respBody = $response->getBody();
110116

111-
error_log('Syncing grade for this lti_user_id: '.
112-
json_decode($request->getPayload()['body'])->userId.' '.print_r([
113-
'request_method' => $request->getMethod(),
114-
'request_url' => $request->getUrl(),
115-
'request_body' => $request->getPayload()['body'],
116-
'response_headers' => $respHeaders,
117-
'response_body' => (string) $respBody,
118-
], true));
117+
if ($this->debuggingMode) {
118+
error_log('Syncing grade for this lti_user_id: '.
119+
json_decode($request->getPayload()['body'])->userId.' '.print_r([
120+
'request_method' => $request->getMethod(),
121+
'request_url' => $request->getUrl(),
122+
'request_body' => $request->getPayload()['body'],
123+
'response_headers' => $respHeaders,
124+
'response_body' => (string) $respBody,
125+
], true));
126+
}
119127

120128
return [
121129
'headers' => $respHeaders,

tests/LtiServiceConnectorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ public function testItGetsAll()
287287

288288
// Makes two requests, but gets the method and URL once before making the request
289289
$this->request->shouldReceive('getMethod')
290-
->times(5)->andReturn($method);
290+
->times(3)->andReturn($method);
291291
$this->request->shouldReceive('getUrl')
292-
->times(5)->andReturn($this->url);
292+
->times(3)->andReturn($this->url);
293293
$this->request->shouldReceive('getPayload')
294-
->times(6)->andReturn($this->requestPayload);
294+
->times(2)->andReturn($this->requestPayload);
295295
// Doesn't find a matching link in on the second header, so only updates the URL once
296296
$this->request->shouldReceive('setUrl')
297297
->once()->andReturn($this->request);

0 commit comments

Comments
 (0)