1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RedirectionIO\Client\Sdk\Command; |
4
|
|
|
|
5
|
|
|
use RedirectionIO\Client\Sdk\Client; |
6
|
|
|
use RedirectionIO\Client\Sdk\HttpMessage\Request; |
7
|
|
|
use RedirectionIO\Client\Sdk\HttpMessage\Response; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Log a request and a response to be used in analysis on redirection io manager. |
11
|
|
|
*/ |
12
|
|
|
class LogCommand extends Command |
13
|
|
|
{ |
14
|
|
|
private $request; |
15
|
|
|
private $response; |
16
|
|
|
|
17
|
|
|
public function __construct(Request $request, Response $response) |
18
|
|
|
{ |
19
|
|
|
$this->request = $request; |
20
|
|
|
$this->response = $response; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getName() |
24
|
|
|
{ |
25
|
|
|
return 'LOG'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getRequest() |
29
|
|
|
{ |
30
|
|
|
$data = [ |
31
|
|
|
'project_id' => $this->projectKey, |
32
|
|
|
'status_code' => $this->response->getStatusCode(), |
33
|
|
|
'host' => $this->request->getHost(), |
34
|
|
|
'request_uri' => $this->request->getPath(), |
35
|
|
|
'method' => $this->request->getMethod(), |
36
|
|
|
'user_agent' => $this->request->getUserAgent(), |
37
|
|
|
'referer' => $this->request->getReferer(), |
38
|
|
|
'scheme' => $this->request->getScheme(), |
39
|
|
|
'proxy' => 'php-sdk-redirectionio:'.Client::VERSION, |
40
|
|
|
'use_json' => true, |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
if ($this->response->getLocation()) { |
44
|
|
|
$data['target'] = $this->response->getLocation(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if ($this->response->getRuleId()) { |
48
|
|
|
$data['rule_id'] = $this->response->getRuleId(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return json_encode($data); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function hasResponse() |
55
|
|
|
{ |
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function parseResponse($response) |
60
|
|
|
{ |
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|