/** * @param string|array $expressions */ public function __construct($expressions) { if (!is_string($expressions) && !is_array($expressions)) { throw new InvalidExprException('The value of "expressions" must not be a string or an array data type.'); } if (empty($expressions)) { throw new InvalidExprException('The value of "expressions" can not be empty.'); } if (is_string($expressions)) { $expressions = explode('|', trim($expressions)); } $expressions = array_filter($expressions); if (count($expressions) < 2) { throw new InvalidExprException('The number of "expressions" must be greater than or equals two.'); } $invalidExpressionsToOr = ['paginate', 'sort', 'or']; foreach ($expressions as $expression) { foreach ($invalidExpressionsToOr as $invalidExpression) { if (stripos($expression, sprintf(':%s:', $invalidExpression)) !== false) { throw new InvalidExprException(sprintf('The value of "expressions" contains the "%s" expression.', $invalidExpression)); } } } $this->expression = 'or'; $this->operator = 'or'; $this->field = null; $this->value = $expressions; $parser = new StringParser(implode('|', $expressions)); $this->queue = $parser->setSeparator('|')->parse(); }
public function testSeparator() { $parser = new StringParser('field:eq:value'); $this->assertEquals('&', $parser->getSeparator()); $parser->setSeparator('@'); $this->assertEquals('@', $parser->getSeparator()); }