1 | <?php |
||
7 | final class Multiline extends ArrayCollection { |
||
8 | /** |
||
9 | * @var \nochso\Omni\EOL |
||
10 | */ |
||
11 | private $eol; |
||
12 | |||
13 | /** |
||
14 | * Create a new Multiline object from a string. |
||
15 | * |
||
16 | * First the input string is split into lines by the detected end-of-line |
||
17 | * character. Afterwards any extra EOL chars will be trimmed. |
||
18 | * |
||
19 | * @see \nochso\Omni\EOL |
||
20 | * |
||
21 | * @param string $input A string to split into a Multiline object |
||
22 | * @param string $defaultEol Default end-of-line type to split the input by. This is a fallback in case it could |
||
23 | * not be detected from the input string. Optional, defaults to `EOL::EOL_LF` i.e. "\n". |
||
24 | * See the `EOL::EOL_*` class constants. |
||
25 | * |
||
26 | * @return \nochso\Omni\Multiline |
||
27 | */ |
||
28 | public static function create($input, $defaultEol = \nochso\Omni\EOL::EOL_LF) { |
||
39 | |||
40 | /** |
||
41 | * __toString returns a single string using the current EOL style. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | public function __toString() { |
||
48 | |||
49 | /** |
||
50 | * Get EOL style ending. |
||
51 | * |
||
52 | * @return \nochso\Omni\EOL |
||
53 | */ |
||
54 | public function getEol() { |
||
57 | |||
58 | /** |
||
59 | * getMaxLength of all lines. |
||
60 | * |
||
61 | * @return int |
||
62 | */ |
||
63 | public function getMaxLength() { |
||
70 | |||
71 | /** |
||
72 | * Set EOL used by this Multiline string. |
||
73 | * |
||
74 | * @param \nochso\Omni\EOL|string $eol Either an `EOL` object or a string ("\r\n" or "\n") |
||
75 | * |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function setEol($eol) { |
||
85 | |||
86 | /** |
||
87 | * Append text to a certain line. |
||
88 | * |
||
89 | * @param string $text |
||
90 | * @param null|int $index Optional, defaults to the last line. Other |
||
91 | * |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function append($text, $index = null) { |
||
101 | |||
102 | /** |
||
103 | * Prefix all lines with a string. |
||
104 | * |
||
105 | * @param string $prefix The prefix to add to the start of the string. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | public function prefix($prefix) { |
||
115 | |||
116 | /** |
||
117 | * Pad all lines to the same length using `str_pad`. |
||
118 | * |
||
119 | * @param int $length If length is larger than the maximum line length, all lines will be padded up to the |
||
120 | * given length. If length is null, the maximum of all line lengths is used. Optional, |
||
121 | * defaults to null. |
||
122 | * @param string $padding Optional, defaults to a space character. Can be more than one character. The padding |
||
123 | * may be truncated if the required number of padding characters can't be evenly |
||
124 | * divided. |
||
125 | * @param int $paddingType Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. |
||
126 | * Defaults to STR_PAD_RIGHT. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function pad($length = null, $padding = ' ', $paddingType = STR_PAD_RIGHT) { |
||
139 | |||
140 | /** |
||
141 | * getLineIndexByCharacterPosition returns the line index containing a certain position. |
||
142 | * |
||
143 | * @param int $characterPosition Position of a character as if Multiline was a raw string. |
||
144 | * |
||
145 | * @return int|null The array index of the line containing the character position. |
||
146 | */ |
||
147 | public function getLineIndexByCharacterPosition($characterPosition) { |
||
158 | } |
||
159 |