function handle_render_request($request) { $graph = new Graph(); /* Assign the requested graph direction and export format */ $graph->set_direction($request["direction"]); $graph->set_export_format($request["export"]); /* Add each node and set its shape */ foreach ($request["nodes"] as $node) { $graph->add_node($node["name"]); $graph->set_node_shape($node["name"], $node["shape"]); } /* Add each edge */ foreach ($request["edges"] as $edge) { $graph->add_edge($edge["origin"], $edge["destination"], $edge["label"]); } /* Export each graph and lookup it's mediatype */ error_log($graph->compile()); $binary = $graph->export(); $mediatype = export_media_type($request); $encoding = base64_encode($binary); $response = array("mediatype" => $mediatype, "encoding" => $encoding); return $response; }