1 | <?php |
||
56 | class ParseNetLink |
||
57 | { |
||
58 | /** |
||
59 | * extract a NetLink from the output of 'ip addr show' or 'ip link show' |
||
60 | * |
||
61 | * @param mixed $linkLines |
||
62 | * the output to parse |
||
63 | * @return NetLink |
||
64 | */ |
||
65 | public function __invoke($linkLines) |
||
69 | |||
70 | /** |
||
71 | * extract a NetLink from the output of 'ip addr show' or 'ip link show' |
||
72 | * |
||
73 | * @param mixed $linkLines |
||
74 | * the output to parse |
||
75 | * @return NetLink |
||
76 | */ |
||
77 | public static function from($linkLines) |
||
82 | |||
83 | /** |
||
84 | * extract a NetLink from the output of 'ip addr show' or 'ip link show' |
||
85 | * |
||
86 | * @param string $linkLines |
||
87 | * the output to parse |
||
88 | * @return NetLink |
||
89 | */ |
||
90 | private static function fromString($linkLines) |
||
95 | |||
96 | /** |
||
97 | * extract a NetLink from the output of 'ip addr show' or 'ip link show' |
||
98 | * |
||
99 | * @param mixed $linkLines |
||
100 | * the output to parse |
||
101 | * @return NetLink |
||
102 | */ |
||
103 | private static function fromTraversable($linkLines) |
||
135 | |||
136 | /** |
||
137 | * called when we have been given a data type that we do not support |
||
138 | * |
||
139 | * @param mixed $linkLines |
||
140 | * @return void |
||
141 | * @throws E4xx_UnsupportedType |
||
142 | */ |
||
143 | private static function nothingMatchesTheInputType($linkLines) |
||
147 | |||
148 | /** |
||
149 | * extract data from the first line of the link definition |
||
150 | * |
||
151 | * @param string $line |
||
152 | * the line to parse |
||
153 | * @return array |
||
154 | * the extracted data |
||
155 | */ |
||
156 | private static function parseFirstLine($line) |
||
187 | |||
188 | /** |
||
189 | * extract the master interface (if there is one) from the first line of |
||
190 | * the link definition |
||
191 | * |
||
192 | * @param array $matches |
||
193 | * the match results from running a regex against the first line |
||
194 | * of the link definition |
||
195 | * @return string|null |
||
196 | */ |
||
197 | private static function extractMasterFromMatches($matches) |
||
210 | |||
211 | /** |
||
212 | * convert the key/value pairs from the first line of the link definition |
||
213 | * into a list of key/value pairs |
||
214 | * |
||
215 | * @param array $matches |
||
216 | * the match results from running a regex against the first line |
||
217 | * of the link definition |
||
218 | * @return array |
||
219 | * the extracted key/value pairs |
||
220 | */ |
||
221 | private static function extractPropertiesFromMatches($matches) |
||
226 | |||
227 | /** |
||
228 | * convert the interface flags from the first line of the link definition |
||
229 | * into a list of flags that are set |
||
230 | * |
||
231 | * @param array $matches |
||
232 | * the match results from running a regex against the first line |
||
233 | * of the link definition |
||
234 | * @return array |
||
235 | * the extracted flags - the flag name is the key, and the value |
||
236 | * is always TRUE |
||
237 | */ |
||
238 | private static function extractFlagsFromMatches($matches) |
||
244 | |||
245 | /** |
||
246 | * extract the data from the second line of the link definition |
||
247 | * |
||
248 | * @param string $line |
||
249 | * the second line of the link definition |
||
250 | * @return array |
||
251 | * a list of the extracted link properties |
||
252 | */ |
||
253 | private static function parseSecondLine($line) |
||
277 | |||
278 | /** |
||
279 | * a map of how to handle supported data types |
||
280 | * |
||
281 | * @var array |
||
282 | */ |
||
283 | private static $dispatchMap = [ |
||
284 | 'String' => 'fromString', |
||
285 | 'Traversable' => 'fromTraversable', |
||
286 | ]; |
||
287 | } |
||
288 |