self::MESSAGE_TYPE_ERROR, 'message' => $message, 'is_technical_error' => $is_technical_error ]; } /** * Add message with type info. * * @param string $message */ public static function addSuccess(string $message): void { self::$messages[] = [ 'type' => self::MESSAGE_TYPE_SUCCESS, 'message' => $message ]; } /** * Add message with type warning. * * @param string $message */ public static function addWarning(string $message): void { self::$messages[] = [ 'type' => self::MESSAGE_TYPE_WARNING, 'message' => $message ]; } /** * Get messages title. * * @return string|null */ public static function getTitle(): ?string { return self::$title; } /** * Set title for error messages. * * @param string $title */ public static function setErrorTitle(string $title): void { self::$type = self::MESSAGE_TYPE_ERROR; self::$title = $title; } /** * Set title for info messages. * * @param $title */ public static function setSuccessTitle(string $title): void { self::$type = self::MESSAGE_TYPE_SUCCESS; self::$title = $title; } /** * Set title for warning messages. * * @param string $title */ public static function setWarningTitle(string $title): void { self::$type = self::MESSAGE_TYPE_WARNING; self::$title = $title; } /** * Get messages type. * * @return string */ public static function getType(): ?string { return self::$type; } /** * Clear messages. */ public static function clear(): void { self::$type = null; self::$title = null; self::$messages = []; } /** * Set messages from FormData. * * @param array $messages */ public static function setScheduleMessages(array $messages): void { self::$schedule_messages = $messages; } /** * Restore schedule messages. */ public static function restoreScheduleMessages(array $current_messages = []): void { if (self::$schedule_messages) { if (array_key_exists('success', self::$schedule_messages) && self::$schedule_messages['success']) { self::setSuccessTitle(self::$schedule_messages['success']); } if (array_key_exists('error', self::$schedule_messages) && self::$schedule_messages['error']) { self::setErrorTitle(self::$schedule_messages['error']); } if (array_key_exists('messages', self::$schedule_messages)) { foreach (self::$schedule_messages['messages'] as $message) { if (!self::checkDuplicates($message, $current_messages)) { continue; } self::addMessage($message); } } self::$schedule_messages = []; } } /** * Check duplicate from current message for schedule message. * * @param array $message * @param array $current_messages * * @return boolean */ protected static function checkDuplicates(array $message, array $current_messages): bool { foreach ($current_messages as $known_messages) { foreach ($known_messages['messages'] as $known_message) { if (count(array_diff_assoc($known_message, $message)) === 0) { return false; } } } return true; } }