1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace whm\Smoke\Extensions\SmokeResponseRetriever\Retriever\Koalamon; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use phm\HttpWebdriverClient\Http\HttpClient; |
7
|
|
|
use Psr\Http\Message\UriInterface; |
8
|
|
|
use whm\Crawler\Http\RequestFactory; |
9
|
|
|
use whm\Html\Uri; |
10
|
|
|
use whm\Smoke\Extensions\SmokeResponseRetriever\Retriever\Retriever as SmokeRetriever; |
11
|
|
|
use whm\Smoke\Scanner\SessionContainer; |
12
|
|
|
|
13
|
|
|
class Retriever implements SmokeRetriever |
14
|
|
|
{ |
15
|
|
|
private $apiKey; |
16
|
|
|
private $systems; |
17
|
|
|
private $project; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var HttpAdapterInterface |
21
|
|
|
*/ |
22
|
|
|
private $client; |
23
|
|
|
|
24
|
|
|
const ENDPOINT_SYSTEMS = 'http://www.koalamon.com/rest/#project#/systems/?api_key=#api_key#'; |
25
|
|
|
|
26
|
|
|
public function init($apiKey, $project) |
27
|
|
|
{ |
28
|
|
|
$this->apiKey = $apiKey; |
29
|
|
|
$this->project = $project; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function setHttpClient(Client $httpClient) |
33
|
|
|
{ |
34
|
|
|
$this->client = $httpClient; |
|
|
|
|
35
|
|
|
$this->systems = $this->getSystems($httpClient); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getSystems(HttpClient $httpClient) |
39
|
|
|
{ |
40
|
|
|
$url = $this->prepareUrl(self::ENDPOINT_SYSTEMS); |
41
|
|
|
|
42
|
|
|
$systems = $httpClient->get(new Uri($url)); |
43
|
|
|
|
44
|
|
|
return json_decode($systems->getBody(), true); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function prepareUrl($url) |
48
|
|
|
{ |
49
|
|
|
$preparedUrl = str_replace('#project#', $this->project, $url); |
50
|
|
|
$preparedUrl = str_replace('#api_key#', $this->apiKey, $preparedUrl); |
51
|
|
|
|
52
|
|
|
return $preparedUrl; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function next() |
56
|
|
|
{ |
57
|
|
|
if (empty($this->systems)) { |
58
|
|
|
return false; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$system = array_pop($this->systems); |
62
|
|
|
|
63
|
|
|
$request = RequestFactory::getRequest(new Uri($system['url']), 'GET', 'php://memory', ['Accept-Encoding' => 'gzip', 'Connection' => 'keep-alive']); |
64
|
|
|
$responses = $this->client->sendRequests(array($request)); |
65
|
|
|
|
66
|
|
|
return $responses[0]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getComingFrom(UriInterface $uri) |
70
|
|
|
{ |
71
|
|
|
return new Uri('http://www.koalamon.com'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getOriginUri(UriInterface $uri) |
75
|
|
|
{ |
76
|
|
|
return $uri; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function setSessionContainer(SessionContainer $sessionContainer) |
80
|
|
|
{ |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getOccuredExceptions() |
84
|
|
|
{ |
85
|
|
|
return []; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..