public static function open($project_url, $ticket)
{
$url = fix_parse_url($project_url);
$response = SimpleHTTP::send('POST', $url['host'], $url['port'], $url['path'], array('a' => 'open', 'ticket' => $ticket));
if ('200' != $response['status_code']) {
throw new Exception("Invalid status code `{$response['status_code']}' returned from server `{$url['host']}'.");
}
$response = trim($response['body']);
if ('' === $response) {
throw new Exception("Unable to open project, no content returned from `{$url['host']}{$url['path']}'.");
}
if ('#S#' == substr($response, 0, 3)) {
$document = DOMDocument::loadXML(substr($response, 3));
$data = array('resources' => array(), 'opened-resource' => array());
$lst = $document->documentElement->getElementsByTagName('resources');
if (0 == $lst->length) {
throw new Exception("Invalid protocol response received from `{$url['host']}{$url['path']}': No resources collection element.");
}
$node_resources = $lst->item(0);
$num_nodes = $node_resources->childNodes->length;
for ($i = 0; $i < $num_nodes; $i++) {
$node = $node_resources->childNodes->item($i);
if (1 == $node->nodeType && 'resource' == $node->tagName) {
try {
$resource = simplexml_import_dom($node);
$ser_resource = array();
foreach (get_object_vars($resource) as $name => $property) {
$ser_resource[$name] = (string) $property;
}
$data['resources'][] = $ser_resource;
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
}
return $data;
}
throw new Exception(substr($response, 3));
}