示例#1
0
文件: Arr.php 项目: myna/myna-php
 public static function get_or_error($array, $key, $location = 'Undefined')
 {
     return isset($array[$key]) ? $array[$key] : Myna::error($location, "no {$key} in array", $array);
 }
示例#2
0
文件: Api.php 项目: myna/myna-php
 /**
  * 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);
     }
 }