public static function pad(
        $input,
        $pad_length,
        $pad_string = ' ',
        $pad_type = STR_PAD_RIGHT
    ) {
        $output = '';
        $length = $pad_length - mb_strlen($input);

        if ($pad_string === null || mb_strlen($pad_string) === 0) {
            $pad_string = ' ';
        }

        if ($length > 0) {
            switch ($pad_type) {
                case STR_PAD_LEFT:
                    $padding = str_repeat(
                        $pad_string,
                        ceil($length / mb_strlen($pad_string))
                    );
                    $output = mb_substr($padding, 0, $length) . $input;
                    break;

                case STR_PAD_BOTH:
                    $left_length = floor($length / 2);
                    $right_length = ceil($length / 2);
                    $padding = str_repeat(
                        $pad_string,
                        ceil($right_length / mb_strlen($pad_string))
                    );
                    $output =
                        mb_substr($padding, 0, $left_length) .
                        $input .
                        mb_substr($padding, 0, $right_length);

                    break;

                case STR_PAD_RIGHT:
                default:
                    $padding = str_repeat(
                        $pad_string,
                        ceil($length / mb_strlen($pad_string))
                    );
                    $output = $input . mb_substr($padding, 0, $length);
            }
        } else {
            $output = $input;
        }
        return $output;
    }