Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 5 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
51 changes: 50 additions & 1 deletion src/NodeJS/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ abstract class Server
*/
protected $connection;

/**
* @var array
*/
protected $options = array();

/**
* Constructor
*
Expand All @@ -76,7 +81,8 @@ public function __construct(
$nodeBin = null,
$serverPath = null,
$threshold = 2000000,
$nodeModulesPath = ''
$nodeModulesPath = '',
$options = array()
) {
if (null === $nodeBin) {
$nodeBin = 'node';
Expand All @@ -93,6 +99,8 @@ public function __construct(

$this->serverPath = $serverPath;
$this->threshold = intval($threshold);

$this->setOptions($options);
}

/**
Expand Down Expand Up @@ -193,6 +201,46 @@ 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this method.

I don't see any potential use of this method, because the only consumer of this options is Zombie itself. Nobody wants to introspect what options current server has.

{
if (!isset($this->options[$option])) {
return $default_value;
}

return $this->options[$option];
}

/**
* 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->options[$key] = $value;
}
$this->serverPath = $this->createTemporaryServer();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add empty line above. If you have any automated code style checks in place for PSR2 standard then this should have been reported as error by them. Also the Scrutinizer CI should have picked that as well.

}

/**
* Setter server script path
*
Expand Down Expand Up @@ -423,6 +471,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');
Expand Down
2 changes: 1 addition & 1 deletion src/NodeJS/Server/ZombieServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down