/** * 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); } }
public function __construct($deploymentUuid, $sessionBuilder, $cache) { $this->cache = $cache; $deployment = \Myna\Data\Deployment::fromArray(json_decode($cache->get($deploymentUuid), true)); parent::__construct($deployment, $sessionBuilder); }