From 8a17347e96fe0c380e2350a6310c796be2dad071 Mon Sep 17 00:00:00 2001 From: Rob Ballou Date: Tue, 2 Feb 2016 08:59:26 -0700 Subject: [PATCH 1/6] Started on allowing Zombie.js options --- src/NodeJS/Server.php | 57 +++++++++++++++++++++++++++++- src/NodeJS/Server/ZombieServer.php | 2 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 94c9fb7..c8dda3f 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -60,6 +60,11 @@ abstract class Server */ protected $connection; + /** + * @var array + */ + protected $options = array(); + /** * Constructor * @@ -76,7 +81,8 @@ public function __construct( $nodeBin = null, $serverPath = null, $threshold = 2000000, - $nodeModulesPath = '' + $nodeModulesPath = '', + $options = array() ) { if (null === $nodeBin) { $nodeBin = 'node'; @@ -93,6 +99,8 @@ public function __construct( $this->serverPath = $serverPath; $this->threshold = intval($threshold); + + $this->setOptions($options); } /** @@ -253,6 +261,52 @@ public function getConnection() return $this->connection; } + /** + * Return the options. + * + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * Set options array. + */ + public function setOptions($options) + { + // pass these to the setOption() method which will validate. + foreach ($options as $key => $value) { + $this->setOption($key, $value); + } + } + + /** + * Set a single option. + */ + public function setOption($option, $value) + { + $valid_options = array( + 'features', + 'headers', + 'waitDuration', + 'proxy', + 'referrer', + 'silent', + 'site', + 'strictSSL', + 'userAgent', + 'language', + 'runScripts', + 'localAddress', + ); + + if (in_array($option, $valid_options)) { + $this->options[$option] = $value; + } + } + /** * Starts the server process * @@ -423,6 +477,7 @@ protected function createTemporaryServer() '%host%' => $this->host, '%port%' => $this->port, '%modules_path%' => $this->nodeModulesPath, + '%options%' => json_encode($this->options), )); $serverPath = tempnam(sys_get_temp_dir(), 'mink_nodejs_server'); diff --git a/src/NodeJS/Server/ZombieServer.php b/src/NodeJS/Server/ZombieServer.php index becc0ba..6e70bcd 100644 --- a/src/NodeJS/Server/ZombieServer.php +++ b/src/NodeJS/Server/ZombieServer.php @@ -173,7 +173,7 @@ protected function getServerScript() stream.on('end', function () { if (browser == null) { - browser = new zombie(); + browser = new zombie(%options%); // Clean up old pointers pointers = []; From 860aacaef7499050947b897c5a1fbf847b0eda54 Mon Sep 17 00:00:00 2001 From: Rob Ballou Date: Fri, 4 Mar 2016 08:41:54 -0700 Subject: [PATCH 2/6] Removed option validation, moved options methods, added getOption() which was missing --- src/NodeJS/Server.php | 96 ++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index c8dda3f..d0dafce 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -201,6 +201,56 @@ public function getNodeModulesPath() return $this->nodeModulesPath; } + /** + * Get a single option. + * + * @param string $option The option name to retrieve. + * @param mixed $default_value The value to return if the option is not set. + * + * @return mixed The option value or default value if it is not set. + */ + public function getOption($option, $default_value = NULL) + { + if (!isset($this->options[$option])) { + return $default_value; + } + + return $this->options[$option]; + } + + /** + * Set a single option. + * + * @param string $option The option name + * @param mixed $value The option value + */ + public function setOption($option, $value) + { + $this->options[$option] = $value; + } + + /** + * Return the all options. + * + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * Set options array. + * + * @param array $options Array of options to set. + */ + public function setOptions($options) + { + foreach ($options as $key => $value) { + $this->setOption($key, $value); + } + } + /** * Setter server script path * @@ -261,52 +311,6 @@ public function getConnection() return $this->connection; } - /** - * Return the options. - * - * @return array - */ - public function getOptions() - { - return $this->options; - } - - /** - * Set options array. - */ - public function setOptions($options) - { - // pass these to the setOption() method which will validate. - foreach ($options as $key => $value) { - $this->setOption($key, $value); - } - } - - /** - * Set a single option. - */ - public function setOption($option, $value) - { - $valid_options = array( - 'features', - 'headers', - 'waitDuration', - 'proxy', - 'referrer', - 'silent', - 'site', - 'strictSSL', - 'userAgent', - 'language', - 'runScripts', - 'localAddress', - ); - - if (in_array($option, $valid_options)) { - $this->options[$option] = $value; - } - } - /** * Starts the server process * From ab2a51e1517028639374f9e3b51c75337204dc44 Mon Sep 17 00:00:00 2001 From: Rob Ballou Date: Fri, 4 Mar 2016 08:45:03 -0700 Subject: [PATCH 3/6] Added createTemporaryServer() call in setOptions() --- src/NodeJS/Server.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index d0dafce..463b372 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -249,6 +249,7 @@ public function setOptions($options) foreach ($options as $key => $value) { $this->setOption($key, $value); } + $this->serverPath = $this->createTemporaryServer(); } /** From 80999d84f259e561bdf3f2a2338ed05c7c2df527 Mon Sep 17 00:00:00 2001 From: Rob Ballou Date: Fri, 4 Mar 2016 09:00:26 -0700 Subject: [PATCH 4/6] Removed setOption(), updated setOptions() --- src/NodeJS/Server.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 463b372..19bf603 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -218,17 +218,6 @@ public function getOption($option, $default_value = NULL) return $this->options[$option]; } - /** - * Set a single option. - * - * @param string $option The option name - * @param mixed $value The option value - */ - public function setOption($option, $value) - { - $this->options[$option] = $value; - } - /** * Return the all options. * @@ -247,7 +236,7 @@ public function getOptions() public function setOptions($options) { foreach ($options as $key => $value) { - $this->setOption($key, $value); + $this->options[$key] = $value; } $this->serverPath = $this->createTemporaryServer(); } From 95fa786e7841dcb589a03cece657532786b45547 Mon Sep 17 00:00:00 2001 From: Rob Ballou Date: Fri, 4 Mar 2016 09:03:30 -0700 Subject: [PATCH 5/6] Removed getOption() --- src/NodeJS/Server.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 19bf603..4dd56bd 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -201,23 +201,6 @@ public function getNodeModulesPath() return $this->nodeModulesPath; } - /** - * Get a single option. - * - * @param string $option The option name to retrieve. - * @param mixed $default_value The value to return if the option is not set. - * - * @return mixed The option value or default value if it is not set. - */ - public function getOption($option, $default_value = NULL) - { - if (!isset($this->options[$option])) { - return $default_value; - } - - return $this->options[$option]; - } - /** * Return the all options. * From 847ecea0cfb562c2bed3e15cdad12af06a7e9ef4 Mon Sep 17 00:00:00 2001 From: Rob Ballou Date: Fri, 4 Mar 2016 09:04:32 -0700 Subject: [PATCH 6/6] Updated setOptions() code styles --- src/NodeJS/Server.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 4dd56bd..32414c8 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -221,6 +221,7 @@ public function setOptions($options) foreach ($options as $key => $value) { $this->options[$key] = $value; } + $this->serverPath = $this->createTemporaryServer(); }