$value) { $atts[] = "$key: $value"; } if (!empty ($atts)) $string .= '|' . implode('\l', $atts) . '\l}'; $record = array ( 'shape' => 'record', 'label' => '{' . $string . '}', 'id' => $id, 'group' => NULL, ); if (!empty ($url)) $record['URL'] = url($url); // Add optional styling static $graphviz_styles; if (! isset($graphviz_styles)) $graphviz_styles = module_invoke_all('graphviz_styles'); if (isset($graphviz_styles[$type])) { $record = array_merge($record, $graphviz_styles[$type]); } #else {dpm("no special style setting for $type");} return $record; } /** * Utility to dump a php object or array * Recursive. * * Setting 'group' is intended to help apply some hints to the graph, getting * all members of an array lined up together. */ function graphviz_add_item(&$G, $item, $name='', $group ='') { $record = graphviz_construct_item($G, $item, $name, $group); $G->addNode($record['id'], $record, $record['group']); return $record['id']; } function graphviz_construct_item(&$G, $item, $name='', $group ='') { $type = gettype($item); static $ids, $id_count, $done_objects; if (empty($done_objects)) $done_objects = array(); $id_count ++; $item_id = $type .'-'. $id_count; // Prevent looping recursion by keeping a note of seen things // and returning just the ID if it's already built if (is_object($item) || is_array($item)) { $item_id = md5(print_r($item, 1)); // this will return the internal obj id as a string } if (in_array($item_id, $done_objects)) { return $item_id; } $done_objects[] = $item_id; // Build object $item = (array) $item; $children = array(); foreach ($item as $varname => $value) { if (is_array($value) || is_object($value)) { $children[$varname] = $value; } else { $attributes[] = "$varname: " . strip_tags($value); } } $dot_string = $name; if (!empty ($type)) { $dot_string = "$type: " . $dot_string; } if (!empty ($attributes)) { $dot_string .= '|' . implode('\l', $attributes) . '\l}'; } $record = array ( 'shape' => 'record', 'label' => '{' . $dot_string . '}', 'color' => 'blue', ); if ($group) {$record['group'] = $group;} $record['id'] = $item_id; // Now add the children foreach ($children as $child_id => $child_item) { if (! empty($child_item)) { // show the children in a group together $groupname = ($type == 'array') ? $item_id : ''; $child_item_id = graphviz_add_item($G, $child_item, $child_id, $groupname); $G->addEdge(array($item_id => $child_item_id), array('color' => 'blue')); } } return $record; }