Skip to content

Commit

Permalink
version 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ddmitov committed Jun 9, 2017
1 parent 31dd244 commit b6ae81d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ elephant-harness is a small [Node.js](http://nodejs.org/) - [Electron](http://el
```javascript
const elephantHarness = require('elephant-harness');

var phpScriptObject = new Object();
var phpScriptObject = {};
phpScriptObject.interpreter = 'php';
phpScriptObject.scriptFullPath = '/test/test.php';

Expand All @@ -43,7 +43,7 @@ elephant-harness npm package test will fail if no ``php`` binary is available on
```javascript
const elephantHarness = require('elephant-harness');

var phpScriptObject = new Object();
var phpScriptObject = {};

// mandatory object property
phpScriptObject.interpreter = 'php-cgi';
Expand Down Expand Up @@ -103,11 +103,12 @@ elephantHarness.startScript(phpScriptObject);
The ``php-cgi`` binary should be used together with the ``-q`` switch in [Electron](http://electron.atom.io/) and [NW.js](http://nwjs.io/) to enable quiet mode and suppress unnecessary HTTP header output.

* **method:**
Only ``GET`` or ``POST`` are allowed.
This object property has no effect if ``formData`` is not set.
Only ``GET`` or ``POST`` are recognized.
This object property requires ``formData`` to be set.

* **formData:**
This object property has no effect if ``method`` is not set.
This object property requires ``method`` to be set.

elephant-harness does not depend on [jQuery](https://jquery.com/), but it can be used for easy acquisition of form data:

```javascript
Expand Down
18 changes: 10 additions & 8 deletions elephant-harness.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// elephant-harness version 0.5.2
// elephant-harness version 0.6.0
// Node.js - Electron - NW.js controller for PHP scripts
// elephant-harness is licensed under the terms of the MIT license.
// Copyright (c) 2016 - 2017 Dimitar D. Mitov
Expand All @@ -23,7 +23,7 @@ const spawn = require('child_process').spawn;
const filesystemObject = require('fs');

function checkScriptSettings(scriptObject) {
// PHP interpreter, full path of the PHP script and
// PHP interpreter, PHP script full path and
// name of the STDOUT handling function
// are mandatory function parameter object properties.
if (scriptObject.interpreter === undefined ||
Expand All @@ -34,30 +34,32 @@ function checkScriptSettings(scriptObject) {
return false;
}

// Check if the supplied script exists:
// Check if script exists:
filesystemObject.access(scriptObject.scriptFullPath, function(error) {
if (error && error.code === 'ENOENT') {
console.log(scriptObject.scriptFullPath + ' was not found.');
return false;
}
});

// If request method is set, form data must also be set and vice versa:
if (scriptObject.method !== undefined &&
scriptObject.formData === undefined) {
// If request method is set, form data must also be set:
if (scriptObject.formData === undefined &&
scriptObject.method !== undefined) {
console.log('Request method is ' + scriptObject.method + ', ' +
'but form data is not supplied.');
return false;
}

if (scriptObject.method === undefined &&
scriptObject.formData !== undefined) {
// If form data is set, request method must also be set:
if (scriptObject.formData !== undefined &&
scriptObject.method === undefined) {
console.log('Form data is supplied, but request method is not set.');
return false;
}
}

module.exports.startScript = function(scriptObject) {
// Check script settings:
var validScriptSettings = checkScriptSettings(scriptObject);
if (validScriptSettings === false) {
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elephant-harness",
"version": "0.5.2",
"version": "0.6.0",
"description": "Node.js - Electron - NW.js controller for PHP scripts",
"main": "elephant-harness.js",
"directories": {
Expand Down

0 comments on commit b6ae81d

Please sign in to comment.