configurationService = $config; } public function getReportData(string $file_path): array { $output = []; // @TODO replace with config service. // $config = $this->dummyConfig()['projects']; $config = $this->configurationService->get('projects'); foreach (array_keys($config) as $key) { $output[$key] = 0; } if ($file = fopen($file_path, 'r')) { while (($line = fgetcsv($file)) !== FALSE) { $parsed = $this->parseCsvFile($line); // $key = reset(array_keys($parsed)); $key = array_key_first($parsed); if (isset($output[$key])) { $output[$key] += (int) reset($parsed); } } } return $output; } protected function parseCsvFile(array $raw_data): array { // $config = $this->dummyConfig(); $config = $this->configurationService->get('projects'); // var_dump($raw_data); foreach ($config as $key => $project) { if (preg_match('/'.$project['pattern'].'/', $raw_data[1])) { return [$key => $raw_data[4]]; } } return []; } protected function dummyConfig(): array { $config = [ 'projects' => [ 'LDP' => [ 'name' => 'lupus.digital', 'pattern' => 'LDP-[0-9]+', 'price' => 26, // optional specify columns ], 'WV' => [ 'name' => 'Wirtschaftsverlag', 'pattern' => 'WV-[0-9]+', 'price' => 26, // optional specify columns ], 'Other' => [ 'name' => 'Other projects', 'pattern' => '(?!.\bLDP\b)(?!.\bWV\b)', 'price' => 26, // optional specify columns ], ], ]; return $config; } }