1 | <?php namespace Gears\String\Methods; |
||
16 | trait Pad |
||
17 | { |
||
18 | /** |
||
19 | * Pads the string to a given length with $padStr. |
||
20 | * |
||
21 | * If length is less than or equal to the length of the string, no padding |
||
22 | * takes places. The default string used for padding is a space, and the |
||
23 | * default type (one of 'left', 'right', 'both') is 'right'. |
||
24 | * |
||
25 | * @param int $length Desired string length after padding. |
||
26 | * |
||
27 | * @param string $padStr String used to pad, defaults to space. |
||
28 | * |
||
29 | * @param string $padType One of 'left', 'right', 'both'. |
||
30 | * |
||
31 | * @return static String after being padded. |
||
32 | * |
||
33 | * @throws \InvalidArgumentException If $padType isn't one of 'right', |
||
34 | * 'left' or 'both'. |
||
35 | */ |
||
36 | public function pad($length, $padStr = ' ', $padType = 'right') |
||
58 | |||
59 | /** |
||
60 | * Adds padding to the left of the string. |
||
61 | * |
||
62 | * @param int $length Desired string length after padding. |
||
63 | * |
||
64 | * @param string $padStr String used to pad, defaults to space. |
||
65 | * |
||
66 | * @return static String with left padding. |
||
67 | */ |
||
68 | public function padLeft($length, $padStr = ' ') |
||
72 | |||
73 | /** |
||
74 | * Adds padding to the right of the string. |
||
75 | * |
||
76 | * @param int $length Desired string length after padding. |
||
77 | * |
||
78 | * @param string $padStr String used to pad, defaults to space. |
||
79 | * |
||
80 | * @return static String with right padding. |
||
81 | */ |
||
82 | public function padRight($length, $padStr = ' ') |
||
86 | |||
87 | /** |
||
88 | * Adds padding to both sides of the string, equally. |
||
89 | * |
||
90 | * @param int $length Desired string length after padding. |
||
91 | * |
||
92 | * @param string $padStr String used to pad, defaults to space. |
||
93 | * |
||
94 | * @return static String with padding applied to both sides. |
||
95 | */ |
||
96 | public function padBoth($length, $padStr = ' ') |
||
101 | |||
102 | /** |
||
103 | * Pad internal helper, adds padding to the left and right of the string. |
||
104 | * |
||
105 | * @param int $left Length of left padding. |
||
106 | * |
||
107 | * @param int $right Length of right padding. |
||
108 | * |
||
109 | * @param string $padStr String used to pad, default is a space. |
||
110 | * |
||
111 | * @return static String with padding applied. |
||
112 | */ |
||
113 | protected function applyPadding($left = 0, $right = 0, $padStr = ' ') |
||
139 | } |
||
140 |