/** * @param $filePath * @param string $fromCharSet * @param string $toCharSet * @return array */ public function import_csv($filePath, $fromCharSet = 'UTF-8', $toCharSet = 'UTF-8') { $config = new LexerConfig(); $config->setDelimiter(';')->setEnclosure("'")->setEscape("\\")->setToCharset($toCharSet)->setFromCharset($fromCharSet); $lexer = new Lexer($config); $interpreter = new Interpreter(); $data = array(); $interpreter->addObserver(function (array $row) use(&$data) { $data[] = $row; }); $lexer->parse($filePath, $interpreter); $attributes = array(); $items = array(); foreach ($data as $i => $row) { if (1 == $i) { $attributes = $row; } if ($i > 1) { $one = array(); foreach ($attributes as $j => $attribute) { if (array_key_exists($j, $row)) { $one[$attribute] = $row[$j]; } } $items[] = $one; } } return $items; }
/** * @expectedException \InvalidArgumentException */ public function testInvalidLine() { $interpreter = new Interpreter(); $sqlObserver = new SqlObserver('test', array('id', 'name'), 'dummy'); $interpreter->addObserver(array($sqlObserver, 'notify')); $interpreter->interpret(array('123', array('test'))); }
/** * Get a new CSVParser using defined settings. * @return Iterator */ public function getIterator() { if (!file_exists($this->filepath)) { //TODO: throw exception instead? return null; } $header = $this->hasheader ? $this->getFirstRow() : null; $output = array(); $config = new LexerConfig(); $config->setDelimiter($this->delimiter); $config->setEnclosure($this->enclosure); $config->setIgnoreHeaderLine($this->hasheader); $interpreter = new Interpreter(); // Ignore row column count consistency $interpreter->unstrict(); $interpreter->addObserver(function (array $row) use(&$output, $header) { if ($header) { //create new row using headings as keys $newrow = array(); foreach ($header as $k => $heading) { if (isset($row[$k])) { $newrow[$heading] = $row[$k]; } } $row = $newrow; } $output[] = $row; }); $lexer = new Lexer($config); $lexer->parse($this->filepath, $interpreter); return new ArrayIterator($output); }
/** * {@inheritdoc} */ public function readerTest() { $interpreter = new Interpreter(); $interpreter->addObserver(function (array $rows) { }); $lexer = new Lexer(new LexerConfig()); $lexer->parse($this->path, $interpreter); }
public function csvInterpreter($file, \Closure $closure) { $config = new LexerConfig(); $config->setDelimiter("\t")->setEnclosure("'")->setEscape("\\")->setToCharset('UTF-8')->setFromCharset('UTF-8'); $lexer = new Lexer(new LexerConfig()); $interpreter = new Interpreter(); $interpreter->addObserver($closure); $lexer->parse($file, $interpreter); }
/** * {@inheritdoc} */ public function load($resource, $type = null) { $lexer = new Lexer($this->lexerConfig); $interpreter = new Interpreter(); $interpreter->addObserver($this->getCallback()); $lexer->parse($resource, $interpreter); $this->loaded = true; return $this->getRows(); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage value is invalid: array */ public function testInvalidLine() { $interpreter = new Interpreter(); $table = 'test'; $options = array('user' => $this->manager->getUser(), 'password' => $this->manager->getPassword()); $sqlObserver = new PdoObserver($table, array('id', 'name'), $this->manager->getDsn(), $options); $interpreter->addObserver(array($sqlObserver, 'notify')); $interpreter->interpret(array('123', array('test', 'test'))); }
/** * @param $path string absolute path to file * @param $closure \Closure * @void */ public function parse($path, Closure $closure) { $config = new LexerConfig(); $config->setDelimiter($this->delimeter); $config->setFromCharset($this->fromCharset); $config->setToCharset($this->toCharset); $lexer = new Lexer($config); $interpreter = new Interpreter(); $interpreter->addObserver($closure); $lexer->parse($path, $interpreter); }
public function up(Schema $schema) { $lexer = new Lexer(new LexerConfig()); $words = array(); $interpreter = new Interpreter(); $interpreter->addObserver(function (array $row) use(&$words) { $words[] = '(' . $this->connection->quote($row[0], \PDO::PARAM_STR) . ')'; }); $lexer->parse(__DIR__ . '/../Resources/files/words.english', $interpreter); $this->addSql('INSERT INTO word (word) VALUES ' . implode(',', $words)); }
public static function import($file, $callback) { $config = new LexerConfig(); $config->setDelimiter(";"); $lexer = new Lexer($config); $interpreter = new Interpreter(); $header = null; $observer = new CSVImporterLexerAssociativeObserver(); $observer->setCallback($callback); $interpreter->addObserver($observer->observer); $lexer->parse($file->getRealPath(), $interpreter); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); $config = new CSV\LexerConfig(); $config->setDelimiter(',')->setEnclosure('"')->setFromCharset('UTF-8')->setToCharset('UTF-8'); $this->manager = $this->getContainer()->get('doctrine.orm.entity_manager'); $lexer = new CSV\Lexer($config); $interpreter = new CSV\Interpreter(); $interpreter->addObserver($this->getObserver()); $lexer->parse($file, $interpreter); $this->manager->flush(); }
/** * @param $file * @param Closure|null $callback * @return array|null */ public function import($file, Closure $callback = null) { $interpreter = new Interpreter(); if ($this->unstrict) { $interpreter->unstrict(); } if (is_null($callback)) { $results = array(); $callback = function (array $row) use(&$results) { $results[] = $row; }; } else { $results = null; } $interpreter->addObserver($callback); $lexer = new Lexer($this->config); $lexer->parse($file, $interpreter); return $results; }
/** * Decode from format * * @method decode * @param {String} $datastore context identifier * @void */ public static function Decode(Resource $resource) { // TODO: «non-silly-impl» // lazy lib work around $data = array(); $tmpfilename = time() . ".tmp.csv"; file_put_contents($tmpfilename, $resource->content()); // setup lexer $lexer = new Lexer(new LexerConfig()); $interpreter = new Interpreter(); // do nothing $interpreter->addObserver(function (array $row) use(&$data) { $data[] = $row; }); // process file $lexer->parse($tmpfilename, $interpreter); // cleanup unlink($tmpfilename); return $data; }
/** * Run the database seeds. * * @return void */ public function run() { $lexer = new Lexer(new LexerConfig()); $interpreter = new Interpreter(); $interpreter->addObserver(function (array $row) { $peak = new \App\Peak(); $peak->created_at = Carbon\Carbon::now()->toDateTimeString(); $peak->updated_at = Carbon\Carbon::now()->toDateTimeString(); $peak->name = $row[0]; $peak->elevation = $row[1]; $peak->prominence = $row[2]; $peak->state = $row[3]; $peak->location = $row[4]; $peak->range = $row[5]; $peak->forecast_link = $row[6]; $peak->description_link = $row[7]; $peak->save(); }); $peakscsv = database_path() . '/seeds/peaks.csv'; $lexer->parse($peakscsv, $interpreter); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; // load composer use Goodby\CSV\Import\Standard\Lexer; use Goodby\CSV\Import\Standard\Interpreter; use Goodby\CSV\Import\Standard\LexerConfig; // the result comes into this variable $temperature = array(); // set up lexer $config = new LexerConfig(); $config->setDelimiter("\t"); $config->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_CSV); $lexer = new Lexer($config); // set up interpreter $interpreter = new Interpreter(); $interpreter->addObserver(function (array $row) use(&$temperature) { $temperature[] = array('temperature' => $row[0], 'city' => $row[1]); }); // parse $lexer->parse('temperature.tsv', $interpreter); var_dump($temperature);
/** * Extract data from de CSV and create new Location objects * * @param string $countryCode Country code * @param string $pathname Pathname * * @return LocationInterface Root location */ private function loadLocationsFrom($countryCode, $pathname) { $countryInfo = $this->getCountryInfo($countryCode); $country = $this->locationBuilder->addLocation($countryInfo[0], $countryInfo[1], $countryInfo[0], 'country'); $interpreter = new Interpreter(); $interpreter->unstrict(); $nbItems = 0; $interpreter->addObserver(function (array $columns) use($country, &$nbItems) { if (isset($columns[1], $columns[2], $columns[3], $columns[4], $columns[5], $columns[6])) { $nbItems++; $stateId = $this->normalizeId($columns[4]); $state = $this->locationBuilder->addLocation($country->getId() . '_' . $stateId, $columns[3], $stateId, 'state', $country); $provinceId = $this->normalizeId($columns[6]); $province = $this->locationBuilder->addLocation($state->getId() . '_' . $provinceId, $columns[5], $provinceId, 'province', $state); $cityId = $this->normalizeId($columns[2]); $city = $this->locationBuilder->addLocation($province->getId() . '_' . $cityId, $columns[2], $cityId, 'city', $province); $postalCodeId = $this->normalizeId($columns[1]); $this->locationBuilder->addLocation($city->getId() . '_' . $postalCodeId, $columns[1], $postalCodeId, 'postalcode', $city); } }); $config = new LexerConfig(); $config->setDelimiter("\t"); $lexer = new Lexer($config); $lexer->parse($pathname, $interpreter); return $country; }
$account = $text = ""; $continue_on_next_line = false; // Open file if ($fp = fopen($file, "r")) { // data from CSV $valuesToImport = array(); // load libraries require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Goodby/CSV/Import/Standard/Lexer.php'; require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Goodby/CSV/Import/Standard/Interpreter.php'; require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Goodby/CSV/Import/Standard/LexerConfig.php'; // Lexer configuration $config = new LexerConfig(); $lexer = new Lexer($config); $config->setIgnoreHeaderLine("true"); // extract data from CSV file $interpreter = new Interpreter(); $interpreter->addObserver(function (array $row) use(&$valuesToImport) { $valuesToImport[] = array('Label' => $row[0], 'Login' => $row[1], 'Password' => $row[2], 'url' => $row[3], 'Comments' => $row[4]); }); $lexer->parse($file, $interpreter); // extract one line foreach ($valuesToImport as $key => $row) { //Check number of fields. MUST be 5. if not stop importation if (count($row) != 5) { $importation_possible = false; //Stop if file has not expected structure if ($importation_possible == false) { echo '[{"error":"bad_structure"}]'; break; } }
public function loadBeneficio(ServicioContratado $servicio) { $file = sprintf(__DIR__ . '/../../Resources/files/%s.csv', $servicio->getNombre() == "Desayunos" ? '100' : '200'); $config = new LexerConfig(); $config->setDelimiter(',')->setEnclosure('"')->setFromCharset('UTF-8')->setToCharset('UTF-8'); $lexer = new Lexer($config); $manager = $this->manager; $bag =& $this->bag; $repo = $this->manager->getRepository('SisesApplicationBundle:Ubicacion\\CentroPoblado'); $findLugar = function ($columns) use($repo, &$bag, $manager) { $nombre = $columns[LoadBeneficiarios::COL_NOM_LUGAR]; $codigoLugar = $columns[LoadBeneficiarios::COL_CODIGO_UBICACION]; if (!isset($bag[LoadBeneficiarios::BAG_UBICACION][$nombre])) { if (!isset($bag[LoadBeneficiarios::BAG_LUGAR][$codigoLugar])) { $bag[LoadBeneficiarios::BAG_LUGAR][$codigoLugar] = $repo->findOneBy(array('codigoDane' => "{$codigoLugar}000")); } $lugar = new LugarEntrega(); $lugar->setUbicacion($bag[LoadBeneficiarios::BAG_LUGAR][$codigoLugar]); $lugar->setNombre($nombre); $manager->persist($lugar); $bag[LoadBeneficiarios::BAG_UBICACION][$nombre] = $lugar; } return $bag[LoadBeneficiarios::BAG_UBICACION][$nombre]; }; $repo2 = $this->manager->getRepository('SisesApplicationBundle:Persona'); $findPersona = function ($column) use($repo2, &$bag, $manager) { $documento = $column[LoadBeneficiarios::COL_DOCUMENTO]; // Busca la persona en la base d datos if (!isset($bag[LoadBeneficiarios::BAG_PERSONA][$documento])) { $bag[LoadBeneficiarios::BAG_PERSONA][$documento] = $repo2->findOneBy(array('documento' => $documento)); } // Crea la persona if (!isset($bag[LoadBeneficiarios::BAG_PERSONA][$documento])) { $persona = new Persona(); $persona->setNombre(trim("{$column[LoadBeneficiarios::COL_1_NOM]} {$column[LoadBeneficiarios::COL_2_NOM]}")); $persona->setApellidos(trim("{$column[LoadBeneficiarios::COL_1_APE]} {$column[LoadBeneficiarios::COL_2_APE]}")); $persona->setDocumento($documento); $manager->persist($persona); $bag[LoadBeneficiarios::BAG_PERSONA][$documento] = $persona; } return $bag[LoadBeneficiarios::BAG_PERSONA][$documento]; }; $interpreter = new Interpreter(); $interpreter->addObserver(function (array $columns) use($bag, $findLugar, $findPersona, $servicio, $manager) { if ($columns[0] == "AÑO") { return; } $beneficiario = new Beneficiario(); $beneficiario->setPersona($findPersona($columns)); $beneficiario->setContrato($servicio->getContrato()); $beneficio = new Beneficio(); $beneficio->setBeneficiario($beneficiario); $beneficio->setLugar($findLugar($columns)); $beneficio->setServicio($servicio); $manager->persist($beneficiario); $manager->persist($beneficio); }); $lexer->parse($file, $interpreter); ksort($bag['ubicacion']); $manager->flush(); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; // load composer use Goodby\CSV\Import\Standard\Lexer; use Goodby\CSV\Import\Standard\Interpreter; use Goodby\CSV\Import\Standard\LexerConfig; $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'root'); $pdo->query('CREATE TABLE IF NOT EXISTS user (id INT, `name` VARCHAR(255), email VARCHAR(255))'); $config = new LexerConfig(); $lexer = new Lexer($config); $interpreter = new Interpreter(); $interpreter->addObserver(function (array $columns) use($pdo) { $checkStmt = $pdo->prepare('SELECT count(*) FROM user WHERE id = ?'); $checkStmt->execute(array($columns[0])); $count = $checkStmt->fetchAll()[0][0]; if ($count === 0) { $stmt = $pdo->prepare('INSERT INTO user (id, name, email) VALUES (?, ?, ?)'); $stmt->execute($columns); } }); $lexer->parse('user.csv', $interpreter);
/** * CSV parser * * @param string $file Path of the file. * @return array Returns the array from csv. * @since 0.1.0 */ public static function csv_parser($csv_file) { if (!is_file($csv_file)) { return new WP_Error('error', 'The CSV file is not found.'); } elseif (!self::is_textfile($csv_file)) { return new WP_Error('error', 'The file is not CSV.'); } $csv = array(); /** * Filter the CSV setting for the csv parser. * * @param array settings for the csv parser. */ $format = apply_filters('acsv_csv_format', array('from_charset' => 'UTF-8', 'to_charset' => 'UTF-8', 'delimiter' => ',', 'enclosure' => '"', 'escape' => '\\')); $config = new LexerConfig(); $config->setFromCharset($format['from_charset']); $config->setToCharset($format['to_charset']); $config->setDelimiter($format['delimiter']); $config->setEnclosure($format['enclosure']); $config->setEscape($format['escape']); $lexer = new Lexer($config); $interpreter = new Interpreter(); $interpreter->unstrict(); $interpreter->addObserver(function (array $row) use(&$csv) { $csv[] = $row; }); $lexer->parse($csv_file, $interpreter); return $csv; }
/** * @return Interpreter */ protected function getInterpreter() { $interpreter = new Interpreter(); $interpreter->unstrict(); return $interpreter; }
/** * @expectedException \InvalidArgumentException */ public function testInvalidCallbale() { $interpreter = new Interpreter(); $interpreter->addObserver('dummy'); $interpreter->interpret($this->expectedLine); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; // load composer use Goodby\CSV\Import\Standard\Lexer; use Goodby\CSV\Import\Standard\Interpreter; use Goodby\CSV\Import\Standard\LexerConfig; use Goodby\CSV\Export\Standard\Exporter; use Goodby\CSV\Export\Standard\ExporterConfig; $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'root', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $pdo->query('CREATE TABLE IF NOT EXISTS user (id INT, `name` VARCHAR(255), email VARCHAR(255))'); // Importing $config = new LexerConfig(); $lexer = new Lexer($config); $interpreter = new Interpreter(); $interpreter->addObserver(function (array $columns) use($pdo) { $stmt = $pdo->prepare('INSERT INTO user (id, name, email) VALUES (?, ?, ?)'); $stmt->execute($columns); }); $lexer->parse('user.csv', $interpreter); // Exporting $config = new ExporterConfig(); $exporter = new Exporter($config); $exporter->export('php://output', array(array('1', 'alice', '*****@*****.**'), array('2', 'bob', '*****@*****.**'), array('3', 'carol', '*****@*****.**')));
public function test_ignore_header() { $csvFilename = CSVFiles::getIssue5CSV(); $config = new LexerConfig(); $config->setIgnoreHeaderLine(true)->setToCharset('UTF-8')->setFromCharset('UTF-8'); $lexer = new Lexer($config); $interpreter = new Interpreter(); $interpreter->addObserver(function (array $columns) use(&$csvContents) { $csvContents[] = $columns; }); $lexer->parse($csvFilename, $interpreter); $this->assertSame(array(array("1", "スティック型クリーナ", "*****@*****.**"), array("2", "bob", "*****@*****.**"), array("14", "スティック型クリーナ", "*****@*****.**"), array("16", "スティック型", "*****@*****.**")), $csvContents); }
private function loadData(ServicioContratado $servicio) { $manager = $this->manager; $bag =& $this->bag; /** @var EntityRepository $repo */ $repo = $this->manager->getRepository('SisesApplicationBundle:Ubicacion\\CentroPoblado'); $repoLugar = $this->manager->getRepository('SisesApplicationBundle:LugarEntrega'); $findLugar = function ($columns) use($repo, $repoLugar, &$bag, $manager) { $nombre = $columns[self::COL_NOM_LUGAR]; $codigoUbicacion = $columns[self::COL_CODIGO_UBICACION]; if (!isset($bag[self::BAG_LUGAR][$nombre])) { $bag[self::BAG_LUGAR][$nombre] = $repoLugar->findOneBy(array('nombre' => $nombre)); } if (!$bag[self::BAG_LUGAR][$nombre]) { if (!isset($bag[self::BAG_UBICACION][$codigoUbicacion])) { $bag[self::BAG_UBICACION][$codigoUbicacion] = $repo->findOneBy(array('codigoDane' => "{$codigoUbicacion}000")); } if (!$bag[self::BAG_UBICACION][$codigoUbicacion]) { throw new \Exception("No se encontro el municipio para codigo {$codigoUbicacion}"); } $lugar = new LugarEntrega(); $lugar->setUbicacion($bag[self::BAG_UBICACION][$codigoUbicacion]); $lugar->setNombre($nombre); $manager->persist($lugar); $bag[self::BAG_LUGAR][$nombre] = $lugar; } return $bag[self::BAG_LUGAR][$nombre]; }; /** @var EntityRepository $repo2 */ $repo2 = $this->manager->getRepository('SisesApplicationBundle:Persona'); $findPersona = function ($column) use($repo2, &$bag, $manager) { $documento = $column[self::COL_DOCUMENTO]; // Busca la persona en la base d datos if (!isset($bag[self::BAG_PERSONA][$documento])) { $bag[self::BAG_PERSONA][$documento] = $repo2->findOneBy(array('documento' => $documento)); } // Crea la persona if (!$bag[self::BAG_PERSONA][$documento]) { $persona = new Persona(); $persona->setNombre(trim("{$column[self::COL_1_NOM]} {$column[self::COL_2_NOM]}")); $persona->setApellidos(trim("{$column[self::COL_1_APE]} {$column[self::COL_2_APE]}")); $persona->setDocumento($documento); $manager->persist($persona); $bag[self::BAG_PERSONA][$documento] = $persona; } return $bag[self::BAG_PERSONA][$documento]; }; $interpreter = new CSV\Interpreter(); $interpreter->addObserver(function (array $columns) use($bag, $findLugar, $findPersona, $servicio, $manager) { if ($columns[0] == "AÑO") { return; } $beneficiario = new Beneficiario(); $beneficiario->setPersona($findPersona($columns)); $beneficiario->setContrato($servicio->getContrato()); $beneficio = new Beneficio(); $beneficio->setBeneficiario($beneficiario); $beneficio->setLugar($findLugar($columns)); $beneficio->setServicio($servicio); $manager->persist($beneficiario); $manager->persist($beneficio); }); $this->lexer->parse($this->file, $interpreter); ksort($bag['ubicacion']); $manager->flush(); }
public function store() { $validator = Validator::make(Input::all(), StockData::$validation_rule); $response = array('status' => 1); if ($validator->passes()) { $filename = time() . '.csv'; Input::file('file')->move(base_path() . '/data', $filename); $config = new LexerConfig(); $lexer = new Lexer($config); $interpreter = new Interpreter(); $row = 0; $stockdata = null; $interpreter->addObserver(function (array $columns) use(&$row, &$stockdata) { if ($row == 0) { if (count($columns) != 28) { } else { $valid = true; $stockdata = new StockData(); $stockdata->user_id = Auth::user()->id; $stockdata->title = Input::get('title'); $stockdata->save(); } } else { if ($stockdata) { $stockdata_row = new StockDataRow(); $tmp = explode(' ', $columns[3]); $stockdata_row->stock_data_id = $stockdata->id; $stockdata_row->rank = $columns[0]; $stockdata_row->symbol = $columns[1]; $stockdata_row->name = $columns[2]; $stockdata_row->exchange = trim($tmp[0]); $stockdata_row->country = trim(str_replace('(', '', str_replace(')', '', $tmp[1]))); $stockdata_row->industry = $columns[4]; $stockdata_row->market_cap = $columns[5]; $stockdata_row->z_score = $columns[6]; $stockdata_row->m_score = $columns[7]; $stockdata_row->f_score = $columns[8]; $stockdata_row->pe_ratio = $columns[9]; $stockdata_row->forward_pe = $columns[10]; $stockdata_row->forward_growth = $columns[11]; $stockdata_row->pb_ratio = $columns[12]; $stockdata_row->asset_growth = $columns[13]; $stockdata_row->ret_1y = $columns[14]; $stockdata_row->off_max_15 = $columns[15]; $stockdata_row->roe = $columns[16]; $stockdata_row->basic_nri_pct_diff = $columns[17]; $stockdata_row->eps_rsd = $columns[18]; $stockdata_row->eps_gr = $columns[19]; $stockdata_row->ss_demand = $columns[20]; $stockdata_row->ss_util = $columns[21]; $stockdata_row->accruals = $columns[22]; $stockdata_row->roa = $columns[23]; $stockdata_row->issuance = $columns[24]; $stockdata_row->noa = $columns[25]; $stockdata_row->profitability = $columns[26]; $stockdata_row->beta = $columns[27]; $stockdata_row->save(); } } $row++; }); $lexer->parse(base_path() . '/data/' . $filename, $interpreter); if ($stockdata) { $response['stockdata'] = $stockdata; $response['message'] = $row . " rows inserted."; } else { $response['status'] = 0; $response['message'] = "There's an error in the CSV file. Please download the template file."; } } else { $response['status'] = 0; $response['message'] = $validator->messages()->first(); } echo json_encode($response); }
/** * Populate a country * * @param OutputInterface $output The output interface * @param string $countryCode Country Code * @param boolean $sourcePackageMustbeReloaded Source package must be reloaded * * @return CountryInterface|null Country populated if created */ public function populateCountry(OutputInterface $output, $countryCode, $sourcePackageMustbeReloaded) { $countryCode = strtoupper($countryCode); $file = $this->downloadRemoteFileFromCountryCode($output, $countryCode, $sourcePackageMustbeReloaded); $countryData = $this->getCountryArray()[$countryCode]; $country = $this->geoBuilder->addCountry($countryData[0], $countryData[1]); $interpreter = new Interpreter(); $interpreter->unstrict(); $interpreter->addObserver(function (array $columns) use($country) { $state = $this->geoBuilder->addState($country, $columns[4], $columns[3]); $province = $this->geoBuilder->addProvince($state, $columns[6], $columns[5]); $city = $this->geoBuilder->addCity($province, $columns[2]); $this->geoBuilder->addPostalCode($city, $columns[1]); }); $config = new LexerConfig(); $config->setDelimiter("\t"); $lexer = new Lexer($config); $started = new DateTime(); $output->writeln('<header>[Geo]</header> <body>Starting file processing</body>'); $lexer->parse($file->getRealpath(), $interpreter); $finished = new DateTime(); $elapsed = $finished->diff($started); $output->writeln('<header>[Geo]</header> <body>File processed in ' . $elapsed->format('%s') . ' seconds</body>'); return $country; }