Subversion Repositories oidplus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
226 daniel-mar 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 VolcanoSearchStr implements VolcanoSearchProvider {
9
        public static function checkId($id) {
10
                return self::strEqual($id, 'str', true); // is always case insensitive
11
        }
12
 
13
        public static function calcDistance($candidate, $searchterm) {
14
                return (self::strEqual($candidate, $searchterm, false)) ? 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 VolcanoSearchStr());
28
 
29
# --- TEST
30
 
31
/*
32
$x = new VolcanoSearchStr();
33
assert($x->calcDistance('a', 'a') ==  0);
34
assert($x->calcDistance('a', 'A') == -1);
35
assert($x->calcDistance('a', 'b') == -1);
36
*/
37