X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=ext%2Faction_helpers%2Fphp%2Fmcollective_action.php;fp=ext%2Faction_helpers%2Fphp%2Fmcollective_action.php;h=64876688cfafc92c2417ecb64e7a74d459fa1bd7;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/ext/action_helpers/php/mcollective_action.php b/ext/action_helpers/php/mcollective_action.php new file mode 100644 index 0000000..6487668 --- /dev/null +++ b/ext/action_helpers/php/mcollective_action.php @@ -0,0 +1,65 @@ +infile = $_ENV["MCOLLECTIVE_REQUEST_FILE"]; + $this->outfile = $_ENV["MCOLLECTIVE_REPLY_FILE"]; + + $this->readJSON(); + } + + function __destruct() { + $this->save(); + } + + function readJSON() { + $this->request = json_decode(file_get_contents($this->infile), true); + unset($this->request["data"]["process_results"]); + } + + function save() { + file_put_contents($this->outfile, json_encode($this->request["data"])); + } + + // prints a line to STDERR that will log at error level in the + // mcollectived log file + function error($msg) { + fwrite(STDERR, "$msg\n"); + } + + // prints a line to STDOUT that will log at info level in the + // mcollectived log file + function info($msg) { + fwrite(STDOUT, "$msg\n"); + } + + // logs an error message and exits with RPCAborted + function fail($msg) { + $this->error($msg); + exit(1); + } + + function __get($property) { + if (isSet($this->request[$property])) { + return $this->request[$property]; + } else { + throw new Exception("No $property in request"); + } + } + + function __set($property, $value) { + $this->request["data"][$property] = $value; + } +} +?>