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.

101 lines
1.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 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. ],
  12. 'credit-card-number' => [
  13. 'name' => 'Credit Card Number',
  14. ],
  15. 'distance' => [
  16. 'name' => 'Distance',
  17. ],
  18. 'duration' => [
  19. 'name' => 'Duration',
  20. ],
  21. 'email' => [
  22. 'name' => 'Email',
  23. ],
  24. 'numeral' => [
  25. 'name' => 'Numeral',
  26. ],
  27. 'ordinal' => [
  28. 'name' => 'Ordinal',
  29. ],
  30. 'phone-number' => [
  31. 'name' => 'Phone Number',
  32. ],
  33. 'quantity' => [
  34. 'name' => 'Quantity',
  35. ],
  36. 'temperature' => [
  37. 'name' => 'Temperature',
  38. ],
  39. 'time' => [
  40. 'name' => 'Time',
  41. ],
  42. 'url' => [
  43. 'name' => 'URL',
  44. ],
  45. 'volume' => [
  46. 'name' => 'Volume',
  47. ],
  48. ];
  49. }
  50. public function getSearchers()
  51. {
  52. return array_keys($this->mapper);
  53. }
  54. public function all()
  55. {
  56. $items = [];
  57. foreach ($this->mapper as $key => $value) {
  58. $items[$key] = [
  59. 'id' => $key,
  60. 'name' => $value['name'],
  61. ];
  62. }
  63. return $items;
  64. }
  65. public function has($id)
  66. {
  67. return in_array($id, $this->getSearchers());
  68. }
  69. public function get($id)
  70. {
  71. if ( ! $this->has($id)) {
  72. return null;
  73. }
  74. return array_merge($this->mapper[$id], [
  75. 'id' => $id,
  76. 'description' => '',
  77. ]);
  78. }
  79. }