Insensitive.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Config;
  10. use ForkBB\Models\Method;
  11. class Insensitive extends Method
  12. {
  13. /**
  14. * Проверяет регистронезависимое сравнение в БД через таблицу config
  15. */
  16. public function insensitive(): bool
  17. {
  18. $result = $this->c->Cache->get('case_insensitive', null);
  19. if (! \is_bool($result)) {
  20. $like = 'pgsql' === $this->c->DB->getType() ? 'ILIKE' : 'LIKE';
  21. $query = "SELECT conf_value
  22. FROM ::config
  23. WHERE conf_name {$like} 's#_регистр' ESCAPE '#'";
  24. $result = 'Ok' === $this->c->DB->query($query)->fetchColumn();
  25. if (true !== $this->c->Cache->set('case_insensitive', $result)) {
  26. throw new RuntimeException('Unable to write value to cache - case_insensitive');
  27. }
  28. }
  29. return $result;
  30. }
  31. }