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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
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
...
@@ -67,13 +67,13 @@ class BooleanValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$options
=
[
$options
=
[
'trueValue'
=>
$this
->
trueValue
,
'trueValue'
=>
$this
->
trueValue
,
'falseValue'
=>
$this
->
falseValue
,
'falseValue'
=>
$this
->
falseValue
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
'true'
=>
$this
->
trueValue
,
'true'
=>
$this
->
trueValue
,
'false'
=>
$this
->
falseValue
,
'false'
=>
$this
->
falseValue
,
],
Yii
::
$app
->
language
),
],
Yii
::
$app
->
language
),
...
...
framework/validators/CompareValidator.php
View file @
d13d274d
...
@@ -117,11 +117,11 @@ class CompareValidator extends Validator
...
@@ -117,11 +117,11 @@ class CompareValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
is_array
(
$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
;
return
;
}
}
...
@@ -129,12 +129,12 @@ class CompareValidator extends Validator
...
@@ -129,12 +129,12 @@ class CompareValidator extends Validator
$compareLabel
=
$compareValue
=
$this
->
compareValue
;
$compareLabel
=
$compareValue
=
$this
->
compareValue
;
}
else
{
}
else
{
$compareAttribute
=
$this
->
compareAttribute
===
null
?
$attribute
.
'_repeat'
:
$this
->
compareAttribute
;
$compareAttribute
=
$this
->
compareAttribute
===
null
?
$attribute
.
'_repeat'
:
$this
->
compareAttribute
;
$compareValue
=
$
object
->
$compareAttribute
;
$compareValue
=
$
model
->
$compareAttribute
;
$compareLabel
=
$
object
->
getAttributeLabel
(
$compareAttribute
);
$compareLabel
=
$
model
->
getAttributeLabel
(
$compareAttribute
);
}
}
if
(
!
$this
->
compareValues
(
$this
->
operator
,
$this
->
type
,
$value
,
$compareValue
))
{
if
(
!
$this
->
compareValues
(
$this
->
operator
,
$this
->
type
,
$value
,
$compareValue
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
,
[
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
,
[
'compareAttribute'
=>
$compareLabel
,
'compareAttribute'
=>
$compareLabel
,
'compareValue'
=>
$compareValue
,
'compareValue'
=>
$compareValue
,
]);
]);
...
@@ -201,7 +201,7 @@ class CompareValidator extends Validator
...
@@ -201,7 +201,7 @@ class CompareValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$options
=
[
$options
=
[
'operator'
=>
$this
->
operator
,
'operator'
=>
$this
->
operator
,
...
@@ -213,8 +213,8 @@ class CompareValidator extends Validator
...
@@ -213,8 +213,8 @@ class CompareValidator extends Validator
$compareValue
=
$this
->
compareValue
;
$compareValue
=
$this
->
compareValue
;
}
else
{
}
else
{
$compareAttribute
=
$this
->
compareAttribute
===
null
?
$attribute
.
'_repeat'
:
$this
->
compareAttribute
;
$compareAttribute
=
$this
->
compareAttribute
===
null
?
$attribute
.
'_repeat'
:
$this
->
compareAttribute
;
$compareValue
=
$
object
->
getAttributeLabel
(
$compareAttribute
);
$compareValue
=
$
model
->
getAttributeLabel
(
$compareAttribute
);
$options
[
'compareAttribute'
]
=
Html
::
getInputId
(
$
object
,
$compareAttribute
);
$options
[
'compareAttribute'
]
=
Html
::
getInputId
(
$
model
,
$compareAttribute
);
}
}
if
(
$this
->
skipOnEmpty
)
{
if
(
$this
->
skipOnEmpty
)
{
...
@@ -222,7 +222,7 @@ class CompareValidator extends Validator
...
@@ -222,7 +222,7 @@ class CompareValidator extends Validator
}
}
$options
[
'message'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
$options
[
'message'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
'compareAttribute'
=>
$compareValue
,
'compareAttribute'
=>
$compareValue
,
'compareValue'
=>
$compareValue
,
'compareValue'
=>
$compareValue
,
],
Yii
::
$app
->
language
);
],
Yii
::
$app
->
language
);
...
...
framework/validators/DateValidator.php
View file @
d13d274d
...
@@ -94,14 +94,14 @@ class DateValidator extends Validator
...
@@ -94,14 +94,14 @@ class DateValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
$timestamp
=
$this
->
parseDateValue
(
$value
);
$timestamp
=
$this
->
parseDateValue
(
$value
);
if
(
$timestamp
===
false
)
{
if
(
$timestamp
===
false
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
,
[]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
,
[]);
}
elseif
(
$this
->
timestampAttribute
!==
null
)
{
}
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
...
@@ -41,13 +41,13 @@ class DefaultValueValidator extends Validator
/**
/**
* @inheritdoc
* @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
)
{
if
(
$this
->
value
instanceof
\Closure
)
{
$
object
->
$attribute
=
call_user_func
(
$this
->
value
,
$object
,
$attribute
);
$
model
->
$attribute
=
call_user_func
(
$this
->
value
,
$model
,
$attribute
);
}
else
{
}
else
{
$
object
->
$attribute
=
$this
->
value
;
$
model
->
$attribute
=
$this
->
value
;
}
}
}
}
}
}
...
...
framework/validators/EmailValidator.php
View file @
d13d274d
...
@@ -92,14 +92,14 @@ class EmailValidator extends Validator
...
@@ -92,14 +92,14 @@ class EmailValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$options
=
[
$options
=
[
'pattern'
=>
new
JsExpression
(
$this
->
pattern
),
'pattern'
=>
new
JsExpression
(
$this
->
pattern
),
'fullPattern'
=>
new
JsExpression
(
$this
->
fullPattern
),
'fullPattern'
=>
new
JsExpression
(
$this
->
fullPattern
),
'allowName'
=>
$this
->
allowName
,
'allowName'
=>
$this
->
allowName
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
],
Yii
::
$app
->
language
),
'enableIDN'
=>
(
boolean
)
$this
->
enableIDN
,
'enableIDN'
=>
(
boolean
)
$this
->
enableIDN
,
];
];
...
...
framework/validators/ExistValidator.php
View file @
d13d274d
...
@@ -81,7 +81,7 @@ class ExistValidator extends Validator
...
@@ -81,7 +81,7 @@ class ExistValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$targetAttribute
=
$this
->
targetAttribute
===
null
?
$attribute
:
$this
->
targetAttribute
;
$targetAttribute
=
$this
->
targetAttribute
===
null
?
$attribute
:
$this
->
targetAttribute
;
...
@@ -91,31 +91,31 @@ class ExistValidator extends Validator
...
@@ -91,31 +91,31 @@ class ExistValidator extends Validator
}
}
$params
=
[];
$params
=
[];
foreach
(
$targetAttribute
as
$k
=>
$v
)
{
foreach
(
$targetAttribute
as
$k
=>
$v
)
{
$params
[
$v
]
=
is_integer
(
$k
)
?
$
object
->
$v
:
$object
->
$k
;
$params
[
$v
]
=
is_integer
(
$k
)
?
$
model
->
$v
:
$model
->
$k
;
}
}
}
else
{
}
else
{
$params
=
[
$targetAttribute
=>
$
object
->
$attribute
];
$params
=
[
$targetAttribute
=>
$
model
->
$attribute
];
}
}
if
(
!
$this
->
allowArray
)
{
if
(
!
$this
->
allowArray
)
{
foreach
(
$params
as
$value
)
{
foreach
(
$params
as
$value
)
{
if
(
is_array
(
$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
;
return
;
}
}
}
}
}
}
$targetClass
=
$this
->
targetClass
===
null
?
get_class
(
$
object
)
:
$this
->
targetClass
;
$targetClass
=
$this
->
targetClass
===
null
?
get_class
(
$
model
)
:
$this
->
targetClass
;
$query
=
$this
->
createQuery
(
$targetClass
,
$params
);
$query
=
$this
->
createQuery
(
$targetClass
,
$params
);
if
(
is_array
(
$
object
->
$attribute
))
{
if
(
is_array
(
$
model
->
$attribute
))
{
if
(
$query
->
count
(
"DISTINCT [[
$targetAttribute
]]"
)
!=
count
(
$
object
->
$attribute
))
{
if
(
$query
->
count
(
"DISTINCT [[
$targetAttribute
]]"
)
!=
count
(
$
model
->
$attribute
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
}
}
}
elseif
(
!
$query
->
exists
())
{
}
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
...
@@ -166,12 +166,12 @@ class FileValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
if
(
$this
->
maxFiles
>
1
)
{
if
(
$this
->
maxFiles
>
1
)
{
$files
=
$
object
->
$attribute
;
$files
=
$
model
->
$attribute
;
if
(
!
is_array
(
$files
))
{
if
(
!
is_array
(
$files
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
uploadRequired
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
uploadRequired
);
return
;
return
;
}
}
...
@@ -180,24 +180,24 @@ class FileValidator extends Validator
...
@@ -180,24 +180,24 @@ class FileValidator extends Validator
unset
(
$files
[
$i
]);
unset
(
$files
[
$i
]);
}
}
}
}
$
object
->
$attribute
=
array_values
(
$files
);
$
model
->
$attribute
=
array_values
(
$files
);
if
(
empty
(
$files
))
{
if
(
empty
(
$files
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
uploadRequired
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
uploadRequired
);
}
}
if
(
count
(
$files
)
>
$this
->
maxFiles
)
{
if
(
count
(
$files
)
>
$this
->
maxFiles
)
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
tooMany
,
[
'limit'
=>
$this
->
maxFiles
]);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
tooMany
,
[
'limit'
=>
$this
->
maxFiles
]);
}
else
{
}
else
{
foreach
(
$files
as
$file
)
{
foreach
(
$files
as
$file
)
{
$result
=
$this
->
validateValue
(
$file
);
$result
=
$this
->
validateValue
(
$file
);
if
(
!
empty
(
$result
))
{
if
(
!
empty
(
$result
))
{
$this
->
addError
(
$
object
,
$attribute
,
$result
[
0
],
$result
[
1
]);
$this
->
addError
(
$
model
,
$attribute
,
$result
[
0
],
$result
[
1
]);
}
}
}
}
}
}
}
else
{
}
else
{
$result
=
$this
->
validateValue
(
$
object
->
$attribute
);
$result
=
$this
->
validateValue
(
$
model
->
$attribute
);
if
(
!
empty
(
$result
))
{
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
...
@@ -334,22 +334,22 @@ class FileValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
ValidationAsset
::
register
(
$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
)
.
');'
;
return
'yii.validation.file(attribute, messages, '
.
json_encode
(
$options
,
JSON_UNESCAPED_SLASHES
|
JSON_UNESCAPED_UNICODE
)
.
');'
;
}
}
/**
/**
* Returns the client side validation options.
* 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
* @param string $attribute the attribute name being validated
* @return array the client side validation options
* @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
=
[];
$options
=
[];
if
(
$this
->
message
!==
null
)
{
if
(
$this
->
message
!==
null
)
{
...
...
framework/validators/FilterValidator.php
View file @
d13d274d
...
@@ -65,11 +65,11 @@ class FilterValidator extends Validator
...
@@ -65,11 +65,11 @@ class FilterValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
!
$this
->
skipOnArray
||
!
is_array
(
$value
))
{
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
...
@@ -162,21 +162,21 @@ class ImageValidator extends FileValidator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
ValidationAsset
::
register
(
$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);'
;
return
'yii.validation.image(attribute, messages, '
.
json_encode
(
$options
,
JSON_UNESCAPED_SLASHES
|
JSON_UNESCAPED_UNICODE
)
.
', deferred);'
;
}
}
/**
/**
* @inheritdoc
* @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
)
{
if
(
$this
->
notImage
!==
null
)
{
$options
[
'notImage'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
notImage
,
[
$options
[
'notImage'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
notImage
,
[
...
...
framework/validators/InlineValidator.php
View file @
d13d274d
...
@@ -58,11 +58,11 @@ class InlineValidator extends Validator
...
@@ -58,11 +58,11 @@ class InlineValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$method
=
$this
->
method
;
$method
=
$this
->
method
;
if
(
is_string
(
$method
))
{
if
(
is_string
(
$method
))
{
$method
=
[
$
object
,
$method
];
$method
=
[
$
model
,
$method
];
}
}
call_user_func
(
$method
,
$attribute
,
$this
->
params
);
call_user_func
(
$method
,
$attribute
,
$this
->
params
);
}
}
...
@@ -70,12 +70,12 @@ class InlineValidator extends Validator
...
@@ -70,12 +70,12 @@ class InlineValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
if
(
$this
->
clientValidate
!==
null
)
{
if
(
$this
->
clientValidate
!==
null
)
{
$method
=
$this
->
clientValidate
;
$method
=
$this
->
clientValidate
;
if
(
is_string
(
$method
))
{
if
(
is_string
(
$method
))
{
$method
=
[
$
object
,
$method
];
$method
=
[
$
model
,
$method
];
}
}
return
call_user_func
(
$method
,
$attribute
,
$this
->
params
);
return
call_user_func
(
$method
,
$attribute
,
$this
->
params
);
...
...
framework/validators/NumberValidator.php
View file @
d13d274d
...
@@ -75,22 +75,22 @@ class NumberValidator extends Validator
...
@@ -75,22 +75,22 @@ class NumberValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
is_array
(
$value
))
{
if
(
is_array
(
$value
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
return
;
return
;
}
}
$pattern
=
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
;
$pattern
=
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
;
if
(
!
preg_match
(
$pattern
,
"
$value
"
))
{
if
(
!
preg_match
(
$pattern
,
"
$value
"
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
}
}
if
(
$this
->
min
!==
null
&&
$value
<
$this
->
min
)
{
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
)
{
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
...
@@ -117,9 +117,9 @@ class NumberValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$label
=
$
object
->
getAttributeLabel
(
$attribute
);
$label
=
$
model
->
getAttributeLabel
(
$attribute
);
$options
=
[
$options
=
[
'pattern'
=>
new
JsExpression
(
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
),
'pattern'
=>
new
JsExpression
(
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
),
...
...
framework/validators/RangeValidator.php
View file @
d13d274d
...
@@ -79,7 +79,7 @@ class RangeValidator extends Validator
...
@@ -79,7 +79,7 @@ class RangeValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$range
=
[];
$range
=
[];
foreach
(
$this
->
range
as
$value
)
{
foreach
(
$this
->
range
as
$value
)
{
...
@@ -89,7 +89,7 @@ class RangeValidator extends Validator
...
@@ -89,7 +89,7 @@ class RangeValidator extends Validator
'range'
=>
$range
,
'range'
=>
$range
,
'not'
=>
$this
->
not
,
'not'
=>
$this
->
not
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
],
Yii
::
$app
->
language
),
];
];
if
(
$this
->
skipOnEmpty
)
{
if
(
$this
->
skipOnEmpty
)
{
...
...
framework/validators/RegularExpressionValidator.php
View file @
d13d274d
...
@@ -62,7 +62,7 @@ class RegularExpressionValidator extends Validator
...
@@ -62,7 +62,7 @@ class RegularExpressionValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$pattern
=
$this
->
pattern
;
$pattern
=
$this
->
pattern
;
$pattern
=
preg_replace
(
'/\\\\x\{?([0-9a-fA-F]+)\}?/'
,
'\u$1'
,
$pattern
);
$pattern
=
preg_replace
(
'/\\\\x\{?([0-9a-fA-F]+)\}?/'
,
'\u$1'
,
$pattern
);
...
@@ -82,7 +82,7 @@ class RegularExpressionValidator extends Validator
...
@@ -82,7 +82,7 @@ class RegularExpressionValidator extends Validator
'pattern'
=>
new
JsExpression
(
$pattern
),
'pattern'
=>
new
JsExpression
(
$pattern
),
'not'
=>
$this
->
not
,
'not'
=>
$this
->
not
,
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
],
Yii
::
$app
->
language
),
];
];
if
(
$this
->
skipOnEmpty
)
{
if
(
$this
->
skipOnEmpty
)
{
...
...
framework/validators/RequiredValidator.php
View file @
d13d274d
...
@@ -86,7 +86,7 @@ class RequiredValidator extends Validator
...
@@ -86,7 +86,7 @@ class RequiredValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$options
=
[];
$options
=
[];
if
(
$this
->
requiredValue
!==
null
)
{
if
(
$this
->
requiredValue
!==
null
)
{
...
@@ -102,7 +102,7 @@ class RequiredValidator extends Validator
...
@@ -102,7 +102,7 @@ class RequiredValidator extends Validator
}
}
$options
[
'message'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$options
[
'message'
],
[
$options
[
'message'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$options
[
'message'
],
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
);
],
Yii
::
$app
->
language
);
ValidationAsset
::
register
(
$view
);
ValidationAsset
::
register
(
$view
);
...
...
framework/validators/SafeValidator.php
View file @
d13d274d
...
@@ -18,7 +18,7 @@ class SafeValidator extends Validator
...
@@ -18,7 +18,7 @@ class SafeValidator extends Validator
/**
/**
* @inheritdoc
* @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
...
@@ -96,12 +96,12 @@ class StringValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
if
(
!
is_string
(
$value
))
{
if
(
!
is_string
(
$value
))
{
$this
->
addError
(
$
object
,
$attribute
,
$this
->
message
);
$this
->
addError
(
$
model
,
$attribute
,
$this
->
message
);
return
;
return
;
}
}
...
@@ -109,13 +109,13 @@ class StringValidator extends Validator
...
@@ -109,13 +109,13 @@ class StringValidator extends Validator
$length
=
mb_strlen
(
$value
,
$this
->
encoding
);
$length
=
mb_strlen
(
$value
,
$this
->
encoding
);
if
(
$this
->
min
!==
null
&&
$length
<
$this
->
min
)
{
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
)
{
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
)
{
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
...
@@ -146,9 +146,9 @@ class StringValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
$label
=
$
object
->
getAttributeLabel
(
$attribute
);
$label
=
$
model
->
getAttributeLabel
(
$attribute
);
$options
=
[
$options
=
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
...
...
framework/validators/UniqueValidator.php
View file @
d13d274d
...
@@ -74,24 +74,24 @@ class UniqueValidator extends Validator
...
@@ -74,24 +74,24 @@ class UniqueValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
/* @var $targetClass ActiveRecordInterface */
/* @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
;
$targetAttribute
=
$this
->
targetAttribute
===
null
?
$attribute
:
$this
->
targetAttribute
;
if
(
is_array
(
$targetAttribute
))
{
if
(
is_array
(
$targetAttribute
))
{
$params
=
[];
$params
=
[];
foreach
(
$targetAttribute
as
$k
=>
$v
)
{
foreach
(
$targetAttribute
as
$k
=>
$v
)
{
$params
[
$v
]
=
is_integer
(
$k
)
?
$
object
->
$v
:
$object
->
$k
;
$params
[
$v
]
=
is_integer
(
$k
)
?
$
model
->
$v
:
$model
->
$k
;
}
}
}
else
{
}
else
{
$params
=
[
$targetAttribute
=>
$
object
->
$attribute
];
$params
=
[
$targetAttribute
=>
$
model
->
$attribute
];
}
}
foreach
(
$params
as
$value
)
{
foreach
(
$params
as
$value
)
{
if
(
is_array
(
$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
;
return
;
}
}
...
@@ -106,14 +106,14 @@ class UniqueValidator extends Validator
...
@@ -106,14 +106,14 @@ class UniqueValidator extends Validator
$query
->
andWhere
(
$this
->
filter
);
$query
->
andWhere
(
$this
->
filter
);
}
}
if
(
!
$
object
instanceof
ActiveRecordInterface
||
$object
->
getIsNewRecord
())
{
if
(
!
$
model
instanceof
ActiveRecordInterface
||
$model
->
getIsNewRecord
())
{
// if current $
object
isn't in the database yet then it's OK just to call exists()
// if current $
model
isn't in the database yet then it's OK just to call exists()
$exists
=
$query
->
exists
();
$exists
=
$query
->
exists
();
}
else
{
}
else
{
// if current $
object
is in the database already we can't use exists()
// if current $
model
is in the database already we can't use exists()
/* @var $
object
s ActiveRecordInterface[] */
/* @var $
model
s ActiveRecordInterface[] */
$
object
s
=
$query
->
limit
(
2
)
->
all
();
$
model
s
=
$query
->
limit
(
2
)
->
all
();
$n
=
count
(
$
object
s
);
$n
=
count
(
$
model
s
);
if
(
$n
===
1
)
{
if
(
$n
===
1
)
{
$keys
=
array_keys
(
$params
);
$keys
=
array_keys
(
$params
);
$pks
=
$targetClass
::
primaryKey
();
$pks
=
$targetClass
::
primaryKey
();
...
@@ -121,10 +121,10 @@ class UniqueValidator extends Validator
...
@@ -121,10 +121,10 @@ class UniqueValidator extends Validator
sort
(
$pks
);
sort
(
$pks
);
if
(
$keys
===
$pks
)
{
if
(
$keys
===
$pks
)
{
// primary key is modified and not unique
// primary key is modified and not unique
$exists
=
$
object
->
getOldPrimaryKey
()
!=
$object
->
getPrimaryKey
();
$exists
=
$
model
->
getOldPrimaryKey
()
!=
$model
->
getPrimaryKey
();
}
else
{
}
else
{
// non-primary key, need to exclude the current record based on PK
// 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
{
}
else
{
$exists
=
$n
>
1
;
$exists
=
$n
>
1
;
...
@@ -132,7 +132,7 @@ class UniqueValidator extends Validator
...
@@ -132,7 +132,7 @@ class UniqueValidator extends Validator
}
}
if
(
$exists
)
{
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
...
@@ -66,14 +66,14 @@ class UrlValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
validateAttribute
(
$
object
,
$attribute
)
public
function
validateAttribute
(
$
model
,
$attribute
)
{
{
$value
=
$
object
->
$attribute
;
$value
=
$
model
->
$attribute
;
$result
=
$this
->
validateValue
(
$value
);
$result
=
$this
->
validateValue
(
$value
);
if
(
!
empty
(
$result
))
{
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
)
{
}
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
...
@@ -111,7 +111,7 @@ class UrlValidator extends Validator
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
clientValidateAttribute
(
$
object
,
$attribute
,
$view
)
public
function
clientValidateAttribute
(
$
model
,
$attribute
,
$view
)
{
{
if
(
strpos
(
$this
->
pattern
,
'{schemes}'
)
!==
false
)
{
if
(
strpos
(
$this
->
pattern
,
'{schemes}'
)
!==
false
)
{
$pattern
=
str_replace
(
'{schemes}'
,
'('
.
implode
(
'|'
,
$this
->
validSchemes
)
.
')'
,
$this
->
pattern
);
$pattern
=
str_replace
(
'{schemes}'
,
'('
.
implode
(
'|'
,
$this
->
validSchemes
)
.
')'
,
$this
->
pattern
);
...
@@ -122,7 +122,7 @@ class UrlValidator extends Validator
...
@@ -122,7 +122,7 @@ class UrlValidator extends Validator
$options
=
[
$options
=
[
'pattern'
=>
new
JsExpression
(
$pattern
),
'pattern'
=>
new
JsExpression
(
$pattern
),
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'message'
=>
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
message
,
[
'attribute'
=>
$
object
->
getAttributeLabel
(
$attribute
),
'attribute'
=>
$
model
->
getAttributeLabel
(
$attribute
),
],
Yii
::
$app
->
language
),
],
Yii
::
$app
->
language
),
'enableIDN'
=>
(
boolean
)
$this
->
enableIDN
,
'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