Exakat\Tasks\Load::saveFiles PHP Метод

saveFiles() приватный Метод

private saveFiles ( )
    private function saveFiles()
    {
        static $extras = array();
        // Saving atoms
        foreach ($this->atoms as $atom) {
            $fileName = $this->exakatDir . '/nodes.g3.' . $atom['atom'] . '.csv';
            assert(!empty($atom), "Atom is empty for {$atom['atom']}\n");
            if ($atom['atom'] === 'Project' && file_exists($fileName)) {
                // Project is saved only once
                continue;
            }
            if (isset($extras[$atom['atom']])) {
                $fp = fopen($fileName, 'a');
            } else {
                $fp = fopen($fileName, 'w+');
                $headers = array('id', 'atom', 'code', 'fullcode', 'line', 'token', 'rank');
                $extras[$atom['atom']] = array();
                foreach (self::$PROP_OPTIONS as $title => $atoms) {
                    if (in_array($atom['atom'], $atoms)) {
                        $headers[] = $title;
                        $extras[$atom['atom']][] = $title;
                    }
                }
                fputcsv($fp, $headers);
            }
            $extra = array();
            foreach ($extras[$atom['atom']] as $e) {
                if ($e == 'variadic' && !isset($atom[$e])) {
                    display(print_r($atom, true));
                }
                $extra[] = isset($atom[$e]) ? '"' . $this->escapeCsv($atom[$e]) . '"' : '"-1"';
            }
            if (count($extras[$atom['atom']]) > 0) {
                $extra = ',' . implode(',', $extra);
            } else {
                $extra = '';
            }
            $written = fwrite($fp, $atom['id'] . ',' . $atom['atom'] . ',"' . $this->escapeCsv($atom['code']) . '","' . $this->escapeCsv($atom['fullcode']) . '",' . (isset($atom['line']) ? $atom['line'] : 0) . ',"' . $this->escapeCsv(isset($atom['token']) ? $atom['token'] : '') . '","' . (isset($atom['rank']) ? $atom['rank'] : -1) . '"' . $extra . "\n");
            if ($written > 2000000) {
                print "Warning : Writing a csv line over 2M in {$fileName}\n";
            }
            fclose($fp);
        }
        $this->atoms = array($this->id0 => $this->atoms[$this->id0]);
        // Saving the links between atoms
        foreach ($this->links as $label => $origins) {
            foreach ($origins as $origin => $destinations) {
                foreach ($destinations as $destination => $links) {
                    assert(!empty($origin), "Unknown origin for Rel files\n");
                    assert(!empty($destination), "Unknown destination for Rel files\n");
                    $csv = $label . '.' . $origin . '.' . $destination;
                    $fileName = $this->exakatDir . '/rels.g3.' . $csv . '.csv';
                    if (isset($extras[$csv])) {
                        $fp = fopen($fileName, 'a');
                    } else {
                        $fp = fopen($fileName, 'w+');
                        fputcsv($fp, array('start', 'end'));
                        $extras[$csv] = 1;
                    }
                    foreach ($links as $link) {
                        fputcsv($fp, array($link['origin'], $link['destination']), ',', '"', '\\');
                    }
                    fclose($fp);
                }
            }
        }
        $this->links = array();
    }
Load