|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Resta\Support; |
|
4
|
|
|
|
|
5
|
|
|
use Resta\Contracts\ApplicationContracts; |
|
6
|
|
|
use Resta\Foundation\ApplicationProvider; |
|
7
|
|
|
|
|
8
|
|
|
class TrackLogger extends ApplicationProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var null|array |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $output; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var null|array |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $arguments; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* TrackLogger constructor. |
|
22
|
|
|
* @param ApplicationContracts $app |
|
23
|
|
|
* @param $output |
|
24
|
|
|
* @param $arguments |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(ApplicationContracts $app,$output,$arguments) |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct($app); |
|
29
|
|
|
|
|
30
|
|
|
if(!$this->app->runningInConsole()){ |
|
31
|
|
|
exception()->runtime('Console application is missing'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$this->output = $output; |
|
35
|
|
|
$this->arguments = $arguments; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* get arguments property variable |
|
40
|
|
|
* |
|
41
|
|
|
* @return array|null |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getArguments() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->arguments; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* get output property variable |
|
50
|
|
|
* |
|
51
|
|
|
* @return array|null |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getOutput() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->output; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param $callback |
|
60
|
|
|
*/ |
|
61
|
|
|
public function handle($callback) |
|
62
|
|
|
{ |
|
63
|
|
|
if(isset($this->arguments['filter'])){ |
|
64
|
|
|
|
|
65
|
|
|
$filterResult = []; |
|
66
|
|
|
$filter = lcfirst($this->arguments['filter']); |
|
67
|
|
|
|
|
68
|
|
|
foreach (explode('+',$filter) as $item){ |
|
69
|
|
|
$itemList = explode('=',$item); |
|
70
|
|
|
if(isset($this->output[$itemList[0]]) && $this->output[$itemList[0]]==$itemList[1]){ |
|
71
|
|
|
$filterResult[] = true; |
|
72
|
|
|
} |
|
73
|
|
|
else{ |
|
74
|
|
|
$filterResult[] = false; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if(!isset($filterResult) || (isset($filterResult) && is_array($filterResult) && !in_array(false,$filterResult))){ |
|
80
|
|
|
|
|
81
|
|
|
if($this->output['meta']['success']) |
|
82
|
|
|
{ |
|
83
|
|
|
echo ''.$this->output['trackNumber'].' - SUCCESS:'; |
|
84
|
|
|
echo PHP_EOL; |
|
85
|
|
|
echo 'Request Success : true'; |
|
86
|
|
|
} |
|
87
|
|
|
else{ |
|
88
|
|
|
|
|
89
|
|
|
echo ''.$this->output['trackNumber'].' - ERROR:'; |
|
90
|
|
|
echo PHP_EOL; |
|
91
|
|
|
echo 'Error: '.$this->output['resource']['errorMessage']; |
|
92
|
|
|
echo PHP_EOL; |
|
93
|
|
|
echo 'Error File: '.$this->output['resource']['errorFile']; |
|
94
|
|
|
echo PHP_EOL; |
|
95
|
|
|
echo 'Error Line: '.$this->output['resource']['errorLine']; |
|
96
|
|
|
echo PHP_EOL; |
|
97
|
|
|
echo 'Error Type: '.$this->output['resource']['errorType']; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
echo PHP_EOL; |
|
101
|
|
|
echo 'Request Code: '.$this->output['meta']['status']; |
|
102
|
|
|
|
|
103
|
|
|
echo PHP_EOL; |
|
104
|
|
|
$requestClientIp = (isset($this->output['clientIp'])) ? $this->output['clientIp'] : null; |
|
105
|
|
|
echo 'Client Ip: '.$requestClientIp ; |
|
106
|
|
|
|
|
107
|
|
|
echo PHP_EOL; |
|
108
|
|
|
$requestEndpoint = (isset($this->output['requestUrl'])) ? $this->output['requestUrl'] : null; |
|
109
|
|
|
echo 'Endpoint: '.$requestEndpoint; |
|
110
|
|
|
|
|
111
|
|
|
echo PHP_EOL; |
|
112
|
|
|
echo 'Get Data: '.json_encode(isset($this->output['getData']) ? $this->output['getData'] : []); |
|
113
|
|
|
|
|
114
|
|
|
echo PHP_EOL; |
|
115
|
|
|
echo 'Post Data: '.json_encode(isset($this->output['postData']) ? $this->output['postData'] : []); |
|
116
|
|
|
|
|
117
|
|
|
echo PHP_EOL; |
|
118
|
|
|
$requestAuth = (isset($this->output['auth'])) ? $this->output['auth'] : null; |
|
119
|
|
|
echo 'Auth: '.$requestAuth; |
|
120
|
|
|
|
|
121
|
|
|
echo PHP_EOL; |
|
122
|
|
|
echo 'Time: '.date('Y-m-d H:i:s'); |
|
123
|
|
|
|
|
124
|
|
|
echo PHP_EOL; |
|
125
|
|
|
$requestClientKey = (isset($this->output['clientApiTokenKey'])) ? $this->output['clientApiTokenKey'] : null; |
|
126
|
|
|
echo 'Client Key: '.$requestClientKey; |
|
127
|
|
|
|
|
128
|
|
|
echo PHP_EOL; |
|
129
|
|
|
if(is_callable($callback)){ |
|
130
|
|
|
echo $callback($this); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
echo PHP_EOL; |
|
134
|
|
|
echo PHP_EOL; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
} |