public function save_chunk()
{
if (static::$fp_nodes === null) {
static::$fp_nodes = fopen('nodes.csv', 'a');
}
$fp = static::$fp_nodes;
// adding in_quote here, as it may not appear on the first token.
$les_cols = array('token', 'code', 'index', 'fullcode', 'line', 'atom', 'root', 'hidden', 'compile', 'in_quote', 'in_for', 'modifiedBy', 'delimiter', 'noDelimiter', 'rank', 'block', 'bracket', 'filename', 'tag', 'association');
if (static::$file_saved == 0) {
$les_cols2 = $les_cols;
$les_cols2[4] .= ':int';
fputcsv($fp, $les_cols2, "\t");
unset($les_cols2);
}
foreach (static::$nodes as $id => $node) {
$row = array();
foreach ($les_cols as $col) {
if (isset($node[$col])) {
$row[$col] = $node[$col];
} elseif ($col == 'line') {
$row[$col] = 0;
} else {
$row[$col] = '';
}
if ($diff = array_diff(array_keys($row), $les_cols, array('id'))) {
display("Some columns were not processed : " . implode(", ", $diff) . ".\n");
}
}
$row['code'] = $this->escapeString($row['code']);
$row['fullcode'] = $this->escapeString($row['fullcode']);
$row['delimiter'] = $this->escapeString($row['delimiter']);
$row['noDelimiter'] = $this->escapeString($row['noDelimiter']);
fputcsv($fp, $row, "\t");
}
static::$nodes = array();
if (static::$fp_rels === null) {
static::$fp_rels = fopen('rels.csv', 'a');
}
$fp = static::$fp_rels;
if (static::$file_saved == 0) {
fputcsv($fp, array('start', 'end', 'type', 'classname', 'function', 'namespace', 'file'), "\t");
}
foreach (static::$links as $id => $link) {
if (isset($link['namespace'])) {
$link['namespace'] = $this->escapeString($link['namespace']);
}
fputcsv($fp, $link, "\t");
}
static::$links = array();
++static::$file_saved;
}