Created
June 24, 2015 21:38
-
-
Save martinamps/73d150e9dcda4c77d451 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Attribute: string { | |
UINT = 'sql_attr_uint'; | |
BOOL = 'sql_attr_bool'; | |
BIGINT = 'sql_attr_bigint'; | |
TIMESTAMP = 'sql_attr_timestamp'; | |
STR2ORDINAL = 'sql_attr_str2ordinal'; | |
FLOAT = 'sql_attr_float'; | |
MULTI = 'sql_attr_multi'; | |
STRING = 'sql_attr_string'; | |
STR2WORDCOUNT = 'sql_attr_str2wordcount'; | |
} | |
enum Field: string { | |
STRING = 'sql_field_string'; | |
STR2WORDCOUNT = 'sql_field_str2wordcount'; | |
} | |
abstract class Source { | |
private string $name; | |
private Map<string, mixed> $params = Map { | |
'type' => 'plain', | |
'docinfo' => 'extern' | |
}; | |
private Vector<Pair<Attribute, string>> $attributes; | |
private Vector<Pair<Field, string>> $fields; | |
public function __construct() { | |
$this->name = __CLASS__; | |
$this->params['path'] = "/data/{$this->name}/index"; | |
} | |
public function __set(string $key, mixed $val) : void { | |
$this->params[$key] = $val; | |
} | |
public function __isset(string $key) : bool { | |
return isset($this->params[$key]); | |
} | |
public function __get(string $key) : mixed { | |
if (isset($this->params[$key])) { | |
return $this->params[$key]; | |
} | |
throw new \OutOfBoundsException("Invalid key passed to Sphinx\Sources\{this->name}::__get"); | |
} | |
public function __unset(string $key) : Map<string, mixed> { | |
return $this->params->remove($key); | |
} | |
public function __toString() : string /* duh */ { | |
$output = ''; | |
foreach ($this->params as $key => $val) { | |
$output .= "$key $val\n"; | |
} | |
return $output; | |
} | |
public function addAttribute(Attribute $type, string $column) { | |
$this->attributes[] = Pair {$type, $column }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment