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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
Validator.php
framework/validators/Validator.php
+17
-0
No files found.
framework/validators/Validator.php
View file @
3a6adcd2
...
@@ -127,6 +127,13 @@ class Validator extends Component
...
@@ -127,6 +127,13 @@ class Validator extends Component
* whether the value is empty.
* whether the value is empty.
*/
*/
public
$isEmpty
;
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.
* Creates a validator object.
...
@@ -171,6 +178,10 @@ class Validator extends Component
...
@@ -171,6 +178,10 @@ class Validator extends Component
$this
->
attributes
=
(
array
)
$this
->
attributes
;
$this
->
attributes
=
(
array
)
$this
->
attributes
;
$this
->
on
=
(
array
)
$this
->
on
;
$this
->
on
=
(
array
)
$this
->
on
;
$this
->
except
=
(
array
)
$this
->
except
;
$this
->
except
=
(
array
)
$this
->
except
;
if
(
$this
->
when
!==
null
)
{
$this
->
enableClientValidation
=
false
;
}
}
}
/**
/**
...
@@ -192,8 +203,14 @@ class Validator extends Component
...
@@ -192,8 +203,14 @@ class Validator extends Component
$skip
=
$this
->
skipOnError
&&
$object
->
hasErrors
(
$attribute
)
$skip
=
$this
->
skipOnError
&&
$object
->
hasErrors
(
$attribute
)
||
$this
->
skipOnEmpty
&&
$this
->
isEmpty
(
$object
->
$attribute
);
||
$this
->
skipOnEmpty
&&
$this
->
isEmpty
(
$object
->
$attribute
);
if
(
!
$skip
)
{
if
(
!
$skip
)
{
if
(
$this
->
when
!==
null
)
{
if
(
call_user_func
(
$this
->
when
,
$object
))
{
$this
->
validateAttribute
(
$object
,
$attribute
);
$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