src/Validation.php
private function formatMessage($format, $context = []) {
        $format = $this->translate($format);

        $msg = preg_replace_callback('`({[^{}]+})`', function ($m) use ($context) {
            $args = array_filter(array_map('trim', explode(',', trim($m[1], '{}'))));
            $field = array_shift($args);

            switch ($field) {
                case 'value':
                    return $this->formatValue($context[$field] ?? null);
                case 'field':
                    $field = $context['field'] ?: 'value';
                    return $this->formatFieldName($field);
                default:
                    return $this->formatField(isset($context[$field]) ? $context[$field] : null, $args);
            }
        }, $format);
        return $msg;
    }
private function formatMessage($format, $context = []) {
        $format = $this->translate($format);

        $msg = preg_replace_callback('`({[^{}]+})`', function ($m) use ($context) {
            $args = array_filter(array_map('trim', explode(',', trim($m[1], '{}'))));
            $field = array_shift($args);

            switch ($field) {
                case 'value':
                    return $this->formatValue($context[$field] ?? null);
                case 'field':
                    $field = $context['field'] ?: 'value';
                    return $this->formatFieldName($field);
                default:
                    return $this->formatField(isset($context[$field]) ? $context[$field] : null, $args);
            }
        }, $format);
        return $msg;
    }
private function formatMessage ( $ format , $ context = [ ] ) { $ format = $ this -> translate ( $ format ) ; $ msg = preg_replace_callback ( '`({[^{}]+})`' , function ( $ m ) use ( $ context ) { $ args = array_filter ( array_map ( 'trim' , explode ( ',' , trim ( $ m [ 1 ] , '{}' ) ) ) ) ; $ field = array_shift ( $ args ) ; switch ( $ field ) { case 'value' : return $ this -> formatValue ( $ context [ $ field ] ?? null ) ; case 'field' : $ field = $ context [ 'field' ] ? : 'value' ; return $ this -> formatFieldName ( $ field ) ; default : return $ this -> formatField ( isset ( $ context [ $ field ] ) ? $ context [ $ field ] : null , $ args ) ; } } , $ format ) ; return $ msg ; }
Expand and translate a message format against an array of values.

@param string $format The message format.
@param array $context The context arguments to apply to the message.
@return string Returns a formatted string.
Expand and translate a message format against an array of values .