Ejemplo n.º 1
0
 /**
  * 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));
     }
 }
Ejemplo n.º 2
0
 public static function get_or_error($array, $key, $location = 'Undefined')
 {
     return isset($array[$key]) ? $array[$key] : Myna::error($location, "no {$key} in array", $array);
 }
Ejemplo n.º 3
0
 public static function error($origin, $reason, $data)
 {
     $message = "{$origin}: {$reason}";
     Myna::var_dump_to_string($data, $message);
     throw new \Exception($message);
 }
Ejemplo n.º 4
0
 /**
  * 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);
     }
 }