argument('path'); $searchers = $this->argument('filters'); $id = md5(uniqid(rand(), true)); $this->storeSearchers($id, $searchers, $documentPath); try { $sendToIngest = new SendDocument(); $sendToIngest->execute($documentPath, $id); $this->info('Processing document..'); $this->info('After the processing will be done the result will show up at the same path as the input.'); } catch (\Exception $exception) { $this->error('Something went wrong. (' . $exception->getMessage() . ')'); } } protected function storeSearchers($id, $searchers, $documentPath) { $data = [ 'searchers' => $this->getSearchers($searchers), 'document_path' => $documentPath, ]; $storage = Storage::disk('local'); $storage->put("searchers/$id.json", json_encode($data)); } protected function getSearchers($searchers) { if (count($searchers) === 1 && str_contains($searchers[0], '.json')) { return $this->getSearchersFromFile($searchers[0]); } return $this->getSearchersFromList($searchers); } protected function getSearchersFromList($searchers) { $list = []; foreach ($searchers as $searcher) { $result = explode(':', $searcher); $list[] = [ 'key' => $result[0], 'replace_with' => $result[1], ]; } return $list; } protected function getSearchersFromFile($path) { $contents = file_get_contents($path); if ( ! $contents) { throw new \Exception('Something went wrong when tried reading from file.'); } return json_decode($contents); } }