Example #1
0
 /**
  * Constructs and returns a validation failure message
  * with the given message key and value.
  * If a translator is available, the translation will be used.
  *
  * @param   int     The key of message.
  * @param   mixed   The value to validate.
  * @return  string  The generated message for validation failure.
  */
 protected function createMessage($key, $value = null)
 {
     // Gets the failure message by key.
     $message = isset(static::$MESSAGE_TEMPLATE[$key]) ? static::$MESSAGE_TEMPLATE[$key] : 'Unexpected validation failure messages is occurred';
     // 1) Translates the temaplte message
     // 2) Replaces the magical constant value
     // 3) Replaces the placeholder to bound variables.
     // 4) Auto-adjust the length of final generated message.
     $message = static::translateMessage($message);
     $message = Util\StringUtils::replace(self::MAGIC_BIND_NAME_VALUE, $value, $message, static::$obscuredValue);
     $message = Util\StringUtils::bindValues($message, $this->option, $strict = false);
     if (static::$autoAdjustMessage) {
         $message = Util\StringUtils::adjust($message, static::$maxMessageLength);
     }
     return $message;
 }