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.

40 lines
921 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\SearchDisplace\Searchers;
  3. class Searcher
  4. {
  5. protected $searchers;
  6. protected $content;
  7. public function __construct($searchers, $content)
  8. {
  9. $this->searchers = $searchers;
  10. $this->content = $content;
  11. ksort($this->searchers);
  12. }
  13. public function execute()
  14. {
  15. $mapper = new Mapper();
  16. $validSearchers = $mapper->getSearchers();
  17. // The object should contain the searcher name, other info, like the user input.
  18. $dimensions = [];
  19. foreach ($this->searchers as $orderNumber => $searcher) {
  20. if ( ! in_array($searcher['key'], $validSearchers)) {
  21. throw new \Exception('Invalid searcher: ' . $searcher['key']);
  22. }
  23. $dimensions[] = $searcher['key'];
  24. }
  25. $duckling = new Duckling();
  26. return $duckling->execute($this->content, $dimensions);
  27. }
  28. }