public function getFileContent($filePath, $createIfNotExists = false) { if ($createIfNotExists && !$this->disk->exists($filePath)) { if (!$this->disk->exists($directory = dirname($filePath))) { mkdir($directory, 0777, true); } file_put_contents($filePath, "<?php\n\nreturn [];"); return []; } try { return (array) (include $filePath); } catch (\ErrorException $e) { throw new FileNotFoundException('File not found: ' . $filePath); } }
/** * The output of the table rows. * * @return array */ private function tableRows() { $allLanguages = $this->manager->languages(); $filesContent = []; $output = []; foreach ($this->files as $fileName => $fileLanguages) { foreach ($fileLanguages as $languageKey => $filePath) { $lines = $filesContent[$fileName][$languageKey] = Arr::dot($this->manager->getFileContent($filePath)); foreach ($lines as $key => $line) { if (!is_array($line) && stripos($line, $this->argument('keyword')) !== false) { $output[$fileName . '.' . $key][$languageKey] = "<bg=yellow;fg=black>{$line}</>"; } } } } // Now that we collected all values that matches the keyword argument // in a close match, we collect the values for the rest of the // languages for the found keys to complete the table view. foreach ($output as $fullKey => $values) { list($fileName, $key) = explode('.', $fullKey, 2); $original = []; foreach ($allLanguages as $languageKey) { $original[$languageKey] = isset($values[$languageKey]) ? $values[$languageKey] : isset($filesContent[$fileName][$languageKey][$key]) ? $filesContent[$fileName][$languageKey][$key] : ''; } // Sort the language values based on language name ksort($original); $output[$fullKey] = array_merge(['key' => "<fg=yellow>{$fullKey}</>"], $original); } return array_values($output); }