protected function ProcessConstraints(array $p_constraints)
{
$parameters = array();
$state = 1;
$attribute = null;
$operator = null;
$value = null;
foreach ($p_constraints as $word) {
switch ($state) {
case 1:
// reading the parameter name
if (!array_key_exists($word, BoxArticlesList::$s_parameters)) {
CampTemplate::singleton()->trigger_error("invalid attribute {$word} in statement list_box_articles, constraints parameter");
return false;
}
$attribute = $word;
$state = 2;
break;
case 2:
// reading the operator
$type = BoxArticlesList::$s_parameters[$attribute]['type'];
try {
$operator = new Operator($word, $type);
} catch (InvalidOperatorException $e) {
CampTemplate::singleton()->trigger_error("invalid operator {$word} of parameter constraints.{$attribute} in statement list_box_articles");
return false;
}
$state = 3;
break;
case 3:
// reading the value to compare against
$type = BoxArticlesList::$s_parameters[$attribute]['type'];
$metaClassName = 'Meta' . strtoupper($type[0]) . strtolower(substr($type, 1));
try {
$value = new $metaClassName($word);
$value = $word;
$comparisonOperation = new ComparisonOperation($attribute, $operator, $value);
$parameters[] = $comparisonOperation;
} catch (InvalidValueException $e) {
CampTemplate::singleton()->trigger_error("invalid value {$word} of parameter constraints.{$attribute} in statement list_box_articles");
return false;
}
$state = 1;
break;
}
}
if ($state != 1) {
CampTemplate::singleton()->trigger_error("unexpected end of constraints parameter in list_box_articles");
return false;
}
return $parameters;
}