1 | <?php |
||
7 | final class Multiline extends ArrayCollection |
||
8 | { |
||
9 | /** |
||
10 | * @var \nochso\Omni\EOL |
||
11 | */ |
||
12 | private $eol; |
||
13 | |||
14 | /** |
||
15 | * Create a new Multiline object from a string. |
||
16 | * |
||
17 | * First the input string is split into lines by the detected end-of-line |
||
18 | * character. Afterwards any extra EOL chars will be trimmed. |
||
19 | * |
||
20 | * @see \nochso\Omni\EOL |
||
21 | * |
||
22 | * @param string $input A string to split into a Multiline object |
||
23 | * @param string $defaultEol Default end-of-line type to split the input by. This is a fallback in case it could |
||
24 | * not be detected from the input string. Optional, defaults to `EOL::EOL_LF` i.e. "\n". |
||
25 | * See the `EOL::EOL_*` class constants. |
||
26 | * |
||
27 | * @return \nochso\Omni\Multiline |
||
28 | */ |
||
29 | public static function create($input, $defaultEol = \nochso\Omni\EOL::EOL_LF) |
||
41 | |||
42 | /** |
||
43 | * __toString returns a single string using the current EOL style. |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | public function __toString() |
||
51 | |||
52 | /** |
||
53 | * Get EOL style ending. |
||
54 | * |
||
55 | * @return \nochso\Omni\EOL |
||
56 | */ |
||
57 | public function getEol() |
||
61 | |||
62 | /** |
||
63 | * getMaxLength of all lines. |
||
64 | * |
||
65 | * @return int |
||
66 | */ |
||
67 | public function getMaxLength() |
||
75 | |||
76 | /** |
||
77 | * Set EOL used by this Multiline string. |
||
78 | * |
||
79 | * @param \nochso\Omni\EOL|string $eol Either an `EOL` object or a string ("\r\n" or "\n") |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function setEol($eol) |
||
91 | |||
92 | /** |
||
93 | * Append text to a certain line. |
||
94 | * |
||
95 | * @param string $text |
||
96 | * @param null|int $index Optional, defaults to the last line. Other |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function append($text, $index = null) |
||
108 | |||
109 | /** |
||
110 | * Prefix all lines with a string. |
||
111 | * |
||
112 | * @param string $prefix The prefix to add to the start of the string. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public function prefix($prefix) |
||
123 | |||
124 | /** |
||
125 | * Pad all lines to the same length using `str_pad`. |
||
126 | * |
||
127 | * @param int $length If length is larger than the maximum line length, all lines will be padded up to the |
||
128 | * given length. If length is null, the maximum of all line lengths is used. Optional, |
||
129 | * defaults to null. |
||
130 | * @param string $padding Optional, defaults to a space character. Can be more than one character. The padding |
||
131 | * may be truncated if the required number of padding characters can't be evenly |
||
132 | * divided. |
||
133 | * @param int $paddingType Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. |
||
134 | * Defaults to STR_PAD_RIGHT. |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | public function pad($length = null, $padding = ' ', $paddingType = STR_PAD_RIGHT) |
||
148 | |||
149 | /** |
||
150 | * getLineIndexByCharacterPosition returns the line index containing a certain position. |
||
151 | * |
||
152 | * @param int $characterPosition Position of a character as if Multiline was a raw string. |
||
153 | * |
||
154 | * @return int|null The array index of the line containing the character position. |
||
155 | */ |
||
156 | public function getLineIndexByCharacterPosition($characterPosition) |
||
168 | } |
||
169 |