| @@ 11-53 (lines=43) @@ | ||
| 8 | use phm\HttpWebdriverClient\Http\Client\HttpClient; |
|
| 9 | use Psr\Http\Message\RequestInterface; |
|
| 10 | ||
| 11 | class ChromeClient implements HttpClient |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var phmChromeClient |
|
| 15 | */ |
|
| 16 | private $chromeClient; |
|
| 17 | ||
| 18 | public function init($host = 'localhost', $port = 4444, $nocache = false) |
|
| 19 | { |
|
| 20 | if ($nocache) { |
|
| 21 | $this->chromeClient = new phmChromeClient($host, $port); |
|
| 22 | } else { |
|
| 23 | $chromeClient = new phmChromeClient($host, $port); |
|
| 24 | $cachedClient = new FileCacheDecorator($chromeClient); |
|
| 25 | $this->chromeClient = new LoggerDecorator($cachedClient); |
|
| 26 | } |
|
| 27 | } |
|
| 28 | ||
| 29 | public function sendRequest(RequestInterface $request) |
|
| 30 | { |
|
| 31 | return $this->chromeClient->sendRequest($request); |
|
| 32 | } |
|
| 33 | ||
| 34 | public function sendRequests(array $requests) |
|
| 35 | { |
|
| 36 | return $this->chromeClient->sendRequests($requests); |
|
| 37 | } |
|
| 38 | ||
| 39 | public function getClientType() |
|
| 40 | { |
|
| 41 | return $this->chromeClient->getClientType(); |
|
| 42 | } |
|
| 43 | ||
| 44 | public function close() |
|
| 45 | { |
|
| 46 | $this->chromeClient->close(); |
|
| 47 | } |
|
| 48 | ||
| 49 | public function setOption($key, $value) |
|
| 50 | { |
|
| 51 | $this->chromeClient->setOption($key, $value); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 11-53 (lines=43) @@ | ||
| 8 | use phm\HttpWebdriverClient\Http\Client\HttpClient; |
|
| 9 | use Psr\Http\Message\RequestInterface; |
|
| 10 | ||
| 11 | class HeadlessChromeClient implements HttpClient |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var HeadlessChrome |
|
| 15 | */ |
|
| 16 | private $chromeClient; |
|
| 17 | ||
| 18 | public function init($nocache = false, $clientTimeout = 31000) |
|
| 19 | { |
|
| 20 | if ($nocache) { |
|
| 21 | $this->chromeClient = new HeadlessChrome($clientTimeout); |
|
| 22 | } else { |
|
| 23 | $chromeClient = new HeadlessChrome($clientTimeout); |
|
| 24 | $cachedClient = new FileCacheDecorator($chromeClient); |
|
| 25 | $this->chromeClient = new LoggerDecorator($cachedClient); |
|
| 26 | } |
|
| 27 | } |
|
| 28 | ||
| 29 | public function sendRequest(RequestInterface $request) |
|
| 30 | { |
|
| 31 | return $this->chromeClient->sendRequest($request); |
|
| 32 | } |
|
| 33 | ||
| 34 | public function sendRequests(array $requests) |
|
| 35 | { |
|
| 36 | return $this->chromeClient->sendRequests($requests); |
|
| 37 | } |
|
| 38 | ||
| 39 | public function getClientType() |
|
| 40 | { |
|
| 41 | return $this->chromeClient->getClientType(); |
|
| 42 | } |
|
| 43 | ||
| 44 | public function close() |
|
| 45 | { |
|
| 46 | $this->chromeClient->close(); |
|
| 47 | } |
|
| 48 | ||
| 49 | public function setOption($key, $value) |
|
| 50 | { |
|
| 51 | $this->chromeClient->setOption($key, $value); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||