public function addCondition($condition = array())
{
$flag = !empty($condition['case']) ? 'D' : '';
if (empty($this->_conditions)) {
$this->addFlag($flag);
}
$string = '';
$extra = '';
$match = isset($condition['match']) ? $condition['match'] : null;
// negate tests starting with 'not ', except 'not equals', which simply uses the != operator
if ($match != 'not equal' && substr($match, 0, 4) == 'not ') {
$string .= '! ';
}
// convert 'field' to PCRE pattern matching
if (strpos($condition['field'], ',') == false) {
$string .= '/^' . $condition['field'] . ':\\s*';
} else {
$string .= '/^(' . str_replace(',', '|', $condition['field']) . '):\\s*';
}
switch ($match) {
case 'not regex':
case 'regex':
$string .= $condition['value'] . '/:h';
break;
case 'filter':
$string = $condition['value'];
break;
case 'exists':
case 'not exist':
// Just run a match for the header name
$string .= '/:h';
break;
case 'less than or equal to':
case 'less than':
case 'equal':
case 'not equal':
case 'greater than or equal to':
case 'greater than':
$string .= '(\\d+(\\.\\d+)?)/:h';
$extra = ' && $MATCH1 ' . $this->_operators[$match] . ' ' . (int) $condition['value'];
break;
case 'begins with':
case 'not begins with':
$string .= preg_quote($condition['value'], '/') . '/:h';
break;
case 'ends with':
case 'not ends with':
$string .= '.*' . preg_quote($condition['value'], '/') . '$/:h';
break;
case 'is':
case 'not is':
$string .= preg_quote($condition['value'], '/') . '$/:h';
break;
case 'matches':
case 'not matches':
$string .= str_replace(array('\\*', '\\?'), array('.*', '.'), preg_quote($condition['value'], '/') . '$') . '/:h';
break;
case 'contains':
case 'not contain':
default:
$string .= '.*' . preg_quote($condition['value'], '/') . '/:h';
break;
}
$this->_conditions[] = array('condition' => $string, 'flags' => $flag, 'extra' => $extra);
}