public function convertAndDump(\Address\Formatter\Formatter $formatter, $outputFile) { // TODO WRITE HEADER IN OUTPUT FILE $sourceFile = fopen($this->dataFile, 'r'); // Парсим фрагменты файла $processedPercent = 0; while ($data = fread($sourceFile, self::$chunkSize)) { xml_parse($this->parser, $data, feof($sourceFile)); // Форматирование строки $this->queue = array_reverse($this->queue); while (count($this->queue) !== 0) { $tableRow = array_pop($this->queue); $tableRow = array_intersect_key($tableRow + $this->defaultRow, $this->defaultRow); $conversionResult = $formatter->handleDataFile($this->tableName, $tableRow); file_put_contents($outputFile, $conversionResult, FILE_APPEND); } // Вывод прогресса в консоль $this->processedLength += self::$chunkSize; $currentPercent = $this->processedLength < $this->contentLength ? ceil($this->processedLength / $this->contentLength * 100) : 100; if ($this->contentLength > self::$chunkSize && $currentPercent > $processedPercent) { $this->output(' ' . $currentPercent . '%'); } $processedPercent = $currentPercent; } fclose($sourceFile); xml_parser_free($this->parser); }
public function convertAndDump(\Address\Formatter\Formatter $formatter, $dumpFile) { // TODO WRITE HEADER IN OUTPUT FILE $conversionResult = $formatter->handleSchemaFile($this->tableName, $this->schemaDocument); file_put_contents($dumpFile, $conversionResult); }