8
8
9
9
namespace phpviet \yii \validation \validators ;
10
10
11
+ use PHPViet \Validation \Rules \IpVN as ConcreteIpVN ;
12
+ use PHPViet \Validation \Validator as ConcreteValidator ;
11
13
use Yii ;
12
-
13
- use yii \validators \Validator ;
14
14
use yii \validators \IpValidator ;
15
-
16
- use PHPViet \Validation \Validator as ConcreteValidator ;
17
- use PHPViet \Validation \Rules \IpVN as ConcreteIpVN ;
15
+ use yii \validators \Validator ;
18
16
19
17
/**
20
18
* @author Vuong Minh <vuongxuongminh@gmail.com>
19
+ *
21
20
* @since 1.0.0
22
21
*/
23
22
class IpVNValidator extends Validator
24
23
{
25
-
26
24
const IPV4 = ConcreteIpVN::IPV4 ;
27
25
28
26
const IPV6 = ConcreteIpVN::IPV6 ;
@@ -33,7 +31,7 @@ class IpVNValidator extends Validator
33
31
public $ version ;
34
32
35
33
/**
36
- * @inheritDoc
34
+ * {@inheritdoc}
37
35
*/
38
36
public function init ()
39
37
{
@@ -43,20 +41,20 @@ public function init()
43
41
}
44
42
45
43
/**
46
- * @inheritDoc
44
+ * {@inheritdoc}
47
45
*/
48
46
public function validateValue ($ value )
49
47
{
50
48
if (ConcreteValidator::ipVN ($ this ->version )->validate ($ value )) {
51
-
52
- return null ;
49
+ return ;
53
50
}
54
51
55
52
return [$ this ->message , []];
56
53
}
57
54
58
55
/**
59
- * @inheritDoc
56
+ * {@inheritdoc}
57
+ *
60
58
* @throws \yii\base\InvalidConfigException
61
59
*/
62
60
public function clientValidateAttribute ($ model , $ attribute , $ view )
@@ -65,7 +63,8 @@ public function clientValidateAttribute($model, $attribute, $view)
65
63
}
66
64
67
65
/**
68
- * @inheritDoc
66
+ * {@inheritdoc}
67
+ *
69
68
* @throws \yii\base\InvalidConfigException
70
69
*/
71
70
public function getClientOptions ($ model , $ attribute )
@@ -74,7 +73,7 @@ public function getClientOptions($model, $attribute)
74
73
}
75
74
76
75
/**
77
- * @inheritDoc
76
+ * {@inheritdoc}
78
77
*/
79
78
protected function getDefaultMessage (): string
80
79
{
@@ -90,30 +89,31 @@ protected function getDefaultMessage(): string
90
89
91
90
/**
92
91
* @var IpValidator
92
+ *
93
93
* @see getClientIpValidator()
94
94
*/
95
95
private $ _clientIpValidator ;
96
96
97
97
/**
98
98
* Trả về [[IpValidator]] hổ trợ cho việc tạo js validator tại client.
99
99
*
100
- * @return IpValidator
101
100
* @throws \yii\base\InvalidConfigException
101
+ *
102
+ * @return IpValidator
102
103
*/
103
104
protected function getClientIpValidator (): IpValidator
104
105
{
105
106
if (null === $ this ->_clientIpValidator ) {
106
107
return $ this ->_clientIpValidator = Yii::createObject ([
107
- 'class ' => IpValidator::class,
108
- 'message ' => $ this ->message ,
108
+ 'class ' => IpValidator::class,
109
+ 'message ' => $ this ->message ,
109
110
'ipv4NotAllowed ' => $ this ->message ,
110
111
'ipv6NotAllowed ' => $ this ->message ,
111
- 'ipv4 ' => null === $ this ->version || self ::IPV4 === $ this ->version ,
112
- 'ipv6 ' => null === $ this ->version || self ::IPV6 === $ this ->version
112
+ 'ipv4 ' => null === $ this ->version || self ::IPV4 === $ this ->version ,
113
+ 'ipv6 ' => null === $ this ->version || self ::IPV6 === $ this ->version ,
113
114
]);
114
115
}
115
116
116
117
return $ this ->_clientIpValidator ;
117
118
}
118
-
119
119
}
0 commit comments