-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from JarvusInnovations/develop
Release: emergence v1.0.7
- Loading branch information
Showing
3 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env node | ||
|
||
|
||
require('yargs') | ||
.command('$0 <site> <event> <context>', 'Fire event within site', yargs => { | ||
yargs | ||
.positional('site', { | ||
describe: 'Handle of site to fire event within' | ||
}) | ||
.positional('event', { | ||
describe: 'Name of event to fire' | ||
}) | ||
.positional('context', { | ||
describe: 'Context path to fire event within' | ||
}) | ||
}, argv => { | ||
var path = require('path'), | ||
documentRoot = path.resolve(__dirname, '../php-bootstrap'), | ||
PHPFPM = require('node-phpfpm'), | ||
phpClient = new PHPFPM({ | ||
sockFile: '/emergence/services/run/php-fpm/php-fpm.sock', | ||
documentRoot: documentRoot + '/' | ||
}), | ||
payload = Object.assign({}, argv); | ||
|
||
delete payload._; | ||
delete payload.help; | ||
delete payload.version; | ||
delete payload.site; | ||
delete payload.event; | ||
delete payload.context; | ||
delete payload['$0']; | ||
|
||
// execute event via PHP-FPM interface | ||
phpClient.run({ | ||
uri: 'event.php', | ||
json: { | ||
site: argv.site, | ||
event: argv.event, | ||
context: argv.context, | ||
payload: payload | ||
} | ||
}, function (err, output, phpErrors) { | ||
if (err == 99) console.error('PHPFPM server error'); | ||
console.log(output); | ||
if (phpErrors) console.error(phpErrors); | ||
}); | ||
|
||
}) | ||
.argv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
// bootstrap emergence | ||
require('bootstrap.inc.php'); | ||
|
||
|
||
// only process POST requests | ||
if ($_SERVER['REQUEST_METHOD'] != 'POST') { | ||
http_response_code(405); | ||
echo "POST only"; | ||
exit(1); | ||
} | ||
|
||
|
||
// parse and validate input | ||
$input = json_decode(file_get_contents('php://input'), true); | ||
|
||
if ( | ||
empty($input) | ||
|| empty($input['site']) | ||
|| empty($input['event']) | ||
|| empty($input['context']) | ||
) { | ||
http_response_code(400); | ||
echo "site, event, and context required"; | ||
exit(1); | ||
} | ||
|
||
|
||
// identify site | ||
$siteRoot = "/emergence/sites/{$input['site']}"; | ||
|
||
if (!is_dir($siteRoot)) { | ||
http_response_code(404); | ||
echo "site not found"; | ||
exit(1); | ||
} | ||
|
||
|
||
// initialize site | ||
Site::$debug = true; | ||
Site::initialize($siteRoot, 'localhost'); | ||
|
||
|
||
// fire event | ||
Emergence\EventBus::fireEvent($input['event'], $input['context'], !empty($input['payload']) ? $input['payload'] : array()); |