SectionsList::ProcessConstraints PHP Method

ProcessConstraints() protected method

Processes list constraints passed in an array.
protected ProcessConstraints ( array $p_constraints ) : array
$p_constraints array
return array
    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, SectionsList::$s_parameters)) {
                        CampTemplate::singleton()->trigger_error("invalid attribute {$word} in statement list_sections, constraints parameter");
                        return false;
                    }
                    $attribute = $word;
                    $state = 2;
                    break;
                case 2:
                    // reading the operator
                    $type = SectionsList::$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_sections");
                        return false;
                    }
                    $state = 3;
                    break;
                case 3:
                    // reading the value to compare against
                    $type = SectionsList::$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_sections");
                        return false;
                    }
                    $state = 1;
                    break;
            }
        }
        if ($state != 1) {
            CampTemplate::singleton()->trigger_error("unexpected end of constraints parameter in list_sections");
            return false;
        }
        return $parameters;
    }