BrowserBase.php in Zircon Profile 8
File
vendor/jcalderonzumba/gastonjs/src/Browser/BrowserBase.php
View source
<?php
namespace Zumba\GastonJS\Browser;
use Zumba\GastonJS\Exception\BrowserError;
use Zumba\GastonJS\Exception\DeadClient;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\ServerException;
class BrowserBase {
protected $logger;
protected $debug;
protected $phantomJSHost;
protected $apiClient;
protected function createApiClient() {
if (class_exists('GuzzleHttp\\Psr7\\Response')) {
$this->apiClient = new Client(array(
"base_uri" => $this
->getPhantomJSHost(),
));
}
else {
$this->apiClient = new Client(array(
"base_url" => $this
->getPhantomJSHost(),
));
}
}
protected function normalizeKeys($keys) {
return $keys;
}
public function getApiClient() {
return $this->apiClient;
}
public function getPhantomJSHost() {
return $this->phantomJSHost;
}
public function getLogger() {
return $this->logger;
}
public function restart() {
}
public function command() {
try {
$args = func_get_args();
$commandName = $args[0];
array_shift($args);
$messageToSend = json_encode(array(
'name' => $commandName,
'args' => $args,
));
$commandResponse = $this
->getApiClient()
->post("/api", array(
"body" => $messageToSend,
));
$jsonResponse = json_decode($commandResponse
->getBody(), TRUE);
} catch (ServerException $e) {
$jsonResponse = json_decode($e
->getResponse()
->getBody()
->getContents(), true);
} catch (ConnectException $e) {
throw new DeadClient($e
->getMessage(), $e
->getCode(), $e);
} catch (\Exception $e) {
throw $e;
}
if (isset($jsonResponse['error'])) {
throw $this
->getErrorClass($jsonResponse);
}
return $jsonResponse['response'];
}
protected function getErrorClass($error) {
$errorClassMap = array(
'Poltergeist.JavascriptError' => "Zumba\\GastonJS\\Exception\\JavascriptError",
'Poltergeist.FrameNotFound' => "Zumba\\GastonJS\\Exception\\FrameNotFound",
'Poltergeist.InvalidSelector' => "Zumba\\GastonJS\\Exception\\InvalidSelector",
'Poltergeist.StatusFailError' => "Zumba\\GastonJS\\Exception\\StatusFailError",
'Poltergeist.NoSuchWindowError' => "Zumba\\GastonJS\\Exception\\NoSuchWindowError",
'Poltergeist.ObsoleteNode' => "Zumba\\GastonJS\\Exception\\ObsoleteNode",
);
if (isset($error['error']['name']) && isset($errorClassMap[$error["error"]["name"]])) {
return new $errorClassMap[$error["error"]["name"]]($error);
}
return new BrowserError($error);
}
}
Classes
Name |
Description |
BrowserBase |
Class BrowserBase
@package Zumba\GastonJS\Browser |