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.

57 lines
1.3 KiB

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