$json input json * @return Common\APObject|false object or false on error */ static function newFromJson($json, string $jsonstring) { if (gettype($json) !== "array") { error_log("newFromJson called with ".gettype($json). " => ". debug_backtrace()[1]['function'] . " json: " . print_r($json, true)); return false; } if (!array_key_exists('type', $json)) { return false; } $return = false; switch($json['type']) { case 'Article': $return = Factory::newArticle(); break; case 'Document': $return = Factory::newDocument(); break; case 'Event': $return = Factory::newEvent(); break; case 'Follow': $return = Factory::newFollow(); break; case 'Image': $return = Factory::newImage(); /*error_log("Image: ". print_r($json, true)); error_log("Image json " . $jsonstring);*/ break; case 'Note': $return = Factory::newNote(); break; case 'Question': $return = Factory::newQuestion(); break; case 'Video': // error_log("newFromJson: video " . $jsonstring); $return = Factory::newVideo(); break; default: error_log("newFromJson: unknown type: '" . $json['type'] . "' " . $jsonstring); error_log(print_r($json, true)); } if ($return !== false && $return->fromJson($json)) { return $return; } return false; } /** * create object tree from json * @param array $json input json * @return Common\Activity|false object or false on error */ static function newActivityFromJson($json) { if (!array_key_exists('type', $json)) { return false; } $return = false; switch($json['type']) { case 'Accept': $return = Factory::newAccept(); break; case 'Announce': $return = Factory::newAnnounce(); break; case 'Create': $return = Factory::newCreate(); break; case 'Delete': $return = Factory::newDelete(); break; case 'Follow': $return = Factory::newFollow(); break; case 'Undo': $return = Factory::newUndo(); break; default: error_log("newActivityFromJson " . print_r($json, true)); echo "unknown activity type: '" . $json['type'] . "'\n"; } if ($return !== false && $return->fromJson($json)) { return $return; } return false; } }