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
3a6adcd2
Commit
3a6adcd2
authored
Mar 22, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2808 from drenty/conditional-validator
Implemented conditional validators (see #2406)
parents
c956ffb7
7ea52fb2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
Validator.php
framework/validators/Validator.php
+18
-1
No files found.
framework/validators/Validator.php
View file @
3a6adcd2
...
...
@@ -127,6 +127,13 @@ class Validator extends Component
* whether the value is empty.
*/
public
$isEmpty
;
/**
* @var callable a PHP callable that determines the conditions upon which the validation is performed.
* If not set, the validation will always be performed. If set, the client-side validation is disabled.
* The signature of the callable should be `function ($model)` which takes the model to be validated as a
* parameter and returns a boolean indicating whether the validation should be performed.
*/
public
$when
;
/**
* Creates a validator object.
...
...
@@ -171,6 +178,10 @@ class Validator extends Component
$this
->
attributes
=
(
array
)
$this
->
attributes
;
$this
->
on
=
(
array
)
$this
->
on
;
$this
->
except
=
(
array
)
$this
->
except
;
if
(
$this
->
when
!==
null
)
{
$this
->
enableClientValidation
=
false
;
}
}
/**
...
...
@@ -192,7 +203,13 @@ class Validator extends Component
$skip
=
$this
->
skipOnError
&&
$object
->
hasErrors
(
$attribute
)
||
$this
->
skipOnEmpty
&&
$this
->
isEmpty
(
$object
->
$attribute
);
if
(
!
$skip
)
{
$this
->
validateAttribute
(
$object
,
$attribute
);
if
(
$this
->
when
!==
null
)
{
if
(
call_user_func
(
$this
->
when
,
$object
))
{
$this
->
validateAttribute
(
$object
,
$attribute
);
}
}
else
{
$this
->
validateAttribute
(
$object
,
$attribute
);
}
}
}
}
...
...
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