<?php
namespace App\Validators;

/**
 * Replace the :date attribute value in a validation error message with the
 * locale-specific date format.
 *
 * Registered in AppServiceProvider.
 *
 * @author Christian Weiske <weiske@mogic.com>
 */
class LocalDateFormatReplacer
{
    /**
     * Replace the :date attribute value with the local date format.
     *
     * @param string $message    Message with ":date" placeholder
     * @param string $attribute  Name of attribute (e.g. "contract_start")
     * @param string $rule       Name of the rule (e.g. "before_or_equals")
     * @param array  $parameters Attributes to dipsplay. Key 0 is the date.
     *
     * @return string Final message with replaced :date
     */
    function replace($message, $attribute, $rule, $parameters)
    {
        $parameters[0] = format_local_date($parameters[0]);
        return str_replace(':date', $parameters[0], $message);
    }
}
?>
