Skip to content

Instantly share code, notes, and snippets.

@arturom
Created January 29, 2016 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturom/d0f86a34914239472ccf to your computer and use it in GitHub Desktop.
Save arturom/d0f86a34914239472ccf to your computer and use it in GitHub Desktop.
<?php
$fh = STDIN;
while (!feof($fh)) {
$command = json_decode(fgets($fh));
if(!is_object($command)) {
exit;
}
$body = json_decode(fgets($fh));
if(!is_object($body)) {
throw new Exception('Invalid body');
}
if(empty($command->index->_type)) {
throw new Exception('Missing type');
}
if($command->index->_type === 'amassetversion') {
if(empty($body->am_asset_id)) {
throw new Exception('missing value for "am_asset_id"');
}
$command->index->_parent = $body->am_asset_version;
}
echo json_encode($command), PHP_EOL;
echo json_encode($body), PHP_EOL;
}
echo PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment