Exakat\Reports\Uml::generate PHP Метод

generate() публичный Метод

public generate ( $folder, $name = 'uml' )
    public function generate($folder, $name = 'uml')
    {
        $res = $this->sqlite->query(<<<SQL
SELECT name, cit.id, extends, type, namespace, 
       (SELECT GROUP_CONCAT(method,   "||")   FROM methods    WHERE citId = cit.id) AS methods,
       (SELECT GROUP_CONCAT( case when value != '' then property || " = " || substr(value, 0, 40) else property end, "||") FROM properties WHERE citId = cit.id) AS properties
    FROM cit
    JOIN namespaces
        ON namespaces.id = cit.namespaceId
SQL
);
        $id = 0;
        $ids = array();
        $dot = array();
        $links = array();
        $colors = array('class' => 'darkorange', 'trait' => 'gold', 'interface' => 'skyblue');
        $subgraphs = array();
        while ($row = $res->fetchArray()) {
            ++$id;
            if (strlen($row['properties']) > 0) {
                $row['properties'] = "+&nbsp;" . str_replace('||', "<br align='left'/>+&nbsp;", $this->str2dot($row['properties'])) . "<br align='left'/>";
            } elseif ($row['type'] == 'interface') {
                $row['properties'] = "&nbsp;";
            } else {
                $row['properties'] = "<i>No properties</i>";
            }
            if (strlen($row['methods']) > 0) {
                $row['methods'] = "+&nbsp;" . str_replace('||', "<br align='left'/>+&nbsp;", $this->str2dot($row['methods'])) . "<br align='left'/>";
            } else {
                $row['methods'] = "<i>No methods</i>";
            }
            $color = $colors[$row['type']];
            $label = "<<table color='white' BORDER='0' CELLBORDER='1' CELLSPACING='0' >\n                          <tr>\n                              <td bgcolor='{$color}' color='black'>{$row['name']}</td>\n                          </tr>\n                          <tr>\n                              <td color='black' align='left'>{$row['properties']}</td>\n                          </tr>\n                          <tr>\n                              <td color='black' align='left'>{$row['methods']}</td>\n                          </tr>\n                       </table>>";
            $R = $id . ' [label=' . $label . ' shape="none"];';
            $ids[$row['id']] = $id;
            $subgraphs[$row['namespace']] = $R;
            $N = explode('\\', $row['namespace']);
            $dotr =& $dot;
            foreach ($N as $n) {
                if (!isset($dotr[$n])) {
                    $dotr[$n] = array();
                }
                $dotr =& $dotr[$n];
            }
            $dotr[] = $R;
            if (!empty($row['extends'])) {
                $links[] = " {$id} -> {$row['extends']} [label=\"extends\"];";
            }
        }
        $res = $this->sqlite->query(<<<SQL
SELECT implementing, implements, type FROM cit_implements
SQL
);
        while ($row = $res->fetchArray()) {
            $links[] = $ids[$row['implementing']] . " -> " . $ids[$row['implements']] . " [label=\"{$row['type']}\"];";
        }
        $dot = <<<DOT
digraph graphname {        
    fontname = "Bitstream Vera Sans"
    fontsize = 8
    colorscheme = "bugn9"
    
    node [
            fontname = "Bitstream Vera Sans"
            fontsize = 8
            shape = "record"
    ]
    
    edge [
            fontname = "Bitstream Vera Sans"
            fontsize = 8
            arrowhead = "empty"
    ]
 
DOT
 . $this->subgraphs($dot) . "\n\n" . implode("\n", $links) . "\n}\n";
        file_put_contents($folder . '/' . $name . '.' . self::FILE_EXTENSION, $dot);
    }