1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
5
|
|
|
* To change this template file, choose Tools | Templates |
6
|
|
|
* and open the template in the editor. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OBRSDK; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Description of DevMode |
13
|
|
|
* |
14
|
|
|
* @author Antonio |
15
|
|
|
*/ |
16
|
|
|
abstract class DebugMode { |
17
|
|
|
|
18
|
|
|
protected static $debugModeStatus = false; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
* @var \OBRSDK\IDebugModeCallback |
23
|
|
|
*/ |
24
|
|
|
protected static $debugObject; |
25
|
|
|
|
26
|
|
|
public static function setDebugObject(\OBRSDK\IDebugModeCallback $callback) { |
27
|
|
|
self::$debugModeStatus = true; |
28
|
|
|
self::$debugObject = $callback; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function debugDadosEnviado($uri, $type, $dados) { |
32
|
|
|
try { |
33
|
|
|
if (self::$debugModeStatus) { |
34
|
|
|
self::$debugObject->dadosEnviado($uri, $type, $dados); |
35
|
|
|
} |
36
|
|
|
} catch (\Exception $ex) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function debugDadosRecebido($uri, $type, $dados, $headers, $statusCode) { |
42
|
|
|
try { |
43
|
|
|
if (!self::$debugModeStatus) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$json_decode = null; |
48
|
|
|
$this->filtrarDados($dados, $json_decode); |
49
|
|
|
|
50
|
|
|
self::$debugObject->dadosRecebido($uri, $type, $json_decode, $headers == null ? [] : $headers, $statusCode); |
|
|
|
|
51
|
|
|
} catch (\Exception $ex) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function filtrarDados(&$dados, &$json_decode) { |
57
|
|
|
if (is_null($dados)) { |
58
|
|
|
$dados = '{}'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$json_decode = json_decode($dados, true); |
62
|
|
|
if ($json_decode == null) { |
63
|
|
|
$json_decode = ['json_decode_falha' => $dados]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|