Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "phpcasperjs/phpcasperjs",
"name": "mihail-shumilov/phpcasperjs",
"description": "Simple PHP wrapper for CasperJS",
"homepage": "https://github.com/alwex/php-casperjs",
"homepage": "https://github.com/mihailShumilov/php-casperjs",
"keywords": ["phpunit", "test", "browser"],
"type": "library",
"license": "MIT",
Expand Down
43 changes: 42 additions & 1 deletion src/Casper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Casper
private $statusText = '';
private $cookies = [];

private $proxy = [
'host' => false,
'port' => false,
'type' => 'manual',
'user' => false,
'pass' => false
];

private $proxyIsSet = false;

public function __construct($path2casper = null, $tempDir = null)
{
if ($path2casper) {
Expand Down Expand Up @@ -104,6 +114,24 @@ public function setUserAgent($userAgent)
$this->userAgent = $userAgent;
}

/**
* Add proxy usage
*
* @param $host
* @param $port
* @param string $type
* @param string $user
* @param string $pass
*/
public function setProxy($host, $port, $type = 'manual', $user = '', $pass = '') {
$this->proxyIsSet = true;
$this->proxy['host'] = $host;
$this->proxy['port'] = $port;
$this->proxy['type'] = $type;
$this->proxy['user'] = $user;
$this->proxy['pass'] = $pass;
}

/**
* enable debug logging into syslog
*
Expand Down Expand Up @@ -205,10 +233,23 @@ public function start($url)
});

casper.userAgent('$this->userAgent');

FRAGMENT;

if($this->proxyIsSet){
$fragment .= <<<FRAGMENT
phantom.setProxy('{$this->proxy['host']}','{$this->proxy['port']}','{$this->proxy['type']}','{$this->proxy['user']}','{$this->proxy['pass']}');
FRAGMENT;

}

$fragment .= <<<FRAGMENT

casper.start().then(function() {
this.open('$url', {
headers: {
'Accept': 'text/html'
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'AcceptEncoding':'gzip, deflate, br'
}
});
});
Expand Down