Ejemplo n.º 1
0
function mapping(AMatch $match)
{
    // Карта ошибок
    $errors_mapping = array(AMatchStatus::KEY_TYPE_NOT_VALID => 'invalid_type', AMatchStatus::KEY_CONDITION_NOT_VALID => 'invalid_data', AMatchStatus::KEY_NOT_EXISTS => 'required');
    $results = $match->matchResults();
    // Результат в кодах
    $comments = $match->matchComments();
    // Комментарий к результату
    $comments_conditions = $match->matchCommentsConditions();
    // Расшифровка результата
    $output = array();
    foreach ($results as $param => $result) {
        $error = array_key_exists($result, $errors_mapping) ? $errors_mapping[$result] : 'other_errors';
        // Ошибка, не имеющая аналогов в карте
        $comment = $param . ': ' . $comments[$param];
        if (isset($comments_conditions[$param]) && !empty($comments_conditions[$param][0])) {
            $comment .= ' (' . $comments_conditions[$param][0] . ')';
            // Дополнительная информация
        }
        $output[$error][] = $comment;
    }
    var_export($output);
}