Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\SearchDisplace\Documents\DocumentFile;
  4. use App\SearchDisplace\SearchAndDisplace;
  5. class SearchAndDisplaceController extends Controller
  6. {
  7. public function show($id)
  8. {
  9. $handler = new DocumentFile();
  10. try {
  11. $documentContent = $handler->getAfterIngest($id);
  12. return response()->json([
  13. 'content' => $documentContent,
  14. 'ingest_status' => !! $documentContent ? 'success' : 'fail',
  15. ], 200);
  16. } catch (\Exception $exception) {
  17. return response()->json([
  18. 'message' => $exception->getMessage(),
  19. ], 400);
  20. }
  21. }
  22. public function store()
  23. {
  24. request()->validate([
  25. 'content' => 'required', // String or file.
  26. 'searchers' => 'required|array', // Check if matches all rules, must have 'key' and 'replace_with'.
  27. ]);
  28. $searchAndDisplace = new SearchAndDisplace(request()->input('content'), [
  29. 'searchers' => request()->input('searchers'),
  30. ]);
  31. try {
  32. return response()->json($searchAndDisplace->execute(), 200);
  33. } catch (\Exception $exception) {
  34. return response()->json([
  35. 'message' => $exception->getMessage(),
  36. 'trace' => $exception->getTrace(),
  37. ], 400);
  38. }
  39. }
  40. }