/** * Log data. You may pass in any number of arguments. */ public static function log() { if (Log::$enabled) { $data = array(); $args = func_get_args(); foreach ($args as $arg) { $message = ""; Myna::var_dump_to_string($arg, $message); array_push($data, $message); } //$stderr = fopen('php://stderr', 'w'); //fwrite($stderr, implode(' ', $data)); //fclose($stderr); error_log(implode(' ', $data)); } }
public static function get_or_error($array, $key, $location = 'Undefined') { return isset($array[$key]) ? $array[$key] : Myna::error($location, "no {$key} in array", $array); }
public static function error($origin, $reason, $data) { $message = "{$origin}: {$reason}"; Myna::var_dump_to_string($data, $message); throw new \Exception($message); }
/** * Parse a response from the server * * @param String data * @return Array or true */ function parse_response($data) { if ($data === false) { // There was a network error $err = error_get_last(); Myna::error("Myna\\Api.parse_response", "There was a network error", $err); } $json = json_decode($data, true); if (is_null($json)) { Myna::error("Myna\\Api.parse_response", "Response from server is not JSON.", $data); } switch ($json['typename']) { case 'problem': return Myna::error("Myna\\Api.parse_response", "Server responded with error", $json['messages']); case 'experiment': return \Myna\Data\Experiment::fromArray($json); case 'deployment': return \Myna\Data\Deployment::fromArray($json); case 'ok': return true; default: return Myna::error("Myna\\Api.parse_response", "Unexpected JSON response", $json); } }