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.

115 lines
2.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\SearchDisplace\Searchers;
  3. class Mapper
  4. {
  5. protected $mapper;
  6. public function __construct()
  7. {
  8. $this->mapper = [
  9. 'amount-of-money' => [
  10. 'name' => 'Amount Of Money',
  11. 'param' => SearchersCollection::PARAM_REQUIRED
  12. ],
  13. 'credit-card-number' => [
  14. 'name' => 'Credit Card Number',
  15. 'param' => SearchersCollection::PARAM_REQUIRED
  16. ],
  17. 'distance' => [
  18. 'name' => 'Distance',
  19. 'param' => SearchersCollection::PARAM_REQUIRED
  20. ],
  21. 'duration' => [
  22. 'name' => 'Duration',
  23. 'param' => SearchersCollection::PARAM_REQUIRED
  24. ],
  25. 'email' => [
  26. 'name' => 'Email',
  27. 'param' => SearchersCollection::PARAM_OPTIONAL
  28. ],
  29. 'numeral' => [
  30. 'name' => 'Numeral',
  31. 'param' => SearchersCollection::PARAM_REQUIRED
  32. ],
  33. 'ordinal' => [
  34. 'name' => 'Ordinal',
  35. 'param' => SearchersCollection::PARAM_REQUIRED
  36. ],
  37. 'phone-number' => [
  38. 'name' => 'Phone Number',
  39. 'param' => SearchersCollection::PARAM_REQUIRED
  40. ],
  41. 'quantity' => [
  42. 'name' => 'Quantity',
  43. 'param' => SearchersCollection::PARAM_REQUIRED
  44. ],
  45. 'temperature' => [
  46. 'name' => 'Temperature',
  47. 'param' => SearchersCollection::PARAM_REQUIRED
  48. ],
  49. 'time' => [
  50. 'name' => 'Time',
  51. 'param' => SearchersCollection::PARAM_REQUIRED
  52. ],
  53. 'url' => [
  54. 'name' => 'URL',
  55. 'param' => SearchersCollection::PARAM_REQUIRED
  56. ],
  57. 'volume' => [
  58. 'name' => 'Volume',
  59. 'param' => SearchersCollection::PARAM_REQUIRED
  60. ],
  61. ];
  62. }
  63. public function getSearchers()
  64. {
  65. return array_keys($this->mapper);
  66. }
  67. public function all()
  68. {
  69. $items = [];
  70. foreach ($this->mapper as $key => $value) {
  71. $items[$key] = [
  72. 'id' => $key,
  73. 'name' => $value['name'],
  74. 'param' => $value['param']
  75. ];
  76. }
  77. return $items;
  78. }
  79. public function has($id)
  80. {
  81. return in_array($id, $this->getSearchers());
  82. }
  83. public function get($id)
  84. {
  85. if ( ! $this->has($id)) {
  86. return null;
  87. }
  88. return array_merge($this->mapper[$id], [
  89. 'id' => $id,
  90. 'description' => '',
  91. ]);
  92. }
  93. }