00001 <?php
00002
00019 final class SMWQueryLanguage {
00020
00029 protected static $comparators = array();
00030
00039 public static function getComparatorStrings() {
00040 self::initializeComparators();
00041 return array_keys( self::$comparators );
00042 }
00043
00055 public static function getComparatorFromString( $string, $defaultComparator = SMW_CMP_EQ ) {
00056 self::initializeComparators();
00057 if ( $string === '' ) return SMW_CMP_EQ;
00058 return array_key_exists( $string, self::$comparators ) ? self::$comparators[$string] : $defaultComparator;
00059 }
00060
00070 public static function getStringForComparator( $comparator ) {
00071 self::initializeComparators();
00072 static $reverseCache = false;
00073
00074 if ( $reverseCache === false ) {
00075 $reverseCache = array_flip( self::$comparators );
00076 }
00077
00078 if ( $comparator == SMW_CMP_EQ ) {
00079 return '';
00080 } elseif ( array_key_exists( $comparator, $reverseCache ) ) {
00081 return $reverseCache[$comparator];
00082 } else {
00083 throw new Exception( "Comparator $comparator does not have a string representatation" );
00084 }
00085 }
00086
00092 protected static function initializeComparators() {
00093 global $smwgQComparators, $smwStrictComparators;
00094 static $initialized = false;
00095
00096 if ( $initialized ) {
00097 return;
00098 }
00099
00100 $initialized = true;
00101
00102
00103 $comparators = array(
00104 '!~' => SMW_CMP_NLKE,
00105 '<<' => SMW_CMP_LESS,
00106 '>>' => SMW_CMP_GRTR,
00107 '<' => $smwStrictComparators ? SMW_CMP_LESS : SMW_CMP_LEQ,
00108 '>' => $smwStrictComparators ? SMW_CMP_GRTR : SMW_CMP_GEQ,
00109 '≤' => SMW_CMP_LEQ,
00110 '≥' => SMW_CMP_GEQ,
00111 '!' => SMW_CMP_NEQ,
00112 '~' => SMW_CMP_LIKE,
00113 );
00114
00115 $allowedComparators = explode( '|', $smwgQComparators );
00116
00117
00118 foreach ( $comparators as $string => $comparator ) {
00119 if ( !in_array( $string, $allowedComparators ) ) {
00120 unset( $comparators[$string] );
00121 }
00122 }
00123
00124 self::$comparators = $comparators;
00125 }
00126
00127 }