23
23
*/
24
24
class MacAddressValidator extends ConstraintValidator
25
25
{
26
- /**
27
- * Checks whether a MAC address is valid.
28
- */
29
- private static function checkMac (string $ mac , string $ type ): bool
30
- {
31
- if (!filter_var ($ mac , \FILTER_VALIDATE_MAC )) {
32
- return false ;
33
- }
34
-
35
- return match ($ type ) {
36
- MacAddress::ALL => true ,
37
- MacAddress::ALL_NO_BROADCAST => !self ::isBroadcast ($ mac ),
38
- MacAddress::LOCAL_ALL => self ::isLocal ($ mac ),
39
- MacAddress::LOCAL_NO_BROADCAST => self ::isLocal ($ mac ) && !self ::isBroadcast ($ mac ),
40
- MacAddress::LOCAL_UNICAST => self ::isLocal ($ mac ) && self ::isUnicast ($ mac ),
41
- MacAddress::LOCAL_MULTICAST => self ::isLocal ($ mac ) && !self ::isUnicast ($ mac ),
42
- MacAddress::LOCAL_MULTICAST_NO_BROADCAST => self ::isLocal ($ mac ) && !self ::isUnicast ($ mac ) && !self ::isBroadcast ($ mac ),
43
- MacAddress::UNIVERSAL_ALL => !self ::isLocal ($ mac ),
44
- MacAddress::UNIVERSAL_UNICAST => !self ::isLocal ($ mac ) && self ::isUnicast ($ mac ),
45
- MacAddress::UNIVERSAL_MULTICAST => !self ::isLocal ($ mac ) && !self ::isUnicast ($ mac ),
46
- MacAddress::UNICAST_ALL => self ::isUnicast ($ mac ),
47
- MacAddress::MULTICAST_ALL => !self ::isUnicast ($ mac ),
48
- MacAddress::MULTICAST_NO_BROADCAST => !self ::isUnicast ($ mac ) && !self ::isBroadcast ($ mac ),
49
- MacAddress::BROADCAST => self ::isBroadcast ($ mac ),
50
- };
51
- }
52
-
53
26
public function validate (mixed $ value , Constraint $ constraint ): void
54
27
{
55
28
if (!$ constraint instanceof MacAddress) {
@@ -78,6 +51,33 @@ public function validate(mixed $value, Constraint $constraint): void
78
51
}
79
52
}
80
53
54
+ /**
55
+ * Checks whether a MAC address is valid.
56
+ */
57
+ private static function checkMac (string $ mac , string $ type ): bool
58
+ {
59
+ if (!filter_var ($ mac , \FILTER_VALIDATE_MAC )) {
60
+ return false ;
61
+ }
62
+
63
+ return match ($ type ) {
64
+ MacAddress::ALL => true ,
65
+ MacAddress::ALL_NO_BROADCAST => !self ::isBroadcast ($ mac ),
66
+ MacAddress::LOCAL_ALL => self ::isLocal ($ mac ),
67
+ MacAddress::LOCAL_NO_BROADCAST => self ::isLocal ($ mac ) && !self ::isBroadcast ($ mac ),
68
+ MacAddress::LOCAL_UNICAST => self ::isLocal ($ mac ) && self ::isUnicast ($ mac ),
69
+ MacAddress::LOCAL_MULTICAST => self ::isLocal ($ mac ) && !self ::isUnicast ($ mac ),
70
+ MacAddress::LOCAL_MULTICAST_NO_BROADCAST => self ::isLocal ($ mac ) && !self ::isUnicast ($ mac ) && !self ::isBroadcast ($ mac ),
71
+ MacAddress::UNIVERSAL_ALL => !self ::isLocal ($ mac ),
72
+ MacAddress::UNIVERSAL_UNICAST => !self ::isLocal ($ mac ) && self ::isUnicast ($ mac ),
73
+ MacAddress::UNIVERSAL_MULTICAST => !self ::isLocal ($ mac ) && !self ::isUnicast ($ mac ),
74
+ MacAddress::UNICAST_ALL => self ::isUnicast ($ mac ),
75
+ MacAddress::MULTICAST_ALL => !self ::isUnicast ($ mac ),
76
+ MacAddress::MULTICAST_NO_BROADCAST => !self ::isUnicast ($ mac ) && !self ::isBroadcast ($ mac ),
77
+ MacAddress::BROADCAST => self ::isBroadcast ($ mac ),
78
+ };
79
+ }
80
+
81
81
/**
82
82
* Checks whether a MAC address is unicast or multicast.
83
83
*/
@@ -90,7 +90,7 @@ private static function isUnicast(string $mac): bool
90
90
}
91
91
92
92
/**
93
- * Checks whether an MAC address is local or universal.
93
+ * Checks whether a MAC address is local or universal.
94
94
*/
95
95
private static function isLocal (string $ mac ): bool
96
96
{
@@ -101,7 +101,7 @@ private static function isLocal(string $mac): bool
101
101
}
102
102
103
103
/**
104
- * Checks whether an MAC address is broadcast.
104
+ * Checks whether a MAC address is broadcast.
105
105
*/
106
106
private static function isBroadcast (string $ mac ): bool
107
107
{
0 commit comments