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
421e31ec
Commit
421e31ec
authored
Apr 04, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished validator refactoring.
parent
3bd186de
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
6 deletions
+25
-6
CaptchaValidator.php
framework/validators/CaptchaValidator.php
+1
-1
ExistValidator.php
framework/validators/ExistValidator.php
+8
-0
NumberValidator.php
framework/validators/NumberValidator.php
+4
-0
RegularExpressionValidator.php
framework/validators/RegularExpressionValidator.php
+5
-4
UniqueValidator.php
framework/validators/UniqueValidator.php
+6
-0
Validator.php
framework/validators/Validator.php
+1
-1
No files found.
framework/validators/CaptchaValidator.php
View file @
421e31ec
...
@@ -53,7 +53,7 @@ class CaptchaValidator extends Validator
...
@@ -53,7 +53,7 @@ class CaptchaValidator extends Validator
public
function
validateValue
(
$value
)
public
function
validateValue
(
$value
)
{
{
$captcha
=
$this
->
getCaptchaAction
();
$captcha
=
$this
->
getCaptchaAction
();
return
$captcha
->
validate
(
$value
,
$this
->
caseSensitive
);
return
!
is_array
(
$value
)
&&
$captcha
->
validate
(
$value
,
$this
->
caseSensitive
);
}
}
/**
/**
...
...
framework/validators/ExistValidator.php
View file @
421e31ec
...
@@ -48,6 +48,11 @@ class ExistValidator extends Validator
...
@@ -48,6 +48,11 @@ class ExistValidator extends Validator
{
{
$value
=
$object
->
$attribute
;
$value
=
$object
->
$attribute
;
if
(
is_array
(
$value
))
{
$this
->
addError
(
$object
,
$attribute
,
Yii
::
t
(
'yii|{attribute} is invalid.'
));
return
;
}
/** @var $className \yii\db\ActiveRecord */
/** @var $className \yii\db\ActiveRecord */
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
Yii
::
import
(
$this
->
className
);
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
Yii
::
import
(
$this
->
className
);
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
...
@@ -67,6 +72,9 @@ class ExistValidator extends Validator
...
@@ -67,6 +72,9 @@ class ExistValidator extends Validator
*/
*/
public
function
validateValue
(
$value
)
public
function
validateValue
(
$value
)
{
{
if
(
is_array
(
$value
))
{
return
false
;
}
if
(
$this
->
className
===
null
)
{
if
(
$this
->
className
===
null
)
{
throw
new
InvalidConfigException
(
'The "className" property must be set.'
);
throw
new
InvalidConfigException
(
'The "className" property must be set.'
);
}
}
...
...
framework/validators/NumberValidator.php
View file @
421e31ec
...
@@ -61,6 +61,10 @@ class NumberValidator extends Validator
...
@@ -61,6 +61,10 @@ class NumberValidator extends Validator
public
function
validateAttribute
(
$object
,
$attribute
)
public
function
validateAttribute
(
$object
,
$attribute
)
{
{
$value
=
$object
->
$attribute
;
$value
=
$object
->
$attribute
;
if
(
is_array
(
$value
))
{
$this
->
addError
(
$object
,
$attribute
,
Yii
::
t
(
'yii|{attribute} is invalid.'
));
return
;
}
if
(
$this
->
integerOnly
)
{
if
(
$this
->
integerOnly
)
{
if
(
!
preg_match
(
$this
->
integerPattern
,
"
$value
"
))
{
if
(
!
preg_match
(
$this
->
integerPattern
,
"
$value
"
))
{
$message
=
$this
->
message
!==
null
?
$this
->
message
:
Yii
::
t
(
'yii|{attribute} must be an integer.'
);
$message
=
$this
->
message
!==
null
?
$this
->
message
:
Yii
::
t
(
'yii|{attribute} must be an integer.'
);
...
...
framework/validators/RegularExpressionValidator.php
View file @
421e31ec
...
@@ -51,8 +51,8 @@ class RegularExpressionValidator extends Validator
...
@@ -51,8 +51,8 @@ class RegularExpressionValidator extends Validator
public
function
validateAttribute
(
$object
,
$attribute
)
public
function
validateAttribute
(
$object
,
$attribute
)
{
{
$value
=
$object
->
$attribute
;
$value
=
$object
->
$attribute
;
if
(
(
!
$this
->
not
&&
!
preg_match
(
$this
->
pattern
,
$value
))
||
(
$this
->
not
&&
preg_match
(
$this
->
pattern
,
$value
)
))
{
if
(
!
$this
->
validateValue
(
$value
))
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is invalid.'
);
$message
=
$this
->
message
!==
null
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is invalid.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
}
}
}
}
...
@@ -64,8 +64,9 @@ class RegularExpressionValidator extends Validator
...
@@ -64,8 +64,9 @@ class RegularExpressionValidator extends Validator
*/
*/
public
function
validateValue
(
$value
)
public
function
validateValue
(
$value
)
{
{
return
!
$this
->
not
&&
preg_match
(
$this
->
pattern
,
$value
)
return
!
is_array
(
$value
)
&&
||
$this
->
not
&&
!
preg_match
(
$this
->
pattern
,
$value
);
(
!
$this
->
not
&&
preg_match
(
$this
->
pattern
,
$value
)
||
$this
->
not
&&
!
preg_match
(
$this
->
pattern
,
$value
));
}
}
/**
/**
...
...
framework/validators/UniqueValidator.php
View file @
421e31ec
...
@@ -40,6 +40,12 @@ class UniqueValidator extends Validator
...
@@ -40,6 +40,12 @@ class UniqueValidator extends Validator
public
function
validateAttribute
(
$object
,
$attribute
)
public
function
validateAttribute
(
$object
,
$attribute
)
{
{
$value
=
$object
->
$attribute
;
$value
=
$object
->
$attribute
;
if
(
is_array
(
$value
))
{
$this
->
addError
(
$object
,
$attribute
,
Yii
::
t
(
'yii|{attribute} is invalid.'
));
return
;
}
/** @var $className \yii\db\ActiveRecord */
/** @var $className \yii\db\ActiveRecord */
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
\Yii
::
import
(
$this
->
className
);
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
\Yii
::
import
(
$this
->
className
);
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
...
...
framework/validators/Validator.php
View file @
421e31ec
...
@@ -192,7 +192,7 @@ abstract class Validator extends Component
...
@@ -192,7 +192,7 @@ abstract class Validator extends Component
*/
*/
public
function
validateValue
(
$value
)
public
function
validateValue
(
$value
)
{
{
throw
new
NotSupportedException
(
__CLASS__
.
' does not support validateValue().'
);
throw
new
NotSupportedException
(
get_class
(
$this
)
.
' does not support validateValue().'
);
}
}
/**
/**
...
...
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