Subversion Repositories oidplus

Rev

Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. # if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
  4. # if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
  5.  
  6. require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
  7.  
  8. class VolcanoSearchStrI implements VolcanoSearchProvider {
  9.         public static function checkId($id) {
  10.                 return self::strEqual($id, 'stri', true); // is always case insensitive
  11.         }
  12.  
  13.         public static function calcDistance($candidate, $searchterm) {
  14.                 return (self::strEqual($candidate, $searchterm, true)) ? 0 : -1;
  15.         }
  16.  
  17.         protected static function strEqual($str1, $str2, $caseInsensitive = false) {
  18.                 if ($caseInsensitive) {
  19.                         return strtolower($str1) == strtolower($str2);
  20.                 } else {
  21.                         return $str1 == $str2;
  22.                 }
  23.         }
  24. }
  25.  
  26. require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
  27. VolcanoDB::registerSearchProvider(new VolcanoSearchStrI());
  28.  
  29. # --- TEST
  30.  
  31. /*
  32. $x = new VolcanoSearchStrI();
  33. assert($x->calcDistance('a', 'a') ==  0);
  34. assert($x->calcDistance('a', 'A') ==  0);
  35. assert($x->calcDistance('a', 'b') == -1);
  36. */
  37.  
  38.