* @package Mammut\DB\Sql */ class Compare extends \Mammut\StrictObject implements iExprBool { protected $left; protected $comparator; protected $right; public function __construct($left = null, $comparator = null, $right = null, $lefttype = iExprValue::TYPE_IDENTIFIER, $righttype = iExprValue::TYPE_VALUE) { if (!is_null($left)) $this->setLeft($left, $lefttype); if (!is_null($right)) $this->setRight($right, $righttype); if (!is_null($comparator)) $this->setComparator($comparator); } public function setLeft($value, $type = iExprValue::TYPE_IDENTIFIER) { if($value instanceof Parameter) $type = iExprValue::TYPE_PARAMETER; $this->left = new Literal($value, $type); return $this; } public function getLeft() { return $this->left; } public function setRight($value, $type = iExprValue::TYPE_VALUE) { if($value instanceof Parameter) $type = iExprValue::TYPE_PARAMETER; $this->right = new Literal($value, $type); return $this; } public function getRight() { return $this->right; } public function setComparator($comparator) { $allowed = [self::OP_EQ,self::OP_NE,self::OP_GT,self::OP_GTE,self::OP_LT,self::OP_LTE]; if(!in_array($comparator, $allowed)) throw new \InvalidArgumentException('type:' . $comparator); $this->comparator = $comparator; return $this; } public function getComparator() { return $this->comparator; } }