1 | <?php |
||
50 | class ClassifyIpAddrLine |
||
51 | { |
||
52 | const LINK_START = 1; |
||
53 | const LINK_ETHER = 2; |
||
54 | const LINK_LOOPBACK = 3; |
||
55 | const LINK_NONE = 4; |
||
56 | const INET_START = 50; |
||
57 | const INET6_START = 51; |
||
58 | const INET_OPTIONS = 52; |
||
59 | const TEST_NEVER_SUPPORTED = 100; |
||
60 | |||
61 | /** |
||
62 | * a list of regexes to use to classify an address line |
||
63 | * @var array |
||
64 | */ |
||
65 | private static $typeMap = [ |
||
66 | '|^\d+:|' => self::LINK_START, |
||
67 | '|link/ether|' => self::LINK_ETHER, |
||
68 | '|link/loopback|' => self::LINK_LOOPBACK, |
||
69 | '|link/none|' => self::LINK_NONE, |
||
70 | '|^\s{0,}inet [0-9{1,3}\.]+/|' => self::INET_START, |
||
71 | '|^\s{0,}inet6 [0-9a-f:]+/|' => self::INET6_START, |
||
72 | '|^\s{0,}valid_lft |' => self::INET_OPTIONS, |
||
73 | '|TEST LINE, NEVER SUPPORTED|' => self::TEST_NEVER_SUPPORTED, |
||
74 | ]; |
||
75 | |||
76 | /** |
||
77 | * given a single line from the output of the 'ip addr show' or 'ip link show' |
||
78 | * commands, tell us what kind of line we are looking at |
||
79 | * |
||
80 | * @param string $line |
||
81 | * the line to classify |
||
82 | * @return int |
||
83 | * one of this class's constants |
||
84 | */ |
||
85 | public function __invoke($line) |
||
89 | |||
90 | /** |
||
91 | * given a single line from the output of the 'ip addr show' or 'ip link show' |
||
92 | * commands, tell us what kind of line we are looking at |
||
93 | * |
||
94 | * @param string $line |
||
95 | * the line to classify |
||
96 | * @return int |
||
97 | * one of this class's constants |
||
98 | */ |
||
99 | public static function from($line) |
||
115 | } |
||
116 |