<?php

namespace ThurData\Servers\KerioEmail\App\Libs\Restrictions\Interfaces;


use function ThurData\Servers\KerioEmail\Core\Helper\di;
use ThurData\Servers\KerioEmail\Core\Lang\Lang;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 07.11.19
 * Time: 10:02
 * Class AbstractRule
 */
abstract class AbstractRule implements RuleInterface
{

    /**
     * @var string
     */
    protected $message = 'somethingWentWrong';

    /**
     * @var array
     */
    protected $replacements = [];

    /**
     * @param $key
     * @param $value
     * @return $this
     */
    protected function addReplacement($key, $value)
    {
        $this->replacements[$key] = $value;
        return $this;
    }
    /**
     *
     * @return mixed|void
     */
    public function getMessage()
    {
        /* @var $lang Lang*/
        $lang = di('lang');

        foreach($this->replacements as $key => $repl)
        {
            $lang->addReplacementConstant($key, $repl);
        }

        return $lang->absoluteT('restrictions', 'error', $this->message);
    }

}