Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
d13d274d
Commit
d13d274d
authored
Oct 31, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed $object to $model
parent
a0bd2033
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
100 additions
and
100 deletions
+100
-100
BooleanValidator.php
framework/validators/BooleanValidator.php
+2
-2
CompareValidator.php
framework/validators/CompareValidator.php
+10
-10
DateValidator.php
framework/validators/DateValidator.php
+4
-4
DefaultValueValidator.php
framework/validators/DefaultValueValidator.php
+4
-4
EmailValidator.php
framework/validators/EmailValidator.php
+2
-2
ExistValidator.php
framework/validators/ExistValidator.php
+9
-9
FileValidator.php
framework/validators/FileValidator.php
+14
-14
FilterValidator.php
framework/validators/FilterValidator.php
+3
-3
ImageValidator.php
framework/validators/ImageValidator.php
+5
-5
InlineValidator.php
framework/validators/InlineValidator.php
+4
-4
NumberValidator.php
framework/validators/NumberValidator.php
+8
-8
RangeValidator.php
framework/validators/RangeValidator.php
+2
-2
RegularExpressionValidator.php
framework/validators/RegularExpressionValidator.php
+2
-2
RequiredValidator.php
framework/validators/RequiredValidator.php
+2
-2
SafeValidator.php
framework/validators/SafeValidator.php
+1
-1
StringValidator.php
framework/validators/StringValidator.php
+8
-8
UniqueValidator.php
framework/validators/UniqueValidator.php
+14
-14
UrlValidator.php
framework/validators/UrlValidator.php
+6
-6
No files found.
framework/validators/BooleanValidator.php
View file @
d13d274d
...
...
@@ -67,13 +67,13 @@ class BooleanValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$options
=
[
'trueValue'
=>
$this
->
trueValue
,
'falseValue'
=>
$this
->
falseValue
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
'true'
=>
$this
->
trueValue
,
'false'
=>
$this
->
falseValue
,
],
Yii
::
$app
->
language
),
...
...
framework/validators/CompareValidator.php
View file @
d13d274d
...
...
@@ -117,11 +117,11 @@ class CompareValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
is_array
(
$value
))
{
$this
->
addError
(
$
object
,
$attribute
,
Yii
::
t
(
'yii'
,
'{attribute} is invalid.'
));
$this
->
addError
(
$
model
,
$attribute
,
Yii
::
t
(
'yii'
,
'{attribute} is invalid.'
));
return
;
}
...
...
@@ -129,12 +129,12 @@ class CompareValidator extends Validator
$compareLabel
=
$compareValue
=
$this
->
compareValue
;
}
else
{
$compareAttribute
=
$this
->
compareAttribute
===
null
?
$attribute
.
'_repeat'
:
$this
->
compareAttribute
;
$compareValue
=
$
object
->
$compareAttribute
;
$compareLabel
=
$
object
->
getAttributeLabel
(
$compareAttribute
);
$compareValue
=
$
model
->
$compareAttribute
;
$compareLabel
=
$
model
->
getAttributeLabel
(
$compareAttribute
);
}
if
(
!
$this
->
compareValues
(
$this
->
operator
,
$this
->
type
,
$value
,
$compareValue
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
,
[
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
,
[
'compareAttribute'
=>
$compareLabel
,
'compareValue'
=>
$compareValue
,
]);
...
...
@@ -201,7 +201,7 @@ class CompareValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$options
=
[
'operator'
=>
$this
->
operator
,
...
...
@@ -213,8 +213,8 @@ class CompareValidator extends Validator
$compareValue
=
$this
->
compareValue
;
}
else
{
$compareAttribute
=
$this
->
compareAttribute
===
null
?
$attribute
.
'_repeat'
:
$this
->
compareAttribute
;
$compareValue
=
$
object
->
getAttributeLabel
(
$compareAttribute
);
$options
[
'compareAttribute'
]
=
Html
::
getInputId
(
$
object
,
$compareAttribute
);
$compareValue
=
$
model
->
getAttributeLabel
(
$compareAttribute
);
$options
[
'compareAttribute'
]
=
Html
::
getInputId
(
$
model
,
$compareAttribute
);
}
if
(
$this
->
skipOnEmpty
)
{
...
...
@@ -222,7 +222,7 @@ class CompareValidator extends Validator
}
$options
[
'message'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
'compareAttribute'
=>
$compareValue
,
'compareValue'
=>
$compareValue
,
],
Yii
::
$app
->
language
);
...
...
framework/validators/DateValidator.php
View file @
d13d274d
...
...
@@ -94,14 +94,14 @@ class DateValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
$timestamp
=
$this
->
parseDateValue
(
$value
);
if
(
$timestamp
===
false
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
,
[]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
,
[]);
}
elseif
(
$this
->
timestampAttribute
!==
null
)
{
$
object
->
{
$this
->
timestampAttribute
}
=
$timestamp
;
$
model
->
{
$this
->
timestampAttribute
}
=
$timestamp
;
}
}
...
...
framework/validators/DefaultValueValidator.php
View file @
d13d274d
...
...
@@ -41,13 +41,13 @@ class DefaultValueValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
if
(
$this
->
isEmpty
(
$
object
->
$attribute
))
{
if
(
$this
->
isEmpty
(
$
model
->
$attribute
))
{
if
(
$this
->
value
instanceof
\Closure
)
{
$
object
->
$attribute
=
call_user_func
(
$this
->
value
,
$object
,
$attribute
);
$
model
->
$attribute
=
call_user_func
(
$this
->
value
,
$model
,
$attribute
);
}
else
{
$
object
->
$attribute
=
$this
->
value
;
$
model
->
$attribute
=
$this
->
value
;
}
}
}
...
...
framework/validators/EmailValidator.php
View file @
d13d274d
...
...
@@ -92,14 +92,14 @@ class EmailValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$options
=
[
'pattern'
=>
new
JsExpression
(
$this
->
pattern
),
'fullPattern'
=>
new
JsExpression
(
$this
->
fullPattern
),
'allowName'
=>
$this
->
allowName
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
'enableIDN'
=>
(
boolean
)
$this
->
enableIDN
,
];
...
...
framework/validators/ExistValidator.php
View file @
d13d274d
...
...
@@ -81,7 +81,7 @@ class ExistValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$targetAttribute
=
$this
->
targetAttribute
===
null
?
$attribute
:
$this
->
targetAttribute
;
...
...
@@ -91,31 +91,31 @@ class ExistValidator extends Validator
}
$params
=
[];
foreach
(
$targetAttribute
as
$k
=>
$v
)
{
$params
[
$v
]
=
is_integer
(
$k
)
?
$
object
->
$v
:
$object
->
$k
;
$params
[
$v
]
=
is_integer
(
$k
)
?
$
model
->
$v
:
$model
->
$k
;
}
}
else
{
$params
=
[
$targetAttribute
=>
$
object
->
$attribute
];
$params
=
[
$targetAttribute
=>
$
model
->
$attribute
];
}
if
(
!
$this
->
allowArray
)
{
foreach
(
$params
as
$value
)
{
if
(
is_array
(
$value
))
{
$this
->
addError
(
$
object
,
$attribute
,
Yii
::
t
(
'yii'
,
'{attribute} is invalid.'
));
$this
->
addError
(
$
model
,
$attribute
,
Yii
::
t
(
'yii'
,
'{attribute} is invalid.'
));
return
;
}
}
}
$targetClass
=
$this
->
targetClass
===
null
?
get_class
(
$
object
)
:
$this
->
targetClass
;
$targetClass
=
$this
->
targetClass
===
null
?
get_class
(
$
model
)
:
$this
->
targetClass
;
$query
=
$this
->
createQuery
(
$targetClass
,
$params
);
if
(
is_array
(
$
object
->
$attribute
))
{
if
(
$query
->
count
(
"DISTINCT [[
$targetAttribute
]]"
)
!=
count
(
$
object
->
$attribute
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
if
(
is_array
(
$
model
->
$attribute
))
{
if
(
$query
->
count
(
"DISTINCT [[
$targetAttribute
]]"
)
!=
count
(
$
model
->
$attribute
))
{
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
}
}
elseif
(
!
$query
->
exists
())
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
}
}
...
...
framework/validators/FileValidator.php
View file @
d13d274d
...
...
@@ -166,12 +166,12 @@ class FileValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
if
(
$this
->
maxFiles
>
1
)
{
$files
=
$
object
->
$attribute
;
$files
=
$
model
->
$attribute
;
if
(
!
is_array
(
$files
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
uploadRequired
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
uploadRequired
);
return
;
}
...
...
@@ -180,24 +180,24 @@ class FileValidator extends Validator
unset
(
$files
[
$i
]);
}
}
$
object
->
$attribute
=
array_values
(
$files
);
$
model
->
$attribute
=
array_values
(
$files
);
if
(
empty
(
$files
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
uploadRequired
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
uploadRequired
);
}
if
(
count
(
$files
)
>
$this
->
maxFiles
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
tooMany
,
[
'limit'
=>
$this
->
maxFiles
]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
tooMany
,
[
'limit'
=>
$this
->
maxFiles
]);
}
else
{
foreach
(
$files
as
$file
)
{
$result
=
$this
->
validateValue
(
$file
);
if
(
!
empty
(
$result
))
{
$this
->
addError
(
$
object
,
$attribute
,
$result
[
0
],
$result
[
1
]);
$this
->
addError
(
$
model
,
$attribute
,
$result
[
0
],
$result
[
1
]);
}
}
}
}
else
{
$result
=
$this
->
validateValue
(
$
object
->
$attribute
);
$result
=
$this
->
validateValue
(
$
model
->
$attribute
);
if
(
!
empty
(
$result
))
{
$this
->
addError
(
$
object
,
$attribute
,
$result
[
0
],
$result
[
1
]);
$this
->
addError
(
$
model
,
$attribute
,
$result
[
0
],
$result
[
1
]);
}
}
}
...
...
@@ -334,22 +334,22 @@ class FileValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
ValidationAsset
::
register
(
$view
);
$options
=
$this
->
getClientOptions
(
$
object
,
$attribute
);
$options
=
$this
->
getClientOptions
(
$
model
,
$attribute
);
return
'yii.validation.file(attribute, messages, '
.
json_encode
(
$options
,
JSON_UNESCAPED_SLASHES
|
JSON_UNESCAPED_UNICODE
)
.
');'
;
}
/**
* Returns the client side validation options.
* @param \yii\base\Model $
object
the model being validated
* @param \yii\base\Model $
model
the model being validated
* @param string $attribute the attribute name being validated
* @return array the client side validation options
*/
protected
function
getClientOptions
(
$
object
,
$attribute
)
protected
function
getClientOptions
(
$
model
,
$attribute
)
{
$label
=
$
object
->
getAttributeLabel
(
$attribute
);
$label
=
$
model
->
getAttributeLabel
(
$attribute
);
$options
=
[];
if
(
$this
->
message
!==
null
)
{
...
...
framework/validators/FilterValidator.php
View file @
d13d274d
...
...
@@ -65,11 +65,11 @@ class FilterValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
!
$this
->
skipOnArray
||
!
is_array
(
$value
))
{
$
object
->
$attribute
=
call_user_func
(
$this
->
filter
,
$value
);
$
model
->
$attribute
=
call_user_func
(
$this
->
filter
,
$value
);
}
}
}
framework/validators/ImageValidator.php
View file @
d13d274d
...
...
@@ -162,21 +162,21 @@ class ImageValidator extends FileValidator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
ValidationAsset
::
register
(
$view
);
$options
=
$this
->
getClientOptions
(
$
object
,
$attribute
);
$options
=
$this
->
getClientOptions
(
$
model
,
$attribute
);
return
'yii.validation.image(attribute, messages, '
.
json_encode
(
$options
,
JSON_UNESCAPED_SLASHES
|
JSON_UNESCAPED_UNICODE
)
.
', deferred);'
;
}
/**
* @inheritdoc
*/
protected
function
getClientOptions
(
$
object
,
$attribute
)
protected
function
getClientOptions
(
$
model
,
$attribute
)
{
$options
=
parent
::
getClientOptions
(
$
object
,
$attribute
);
$options
=
parent
::
getClientOptions
(
$
model
,
$attribute
);
$label
=
$
object
->
getAttributeLabel
(
$attribute
);
$label
=
$
model
->
getAttributeLabel
(
$attribute
);
if
(
$this
->
notImage
!==
null
)
{
$options
[
'notImage'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
notImage
,
[
...
...
framework/validators/InlineValidator.php
View file @
d13d274d
...
...
@@ -58,11 +58,11 @@ class InlineValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$method
=
$this
->
method
;
if
(
is_string
(
$method
))
{
$method
=
[
$
object
,
$method
];
$method
=
[
$
model
,
$method
];
}
call_user_func
(
$method
,
$attribute
,
$this
->
params
);
}
...
...
@@ -70,12 +70,12 @@ class InlineValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
if
(
$this
->
clientValidate
!==
null
)
{
$method
=
$this
->
clientValidate
;
if
(
is_string
(
$method
))
{
$method
=
[
$
object
,
$method
];
$method
=
[
$
model
,
$method
];
}
return
call_user_func
(
$method
,
$attribute
,
$this
->
params
);
...
...
framework/validators/NumberValidator.php
View file @
d13d274d
...
...
@@ -75,22 +75,22 @@ class NumberValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
is_array
(
$value
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
return
;
}
$pattern
=
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
;
if
(
!
preg_match
(
$pattern
,
"
$value
"
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
}
if
(
$this
->
min
!==
null
&&
$value
<
$this
->
min
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
tooSmall
,
[
'min'
=>
$this
->
min
]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
tooSmall
,
[
'min'
=>
$this
->
min
]);
}
if
(
$this
->
max
!==
null
&&
$value
>
$this
->
max
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
tooBig
,
[
'max'
=>
$this
->
max
]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
tooBig
,
[
'max'
=>
$this
->
max
]);
}
}
...
...
@@ -117,9 +117,9 @@ class NumberValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$label
=
$
object
->
getAttributeLabel
(
$attribute
);
$label
=
$
model
->
getAttributeLabel
(
$attribute
);
$options
=
[
'pattern'
=>
new
JsExpression
(
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
),
...
...
framework/validators/RangeValidator.php
View file @
d13d274d
...
...
@@ -79,7 +79,7 @@ class RangeValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$range
=
[];
foreach
(
$this
->
range
as
$value
)
{
...
...
@@ -89,7 +89,7 @@ class RangeValidator extends Validator
'range'
=>
$range
,
'not'
=>
$this
->
not
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
];
if
(
$this
->
skipOnEmpty
)
{
...
...
framework/validators/RegularExpressionValidator.php
View file @
d13d274d
...
...
@@ -62,7 +62,7 @@ class RegularExpressionValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$pattern
=
$this
->
pattern
;
$pattern
=
preg_replace
(
'/\\\\x\{?([0-9a-fA-F]+)\}?/'
,
'\u$1'
,
$pattern
);
...
...
@@ -82,7 +82,7 @@ class RegularExpressionValidator extends Validator
'pattern'
=>
new
JsExpression
(
$pattern
),
'not'
=>
$this
->
not
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
];
if
(
$this
->
skipOnEmpty
)
{
...
...
framework/validators/RequiredValidator.php
View file @
d13d274d
...
...
@@ -86,7 +86,7 @@ class RequiredValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$options
=
[];
if
(
$this
->
requiredValue
!==
null
)
{
...
...
@@ -102,7 +102,7 @@ class RequiredValidator extends Validator
}
$options
[
'message'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$options
[
'message'
],
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
);
ValidationAsset
::
register
(
$view
);
...
...
framework/validators/SafeValidator.php
View file @
d13d274d
...
...
@@ -18,7 +18,7 @@ class SafeValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
}
}
framework/validators/StringValidator.php
View file @
d13d274d
...
...
@@ -96,12 +96,12 @@ class StringValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
!
is_string
(
$value
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
return
;
}
...
...
@@ -109,13 +109,13 @@ class StringValidator extends Validator
$length
=
mb_strlen
(
$value
,
$this
->
encoding
);
if
(
$this
->
min
!==
null
&&
$length
<
$this
->
min
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
tooShort
,
[
'min'
=>
$this
->
min
]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
tooShort
,
[
'min'
=>
$this
->
min
]);
}
if
(
$this
->
max
!==
null
&&
$length
>
$this
->
max
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
tooLong
,
[
'max'
=>
$this
->
max
]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
tooLong
,
[
'max'
=>
$this
->
max
]);
}
if
(
$this
->
length
!==
null
&&
$length
!==
$this
->
length
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
notEqual
,
[
'length'
=>
$this
->
length
]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
notEqual
,
[
'length'
=>
$this
->
length
]);
}
}
...
...
@@ -146,9 +146,9 @@ class StringValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
$label
=
$
object
->
getAttributeLabel
(
$attribute
);
$label
=
$
model
->
getAttributeLabel
(
$attribute
);
$options
=
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
...
...
framework/validators/UniqueValidator.php
View file @
d13d274d
...
...
@@ -74,24 +74,24 @@ class UniqueValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
/* @var $targetClass ActiveRecordInterface */
$targetClass
=
$this
->
targetClass
===
null
?
get_class
(
$
object
)
:
$this
->
targetClass
;
$targetClass
=
$this
->
targetClass
===
null
?
get_class
(
$
model
)
:
$this
->
targetClass
;
$targetAttribute
=
$this
->
targetAttribute
===
null
?
$attribute
:
$this
->
targetAttribute
;
if
(
is_array
(
$targetAttribute
))
{
$params
=
[];
foreach
(
$targetAttribute
as
$k
=>
$v
)
{
$params
[
$v
]
=
is_integer
(
$k
)
?
$
object
->
$v
:
$object
->
$k
;
$params
[
$v
]
=
is_integer
(
$k
)
?
$
model
->
$v
:
$model
->
$k
;
}
}
else
{
$params
=
[
$targetAttribute
=>
$
object
->
$attribute
];
$params
=
[
$targetAttribute
=>
$
model
->
$attribute
];
}
foreach
(
$params
as
$value
)
{
if
(
is_array
(
$value
))
{
$this
->
addError
(
$
object
,
$attribute
,
Yii
::
t
(
'yii'
,
'{attribute} is invalid.'
));
$this
->
addError
(
$
model
,
$attribute
,
Yii
::
t
(
'yii'
,
'{attribute} is invalid.'
));
return
;
}
...
...
@@ -106,14 +106,14 @@ class UniqueValidator extends Validator
$query
->
andWhere
(
$this
->
filter
);
}
if
(
!
$
object
instanceof
ActiveRecordInterface
||
$object
->
getIsNewRecord
())
{
// if current $
object
isn't in the database yet then it's OK just to call exists()
if
(
!
$
model
instanceof
ActiveRecordInterface
||
$model
->
getIsNewRecord
())
{
// if current $
model
isn't in the database yet then it's OK just to call exists()
$exists
=
$query
->
exists
();
}
else
{
// if current $
object
is in the database already we can't use exists()
/* @var $
object
s ActiveRecordInterface[] */
$
object
s
=
$query
->
limit
(
2
)
->
all
();
$n
=
count
(
$
object
s
);
// if current $
model
is in the database already we can't use exists()
/* @var $
model
s ActiveRecordInterface[] */
$
model
s
=
$query
->
limit
(
2
)
->
all
();
$n
=
count
(
$
model
s
);
if
(
$n
===
1
)
{
$keys
=
array_keys
(
$params
);
$pks
=
$targetClass
::
primaryKey
();
...
...
@@ -121,10 +121,10 @@ class UniqueValidator extends Validator
sort
(
$pks
);
if
(
$keys
===
$pks
)
{
// primary key is modified and not unique
$exists
=
$
object
->
getOldPrimaryKey
()
!=
$object
->
getPrimaryKey
();
$exists
=
$
model
->
getOldPrimaryKey
()
!=
$model
->
getPrimaryKey
();
}
else
{
// non-primary key, need to exclude the current record based on PK
$exists
=
$
objects
[
0
]
->
getPrimaryKey
()
!=
$object
->
getOldPrimaryKey
();
$exists
=
$
models
[
0
]
->
getPrimaryKey
()
!=
$model
->
getOldPrimaryKey
();
}
}
else
{
$exists
=
$n
>
1
;
...
...
@@ -132,7 +132,7 @@ class UniqueValidator extends Validator
}
if
(
$exists
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
}
}
}
framework/validators/UrlValidator.php
View file @
d13d274d
...
...
@@ -66,14 +66,14 @@ class UrlValidator extends Validator
/**
* @inheritdoc
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
$result
=
$this
->
validateValue
(
$value
);
if
(
!
empty
(
$result
))
{
$this
->
addError
(
$
object
,
$attribute
,
$result
[
0
],
$result
[
1
]);
$this
->
addError
(
$
model
,
$attribute
,
$result
[
0
],
$result
[
1
]);
}
elseif
(
$this
->
defaultScheme
!==
null
&&
strpos
(
$value
,
'://'
)
===
false
)
{
$
object
->
$attribute
=
$this
->
defaultScheme
.
'://'
.
$value
;
$
model
->
$attribute
=
$this
->
defaultScheme
.
'://'
.
$value
;
}
}
...
...
@@ -111,7 +111,7 @@ class UrlValidator extends Validator
/**
* @inheritdoc
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
if
(
strpos
(
$this
->
pattern
,
'{schemes}'
)
!==
false
)
{
$pattern
=
str_replace
(
'{schemes}'
,
'('
.
implode
(
'|'
,
$this
->
validSchemes
)
.
')'
,
$this
->
pattern
);
...
...
@@ -122,7 +122,7 @@ class UrlValidator extends Validator
$options
=
[
'pattern'
=>
new
JsExpression
(
$pattern
),
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
'enableIDN'
=>
(
boolean
)
$this
->
enableIDN
,
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment