/** * Performs some special handling if the operator requires a range or a * list. * * @param string, array $operand */ protected function _validateRightOperand($operand) { if ($this->_operator == self::OP_BETWEEN || $this->_operator == self::OP_IN) { /* This logic doesn't attempt to verify that the ends of a range are valid for range comparison, as that's sort of a pain. */ if (is_array($operand)) { if ($this->_operator == self::OP_BETWEEN) { if (count($operand) != 2) { throw new InvalidArgumentException('When passing an array as an operand to a range ' . 'operator, it must contain exactly two values.'); } $operand = implode('_', $operand); } else { foreach ($operand as &$opComponent) { $opComponent = \PFXUtils::escape($opComponent, '|'); } $operand = implode('|', $operand); } } elseif ($this->_operator == self::OP_BETWEEN) { $components = explode('_', $operand); if (count($components) != 2) { throw new InvalidArgumentException('Operands used with the <> operator must have ' . 'exactly two boundaries separated by an underscore.'); } } } return parent::_validateRightOperand($operand); }
/** * Tests the parsing of conditional expressions from their string * representations. */ public function testParsingFromString() { $x = new GaDataConditionalExpression('ga:foo==bar'); $this->assertEquals('ga:foo', $x->getLeftOperand()); $this->assertEquals(GaDataConditionalExpression::OP_EQ, $x->getOperator()); $this->assertEquals('bar', $x->getRightOperand()); $x = new GaDataConditionalExpression('ga:bar!@234.5'); $this->assertEquals('ga:bar', $x->getLeftOperand()); $this->assertEquals(GaDataConditionalExpression::OP_NOT_CONTAINS, $x->getOperator()); $this->assertEquals(234.5, $x->getRightOperand()); $x = new GaDataConditionalExpression('ga:baz=~foo\\,bar'); $this->assertEquals('ga:baz', $x->getLeftOperand()); $this->assertEquals(GaDataConditionalExpression::OP_REGEXP, $x->getOperator()); $this->assertEquals('foo\\,bar', $x->getRightOperand()); $x = new GaDataConditionalExpression('ga:bumf!~a\\;b\\;c\\;d\\;'); $this->assertEquals('ga:bumf', $x->getLeftOperand()); $this->assertEquals(GaDataConditionalExpression::OP_NOT_REGEXP, $x->getOperator()); $this->assertEquals('a\\;b\\;c\\;d\\;', $x->getRightOperand()); // The parsing should also perform escaping where necessary $x = new GaDataConditionalExpression('ga:asdf>=2,5'); $this->assertEquals('ga:asdf', $x->getLeftOperand()); $this->assertEquals(GaDataConditionalExpression::OP_GE, $x->getOperator()); $this->assertEquals('2\\,5', $x->getRightOperand()); }