|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @link https://github.com/vuongxuongminh/symfony-validation |
| 4 | + * @copyright Copyright (c) 2019 Vuong Xuong Minh |
| 5 | + * @license [MIT](http://www.opensource.org/licenses/MIT) |
| 6 | + */ |
| 7 | + |
| 8 | +namespace PHPViet\Symfony\Validation\Constraints; |
| 9 | + |
| 10 | +use Symfony\Component\Validator\Constraint; |
| 11 | +use PHPViet\Validation\Rules\IpVN as BaseIpVN; |
| 12 | + |
| 13 | +/** |
| 14 | + * @author Vuong Minh <vuongxuongminh@gmail.com> |
| 15 | + * @since 1.0.0 |
| 16 | + */ |
| 17 | +class IpVN extends Constraint |
| 18 | +{ |
| 19 | + const IPV4 = BaseIpVN::IPV4; |
| 20 | + |
| 21 | + const IPV6 = BaseIpVN::IPV6; |
| 22 | + |
| 23 | + const IP_VN_ERROR = 'a21abd13-9fc6-4319-a07a-9dfdc0b33719'; |
| 24 | + |
| 25 | + const IPV4_VN_ERROR = '6b162d27-d99e-4c4c-aadd-179a8b37ebc8'; |
| 26 | + |
| 27 | + const IPV6_VN_ERROR = '1c417ab3-734c-4694-a52e-af4bcfc8dd4f'; |
| 28 | + |
| 29 | + protected static $errorNames = [ |
| 30 | + self::IP_VN_ERROR => 'IP_VN_ERROR', |
| 31 | + self::IPV4_VN_ERROR => 'IPV4_VN_ERROR', |
| 32 | + self::IPV6_VN_ERROR => 'IPV6_VN_ERROR', |
| 33 | + ]; |
| 34 | + |
| 35 | + public $message; |
| 36 | + |
| 37 | + public $version; |
| 38 | + |
| 39 | + public function __construct($options = null) |
| 40 | + { |
| 41 | + parent::__construct($options); |
| 42 | + |
| 43 | + if (null === $this->message) { |
| 44 | + switch ($this->version) { |
| 45 | + case self::IPV4: |
| 46 | + $this->message = 'This is not a valid Vietnam ipv4.'; |
| 47 | + break; |
| 48 | + case self::IPV6: |
| 49 | + $this->message = 'This is not a valid Vietnam ipv6.'; |
| 50 | + break; |
| 51 | + default: |
| 52 | + $this->message = 'This is not a valid Vietnam ip.'; |
| 53 | + break; |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments