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.

54 lines
1.2 KiB

  1. <?php
  2. namespace App\SearchDisplace\Searchers;
  3. class SearchersCollection
  4. {
  5. public function all()
  6. {
  7. $collection = [];
  8. foreach ((new SearchersStorage())->all() as $item) {
  9. $collection[] = array_merge($item, [
  10. 'type' => 'custom',
  11. ]);
  12. }
  13. foreach ((new Mapper)->all() as $item) {
  14. $collection[] = array_merge($item, [
  15. 'type' => 'duckling',
  16. ]);
  17. }
  18. return $collection;
  19. }
  20. public function get($id)
  21. {
  22. $searcherStorage = new SearchersStorage();
  23. if ($searcherStorage->has($id)) {
  24. return array_merge($searcherStorage->get($id), [
  25. 'type' => 'custom',
  26. ]);
  27. }
  28. $ducklingMapper = new Mapper();
  29. if ($ducklingMapper->has($id)) {
  30. return array_merge($ducklingMapper->get($id), [
  31. 'type' => 'duckling',
  32. ]);
  33. }
  34. return null;
  35. }
  36. public function has($id)
  37. {
  38. $searcherStorage = new SearchersStorage();
  39. $ducklingMapper = new Mapper();
  40. return $searcherStorage->has($id) || $ducklingMapper->has($id);
  41. }
  42. }