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.
51 lines
1.4 KiB
51 lines
1.4 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\SearchDisplace\Documents\DocumentFile;
|
|
use App\SearchDisplace\SearchAndDisplace;
|
|
|
|
class SearchAndDisplaceController extends Controller
|
|
{
|
|
public function show($id)
|
|
{
|
|
$handler = new DocumentFile();
|
|
|
|
try {
|
|
$documentContent = $handler->getAfterIngest($id);
|
|
|
|
return response()->json([
|
|
'content' => $documentContent,
|
|
'ingest_status' => !! $documentContent ? 'success' : 'fail',
|
|
], 200);
|
|
} catch (\Exception $exception) {
|
|
return response()->json([
|
|
'message' => $exception->getMessage(),
|
|
], 400);
|
|
}
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
request()->validate([
|
|
'content' => 'required', // String or file.
|
|
'searchers' => 'required|array', // Check if matches all rules, must have 'key' and 'replace_with'.
|
|
]);
|
|
|
|
$searchAndDisplace = new SearchAndDisplace(request()->get('content'), [
|
|
'searchers' => request()->get('searchers'),
|
|
]);
|
|
|
|
try {
|
|
$resultedDocumentContent = $searchAndDisplace->execute();
|
|
|
|
return response()->json([
|
|
'content' => $resultedDocumentContent,
|
|
], 200);
|
|
} catch (\Exception $exception) {
|
|
return response()->json([
|
|
'message' => $exception->getMessage(),
|
|
], 400);
|
|
}
|
|
}
|
|
}
|