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
af09fe16
Commit
af09fe16
authored
May 22, 2014
by
Alexander Kochetov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve `in` validator to properly support array attributes.
parent
433d67c7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
RangeValidator.php
framework/validators/RangeValidator.php
+16
-2
No files found.
framework/validators/RangeValidator.php
View file @
af09fe16
...
@@ -35,6 +35,10 @@ class RangeValidator extends Validator
...
@@ -35,6 +35,10 @@ class RangeValidator extends Validator
* the attribute value should NOT be among the list of values defined via [[range]].
* the attribute value should NOT be among the list of values defined via [[range]].
*/
*/
public
$not
=
false
;
public
$not
=
false
;
/**
* @var boolean whether to allow array type attribute.
*/
public
$allowArray
=
false
;
/**
/**
* @inheritdoc
* @inheritdoc
...
@@ -55,8 +59,18 @@ class RangeValidator extends Validator
...
@@ -55,8 +59,18 @@ class RangeValidator extends Validator
*/
*/
protected
function
validateValue
(
$value
)
protected
function
validateValue
(
$value
)
{
{
$valid
=
!
$this
->
not
&&
in_array
(
$value
,
$this
->
range
,
$this
->
strict
)
if
(
!
$this
->
allowArray
&&
is_array
(
$value
))
{
||
$this
->
not
&&
!
in_array
(
$value
,
$this
->
range
,
$this
->
strict
);
return
[
$this
->
message
,
[]];
}
$valid
=
false
;
foreach
((
array
)
$value
as
$v
)
{
if
(
!
(
$valid
=
!
$this
->
not
&&
in_array
(
$v
,
$this
->
range
,
$this
->
strict
)
||
$this
->
not
&&
!
in_array
(
$v
,
$this
->
range
,
$this
->
strict
)))
{
break
;
}
}
return
$valid
?
null
:
[
$this
->
message
,
[]];
return
$valid
?
null
:
[
$this
->
message
,
[]];
}
}
...
...
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