jonnnnyw/php-phantomjs — pull request #3 by Samyoul (2013-12-14 16:48:51+00:00)
Title: Added setScript() Method, and upgraded open() Method to accept unlimited params

setScript() Method:
Due to the current limitations of the php mask for PhantomJS I needed to
build in a setScript method to be able to use more advanced
functionality.

The setScript method currently overrides all Request object data.

Example of usage (Using Laravel):

/** @var $client JonnyW\PhantomJs\Client */
$client = App::make("PhantomClient");

$client->setScript("https://raw.github.com/ariya/phantomjs/master/examples/technews.js");

/** @var $request JonnyW\PhantomJs\Message\Request */
$request = $client->getMessageFactory()->createRequest('GET',
'doesnotmatter.com');
$request->addHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS
X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.2
Safari/534.34');

/** @var $response JonnyW\PhantomJs\Message\Response */
$response = $client->getMessageFactory()->createResponse();

// Send the request
$client->send($request, $response);

open() Method:
In extension of the setScript() method, I needed to be able to send
arguments directly to the command line.

The changes to the open() method will allow the user to send parameters
to the command line, to be used in conjunction with arguments the
selected script requires.

example usage below:

/** @var $client JonnyW\PhantomJs\Client */
$client = App::make("PhantomClient");

$client->setScript("https://raw.github.com/ariya/phantomjs/master/examples/direction.js");

/** @var $request JonnyW\PhantomJs\Message\Request */
$request = $client->getMessageFactory()->createRequest('GET',
'doesnotmatter.com');
$request->addHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS
X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.2
Safari/534.34');

/** @var $response JonnyW\PhantomJs\Message\Response */
$response = $client->getMessageFactory()->createResponse();

// Send the request
$client->open($request, $response, "london", "paris");

echo $response->getCommandLine();

Further, I've made adjustments to the response class to handle calls
back from the command line.