1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yii\jquery\validators\client; |
9
|
|
|
|
10
|
|
|
use yii\jquery\ValidationAsset; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* ImageValidator composes client-side validation code from [[\yii\validators\ImageValidator]]. |
14
|
|
|
* |
15
|
|
|
* @see \yii\validators\ImageValidator |
16
|
|
|
* @see ValidationAsset |
17
|
|
|
* |
18
|
|
|
* @author Paul Klimov <[email protected]> |
19
|
|
|
* @since 2.1.0 |
20
|
|
|
*/ |
21
|
|
|
class ImageValidator extends FileValidator |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
public function build($validator, $model, $attribute, $view) |
27
|
|
|
{ |
28
|
|
|
ValidationAsset::register($view); |
29
|
|
|
$options = $this->getClientOptions($validator, $model, $attribute); |
|
|
|
|
30
|
|
|
return 'yii.validation.image(attribute, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ', deferred);'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns the client-side validation options. |
35
|
|
|
* @param \yii\validators\ImageValidator $validator the server-side validator. |
36
|
|
|
* @param \yii\base\Model $model the model being validated |
37
|
|
|
* @param string $attribute the attribute name being validated |
38
|
|
|
* @return array the client-side validation options |
39
|
|
|
*/ |
40
|
|
|
public function getClientOptions($validator, $model, $attribute) |
41
|
|
|
{ |
42
|
|
|
$options = parent::getClientOptions($validator, $model, $attribute); |
43
|
|
|
|
44
|
|
|
$label = $model->getAttributeLabel($attribute); |
45
|
|
|
|
46
|
|
|
if ($validator->notImage !== null) { |
47
|
|
|
$options['notImage'] = $validator->formatMessage($validator->notImage, [ |
48
|
|
|
'attribute' => $label, |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($validator->minWidth !== null) { |
53
|
|
|
$options['minWidth'] = $validator->minWidth; |
54
|
|
|
$options['underWidth'] = $validator->formatMessage($validator->underWidth, [ |
55
|
|
|
'attribute' => $label, |
56
|
|
|
'limit' => $validator->minWidth, |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($validator->maxWidth !== null) { |
61
|
|
|
$options['maxWidth'] = $validator->maxWidth; |
62
|
|
|
$options['overWidth'] = $validator->formatMessage($validator->overWidth, [ |
63
|
|
|
'attribute' => $label, |
64
|
|
|
'limit' => $validator->maxWidth, |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if ($validator->minHeight !== null) { |
69
|
|
|
$options['minHeight'] = $validator->minHeight; |
70
|
|
|
$options['underHeight'] = $validator->formatMessage($validator->underHeight, [ |
71
|
|
|
'attribute' => $label, |
72
|
|
|
'limit' => $validator->minHeight, |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if ($validator->maxHeight !== null) { |
77
|
|
|
$options['maxHeight'] = $validator->maxHeight; |
78
|
|
|
$options['overHeight'] = $validator->formatMessage($validator->overHeight, [ |
79
|
|
|
'attribute' => $label, |
80
|
|
|
'limit' => $validator->maxHeight, |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $options; |
85
|
|
|
} |
86
|
|
|
} |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.