2323 */
2424class MacAddressValidator extends ConstraintValidator
2525{
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-
5326 public function validate (mixed $ value , Constraint $ constraint ): void
5427 {
5528 if (!$ constraint instanceof MacAddress) {
@@ -78,6 +51,33 @@ public function validate(mixed $value, Constraint $constraint): void
7851 }
7952 }
8053
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+
8181 /**
8282 * Checks whether a MAC address is unicast or multicast.
8383 */
@@ -90,7 +90,7 @@ private static function isUnicast(string $mac): bool
9090 }
9191
9292 /**
93- * Checks whether an MAC address is local or universal.
93+ * Checks whether a MAC address is local or universal.
9494 */
9595 private static function isLocal (string $ mac ): bool
9696 {
@@ -101,7 +101,7 @@ private static function isLocal(string $mac): bool
101101 }
102102
103103 /**
104- * Checks whether an MAC address is broadcast.
104+ * Checks whether a MAC address is broadcast.
105105 */
106106 private static function isBroadcast (string $ mac ): bool
107107 {
0 commit comments