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.

73 lines
1.7 KiB

  1. <?php
  2. namespace App\SearchDisplace\Searchers;
  3. use Illuminate\Support\Facades\Storage;
  4. class SearchersStorage
  5. {
  6. protected $storage;
  7. protected $searchers = [];
  8. public function __construct()
  9. {
  10. $this->storage = Storage::disk('local');
  11. }
  12. public function all()
  13. {
  14. $searchers = [];
  15. $files = $this->storage->files('searchers');
  16. foreach ($files as $file) {
  17. if (pathinfo($file, PATHINFO_EXTENSION) === 'json') {
  18. $fileName = pathinfo($file, PATHINFO_FILENAME);
  19. $result = explode('_', $fileName);
  20. if (count($result) < 2) {
  21. continue;
  22. }
  23. $searchers[$fileName] = [
  24. 'id' => $fileName,
  25. 'name' => $result[1],
  26. 'tag' => '',
  27. 'param' => SearchersCollection::PARAM_REQUIRED,
  28. ];
  29. if (count($result) === 3) {
  30. $searchers[$fileName]['tag'] = $result[2];
  31. // $searchers[$fileName]['param'] = SearchersCollection::PARAM_REQUIRED;
  32. }
  33. // if (count($result) === 3) {
  34. // $searchers[$fileName]['param'] = $result[2];
  35. // }
  36. }
  37. }
  38. return $searchers;
  39. }
  40. public function has($id)
  41. {
  42. return $this->storage->exists("searchers/$id.json");
  43. }
  44. public function get($id)
  45. {
  46. $contents = $this->storage->get("searchers/$id.json");
  47. return json_decode($contents, true);
  48. }
  49. public function destroy($id)
  50. {
  51. if ( ! $this->has($id)) {
  52. return false;
  53. }
  54. return $this->storage->delete("searchers/$id.json");
  55. }
  56. }