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.

59 lines
1.3 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. $searchers[$fileName] = [
  22. 'id' => $fileName,
  23. 'name' => $result[1],
  24. ];
  25. }
  26. }
  27. }
  28. return $searchers;
  29. }
  30. public function has($id)
  31. {
  32. return $this->storage->exists("searchers/$id.json");
  33. }
  34. public function get($id)
  35. {
  36. $contents = $this->storage->get("searchers/$id.json");
  37. return json_decode($contents, true);
  38. }
  39. public function destroy($id)
  40. {
  41. if ( ! $this->has($id)) {
  42. return false;
  43. }
  44. return $this->storage->delete("searchers/$id.json");
  45. }
  46. }