1: <?php
2:
3: namespace PHPixie\Database\Parser;
4:
5: abstract class Operator
6: {
7: protected $methodMap = array();
8: protected $operators;
9:
10: public function __construct()
11: {
12: $this->buildMethodMap();
13: }
14:
15: public function parse($condition)
16: {
17: $operator = $condition->operator();
18: $method = $this->getMethodName($operator);
19:
20: return $this->$method(
21: $condition->field(),
22: $operator,
23: $condition->values(),
24: $condition->isNegated()
25: );
26: }
27:
28: protected function getMethodName($operator)
29: {
30: if(!isset($this->methodMap[$operator]))
31: throw new \PHPixie\Database\Exception\Parser("The '{$operator}' operator is not supported");
32:
33: return 'parse'.ucfirst($this->methodMap[$operator]);
34: }
35:
36: protected function buildMethodMap()
37: {
38: foreach($this->operators as $method => $operators)
39: foreach($operators as $operator)
40: $this->methodMap[$operator] = $method;
41: }
42: }
43: