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
c80c9dec
Commit
c80c9dec
authored
Jul 22, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
b51c3bc7
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
196 additions
and
143 deletions
+196
-143
BooleanValidator.php
framework/validators/BooleanValidator.php
+3
-2
CaptchaValidator.php
framework/validators/CaptchaValidator.php
+3
-2
CompareValidator.php
framework/validators/CompareValidator.php
+3
-2
DateValidator.php
framework/validators/DateValidator.php
+3
-2
DefaultValueValidator.php
framework/validators/DefaultValueValidator.php
+3
-2
EmailValidator.php
framework/validators/EmailValidator.php
+3
-2
ExistValidator.php
framework/validators/ExistValidator.php
+3
-2
FileValidator.php
framework/validators/FileValidator.php
+3
-2
FilterValidator.php
framework/validators/FilterValidator.php
+3
-2
InlineValidator.php
framework/validators/InlineValidator.php
+3
-2
NumberValidator.php
framework/validators/NumberValidator.php
+3
-2
RangeValidator.php
framework/validators/RangeValidator.php
+3
-2
RegularExpressionValidator.php
framework/validators/RegularExpressionValidator.php
+3
-2
RequiredValidator.php
framework/validators/RequiredValidator.php
+3
-2
SafeValidator.php
framework/validators/SafeValidator.php
+3
-2
StringValidator.php
framework/validators/StringValidator.php
+3
-2
TypeValidator.php
framework/validators/TypeValidator.php
+3
-2
UniqueValidator.php
framework/validators/UniqueValidator.php
+3
-2
UnsafeValidator.php
framework/validators/UnsafeValidator.php
+3
-2
UrlValidator.php
framework/validators/UrlValidator.php
+3
-2
Validator.php
framework/validators/Validator.php
+133
-103
upgrade.txt
upgrade.txt
+3
-0
No files found.
framework/validators/BooleanValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CBooleanValidator class file.
* CBooleanValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CBooleanValidator validates that the attribute value is either {@link trueValue} or {@link falseValue}.
* CBooleanValidator validates that the attribute value is either {@link trueValue} or {@link falseValue}.
*
*
...
...
framework/validators/CaptchaValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CCaptchaValidator class file.
* CCaptchaValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CCaptchaValidator validates that the attribute value is the same as the verification code displayed in the CAPTCHA.
* CCaptchaValidator validates that the attribute value is the same as the verification code displayed in the CAPTCHA.
*
*
...
...
framework/validators/CompareValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CCompareValidator class file.
* CCompareValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CCompareValidator compares the specified attribute value with another value and validates if they are equal.
* CCompareValidator compares the specified attribute value with another value and validates if they are equal.
*
*
...
...
framework/validators/DateValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CDateValidator class file.
* CDateValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CDateValidator verifies if the attribute represents a date, time or datetime.
* CDateValidator verifies if the attribute represents a date, time or datetime.
*
*
...
...
framework/validators/DefaultValueValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CDefaultValueValidator class file.
* CDefaultValueValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CDefaultValueValidator sets the attributes with the specified value.
* CDefaultValueValidator sets the attributes with the specified value.
* It does not do validation. Its existence is mainly to allow
* It does not do validation. Its existence is mainly to allow
...
...
framework/validators/EmailValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CEmailValidator class file.
* CEmailValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CEmailValidator validates that the attribute value is a valid email address.
* CEmailValidator validates that the attribute value is a valid email address.
*
*
...
...
framework/validators/ExistValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CExistValidator class file.
* CExistValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CExistValidator validates that the attribute value exists in a table.
* CExistValidator validates that the attribute value exists in a table.
*
*
...
...
framework/validators/FileValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CFileValidator class file.
* CFileValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CFileValidator verifies if an attribute is receiving a valid uploaded file.
* CFileValidator verifies if an attribute is receiving a valid uploaded file.
*
*
...
...
framework/validators/FilterValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CFilterValidator class file.
* CFilterValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CFilterValidator transforms the data being validated based on a filter.
* CFilterValidator transforms the data being validated based on a filter.
*
*
...
...
framework/validators/InlineValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CInlineValidator class file.
* CInlineValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CInlineValidator represents a validator which is defined as a method in the object being validated.
* CInlineValidator represents a validator which is defined as a method in the object being validated.
*
*
...
...
framework/validators/NumberValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CNumberValidator class file.
* CNumberValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CNumberValidator validates that the attribute value is a number.
* CNumberValidator validates that the attribute value is a number.
*
*
...
...
framework/validators/RangeValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CRangeValidator class file.
* CRangeValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CRangeValidator validates that the attribute value is among the list (specified via {@link range}).
* CRangeValidator validates that the attribute value is among the list (specified via {@link range}).
* You may invert the validation logic with help of the {@link not} property (available since 1.1.5).
* You may invert the validation logic with help of the {@link not} property (available since 1.1.5).
...
...
framework/validators/RegularExpressionValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CRegularExpressionValidator class file.
* CRegularExpressionValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CRegularExpressionValidator validates that the attribute value matches to the specified {@link pattern regular expression}.
* CRegularExpressionValidator validates that the attribute value matches to the specified {@link pattern regular expression}.
* You may invert the validation logic with help of the {@link not} property (available since 1.1.5).
* You may invert the validation logic with help of the {@link not} property (available since 1.1.5).
...
...
framework/validators/RequiredValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CRequiredValidator class file.
* CRequiredValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CRequiredValidator validates that the specified attribute does not have null or empty value.
* CRequiredValidator validates that the specified attribute does not have null or empty value.
*
*
...
...
framework/validators/SafeValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CSafeValidator class file.
* CSafeValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CSafeValidator marks the associated attributes to be safe for massive assignments.
* CSafeValidator marks the associated attributes to be safe for massive assignments.
*
*
...
...
framework/validators/StringValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CStringValidator class file.
* CStringValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CStringValidator validates that the attribute value is of certain length.
* CStringValidator validates that the attribute value is of certain length.
*
*
...
...
framework/validators/TypeValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CTypeValidator class file.
* CTypeValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CTypeValidator verifies if the attribute is of the type specified by {@link type}.
* CTypeValidator verifies if the attribute is of the type specified by {@link type}.
*
*
...
...
framework/validators/UniqueValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CUniqueValidator class file.
* CUniqueValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CUniqueValidator validates that the attribute value is unique in the corresponding database table.
* CUniqueValidator validates that the attribute value is unique in the corresponding database table.
*
*
...
...
framework/validators/UnsafeValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CUnsafeValidator class file.
* CUnsafeValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CUnsafeValidator marks the associated attributes to be unsafe so that they cannot be massively assigned.
* CUnsafeValidator marks the associated attributes to be unsafe so that they cannot be massively assigned.
*
*
...
...
framework/validators/UrlValidator.php
View file @
c80c9dec
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
/**
/**
* CUrlValidator class file.
* CUrlValidator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
* CUrlValidator validates that the attribute value is a valid http or https URL.
* CUrlValidator validates that the attribute value is a valid http or https URL.
*
*
...
...
framework/validators/Validator.php
View file @
c80c9dec
<?php
<?php
/**
/**
*
C
Validator class file.
* Validator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\validators
;
/**
/**
*
C
Validator is the base class for all validators.
* Validator is the base class for all validators.
*
*
* Child classes must implement the {@link validateAttribute} method.
* Child classes must implement the {@link validateAttribute} method.
*
*
...
@@ -52,33 +53,40 @@
...
@@ -52,33 +53,40 @@
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: CValidator.php 3160 2011-04-03 01:08:23Z qiang.xue $
* @version $Id: CValidator.php 3160 2011-04-03 01:08:23Z qiang.xue $
* @package system.validators
* @package system.validators
* @since
1
.0
* @since
2
.0
*/
*/
abstract
class
CValidator
extends
C
Component
abstract
class
Validator
extends
\yii\base\
Component
{
{
/**
/**
* @var array list of built-in validators (name
=>class
)
* @var array list of built-in validators (name
=> class or configuration
)
*/
*/
public
static
$builtInValidators
=
array
(
public
static
$builtInValidators
=
array
(
'required'
=>
'CRequiredValidator'
,
'required'
=>
'\yii\validators\RequiredValidator'
,
'filter'
=>
'CFilterValidator'
,
'filter'
=>
'\yii\validators\FilterValidator'
,
'match'
=>
'CRegularExpressionValidator'
,
'match'
=>
'\yii\validators\RegularExpressionValidator'
,
'email'
=>
'CEmailValidator'
,
'email'
=>
'\yii\validators\EmailValidator'
,
'url'
=>
'CUrlValidator'
,
'url'
=>
'\yii\validators\UrlValidator'
,
'unique'
=>
'CUniqueValidator'
,
'compare'
=>
'\yii\validators\CompareValidator'
,
'compare'
=>
'CCompareValidator'
,
'length'
=>
'\yii\validators\StringValidator'
,
'length'
=>
'CStringValidator'
,
'in'
=>
'\yii\validators\RangeValidator'
,
'in'
=>
'CRangeValidator'
,
'numerical'
=>
'\yii\validators\NumberValidator'
,
'numerical'
=>
'CNumberValidator'
,
'captcha'
=>
'CCaptchaValidator'
,
'boolean'
=>
'\yii\validators\BooleanValidator'
,
'type'
=>
'CTypeValidator'
,
'integer'
=>
'\yii\validators\IntegerValidator'
,
'file'
=>
'CFileValidator'
,
'float'
=>
'\yii\validators\FloatValidator'
,
'default'
=>
'CDefaultValueValidator'
,
'string'
=>
'\yii\validators\StringValidator'
,
'exist'
=>
'CExistValidator'
,
'date'
=>
'\yii\validators\DateValidator'
,
'boolean'
=>
'CBooleanValidator'
,
'safe'
=>
'CSafeValidator'
,
'captcha'
=>
'\yii\validators\CaptchaValidator'
,
'unsafe'
=>
'CUnsafeValidator'
,
'type'
=>
'\yii\validators\TypeValidator'
,
'date'
=>
'CDateValidator'
,
'file'
=>
'\yii\validators\FileValidator'
,
'default'
=>
'\yii\validators\DefaultValueValidator'
,
'unique'
=>
'\yii\validators\UniqueValidator'
,
'exist'
=>
'\yii\validators\ExistValidator'
,
'safe'
=>
'\yii\validators\SafeValidator'
,
'unsafe'
=>
'\yii\validators\UnsafeValidator'
,
);
);
/**
/**
...
@@ -86,126 +94,149 @@ abstract class CValidator extends CComponent
...
@@ -86,126 +94,149 @@ abstract class CValidator extends CComponent
*/
*/
public
$attributes
;
public
$attributes
;
/**
/**
* @var string the user-defined error message. Different validators may define various
* @var string the user-defined error message. Error message may contain some placeholders
* placeholders in the message that are to be replaced with actual values. All validators
* that will be replaced with the actual values by the validator.
* recognize "{attribute}" placeholder, which will be replaced with the label of the attribute.
* The `{attribute}` and `{value}` are placeholders supported by all validators.
* They will be replaced with the attribute label and value, respectively.
*/
*/
public
$message
;
public
$message
;
/**
/**
* @var boolean whether this validation rule should be skipped if when there is already a validation
* error for the current attribute. Defaults to false.
* @since 1.1.1
*/
public
$skipOnError
=
false
;
/**
* @var array list of scenarios that the validator should be applied.
* @var array list of scenarios that the validator should be applied.
* Each array value refers to a scenario name with the same name as its array key.
* Each array value refers to a scenario name with the same name as its array key.
*/
*/
public
$on
;
public
$on
;
/**
/**
* @var boolean whether attributes listed with this validator should be considered safe for massive assignment.
* @var boolean whether this validation rule should be skipped if the attribute being validated
* Defaults to true.
* already has some validation error according to the previous rules. Defaults to false.
* @since 1.1.4
*/
public
$skipOnError
=
false
;
/**
* @var boolean whether attributes listed with this validator should be considered safe for
* massive assignment. Defaults to true.
*/
*/
public
$safe
=
true
;
public
$safe
=
true
;
/**
/**
* @var boolean whether to
perform
client-side validation. Defaults to true.
* @var boolean whether to
enable
client-side validation. Defaults to true.
* Please refer to
{@link CActiveForm::enableClientValidation} for more details about client-side validation.
* Please refer to
[[\yii\web\ActiveForm::enableClientValidation]] for more details about
*
@since 1.1.7
*
client-side validation.
*/
*/
public
$enableClientValidation
=
true
;
public
$enableClientValidation
=
true
;
/**
/**
* Validates a value.
* Child classes should override this method to implement the actual validation logic.
* @param mixed $value the value being validated.
* @return boolean whether the value is valid.
*/
abstract
public
function
validateValue
(
$value
);
/**
* Validates a single attribute.
* Validates a single attribute.
* This method should be overridden by child classes.
* The default implementation will call [[validateValue]] to determine if
* @param CModel $object the data object being validated
* the attribute value is valid or not. If not, the [[message|error message]]
* will be added to the model object.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param string $attribute the name of the attribute to be validated.
*/
*/
abstract
protected
function
validateAttribute
(
$object
,
$attribute
);
public
function
validateAttribute
(
$object
,
$attribute
)
{
if
(
!
$this
->
validateValue
(
$object
->
$attribute
))
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
/**
/**
* Creates a validator object.
* Creates a validator object.
* @param string $name the name or class of the validator
* @param string $type the validator type. This can be a method name,
* @param CModel $object the data object being validated that may contain the inline validation method
* a built-in validator name, a class name, or a path alias of validator class.
* @param \yii\base\Model $object the data object being validated.
* @param mixed $attributes list of attributes to be validated. This can be either an array of
* @param mixed $attributes list of attributes to be validated. This can be either an array of
* the attribute names or a string of comma-separated attribute names.
* the attribute names or a string of comma-separated attribute names.
* @param array $params initial values to be applied to the validator properties
* @param array $params initial values to be applied to the validator properties
* @return
C
Validator the validator
* @return Validator the validator
*/
*/
public
static
function
createValidator
(
$
nam
e
,
$object
,
$attributes
,
$params
=
array
())
public
static
function
createValidator
(
$
typ
e
,
$object
,
$attributes
,
$params
=
array
())
{
{
if
(
is_string
(
$attributes
))
if
(
!
is_array
(
$attributes
))
{
$attributes
=
preg_split
(
'/[\s,]+/'
,
$attributes
,
-
1
,
PREG_SPLIT_NO_EMPTY
);
$attributes
=
preg_split
(
'/[\s,]+/'
,
$attributes
,
-
1
,
PREG_SPLIT_NO_EMPTY
);
}
if
(
isset
(
$params
[
'on'
]))
if
(
isset
(
$params
[
'on'
]))
{
{
if
(
is_array
(
$params
[
'on'
]))
{
if
(
is_array
(
$params
[
'on'
]))
$on
=
$params
[
'on'
];
$on
=
$params
[
'on'
];
else
}
else
{
$on
=
preg_split
(
'/[\s,]+/'
,
$params
[
'on'
],
-
1
,
PREG_SPLIT_NO_EMPTY
);
$on
=
preg_split
(
'/[\s,]+/'
,
$params
[
'on'
],
-
1
,
PREG_SPLIT_NO_EMPTY
);
}
$params
[
'on'
]
=
empty
(
$on
)
?
array
()
:
array_combine
(
$on
,
$on
);
}
else
{
$params
[
'on'
]
=
array
();
}
}
else
$on
=
array
();
if
(
method_exists
(
$object
,
$name
))
if
(
method_exists
(
$object
,
$type
))
{
// method-based validator
{
$config
=
array
(
$validator
=
new
CInlineValidator
;
'class'
=>
'\yii\validators\InlineValidator'
,
$validator
->
attributes
=
$attributes
;
'method'
=>
$type
,
$validator
->
method
=
$name
;
'attributes'
=>
$attributes
,
$validator
->
params
=
$params
;
);
if
(
isset
(
$params
[
'skipOnError'
]))
$validator
->
skipOnError
=
$params
[
'skipOnError'
];
}
}
else
else
{
{
if
(
is_string
(
$type
)
&&
isset
(
self
::
$builtInValidators
[
$type
]))
{
$params
[
'attributes'
]
=
$attributes
;
$type
=
self
::
$builtInValidators
[
$type
];
if
(
isset
(
self
::
$builtInValidators
[
$name
]))
}
$className
=
Yii
::
import
(
self
::
$builtInValidators
[
$name
],
true
);
$config
=
array
(
else
'class'
=>
$type
,
$className
=
Yii
::
import
(
$name
,
true
);
'attributes'
=>
$attributes
,
$validator
=
new
$className
;
);
foreach
(
$params
as
$name
=>
$value
)
}
$validator
->
$name
=
$value
;
$validator
=
\Yii
::
createComponent
(
$config
);
foreach
(
$params
as
$name
=>
$value
)
{
$validator
->
$name
=
$value
;
}
}
$validator
->
on
=
empty
(
$on
)
?
array
()
:
array_combine
(
$on
,
$on
);
return
$validator
;
return
$validator
;
}
}
/**
/**
* Validates the specified object.
* Validates the specified object.
* @param
C
Model $object the data object being validated
* @param
\yii\base\
Model $object the data object being validated
* @param array $attributes the list of attributes to be validated. Defaults to null,
* @param array $attributes the list of attributes to be validated. Defaults to null,
* meaning every attribute listed in
{@link attributes}
will be validated.
* meaning every attribute listed in
[[attributes]]
will be validated.
*/
*/
public
function
validate
(
$object
,
$attributes
=
null
)
public
function
validate
(
$object
,
$attributes
=
null
)
{
{
if
(
is_array
(
$attributes
))
if
(
is_array
(
$attributes
))
{
$attributes
=
array_intersect
(
$this
->
attributes
,
$attributes
);
$attributes
=
array_intersect
(
$this
->
attributes
,
$attributes
);
else
}
else
{
$attributes
=
$this
->
attributes
;
$attributes
=
$this
->
attributes
;
foreach
(
$attributes
as
$attribute
)
}
{
foreach
(
$attributes
as
$attribute
)
{
if
(
!
$this
->
skipOnError
||
!
$object
->
hasErrors
(
$attribute
))
if
(
!
$this
->
skipOnError
||
!
$object
->
hasErrors
(
$attribute
))
{
$this
->
validateAttribute
(
$object
,
$attribute
);
$this
->
validateAttribute
(
$object
,
$attribute
);
}
}
}
}
}
/**
/**
* Returns the JavaScript needed for performing client-side validation.
* Returns the JavaScript needed for performing client-side validation.
* Do not override this method if the validator does not support client-side validation.
*
* Two predefined JavaScript variables can be used:
* You may override this method to return the JavaScript validation code if
* <ul>
* the validator can support client-side validation.
* <li>value: the value to be validated</li>
*
* <li>messages: an array used to hold the validation error messages for the value</li>
* The following JavaScript variables are predefined and can be used in the validation code:
* </ul>
*
* @param CModel $object the data object being validated
* - `attribute`: the name of the attribute being validated.
* - `value`: the value being validated.
* - `messages`: an array used to hold the validation error messages for the attribute.
*
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param string $attribute the name of the attribute to be validated.
* @return string the client-side validation script. Null if the validator does not support client-side validation.
* @return string the client-side validation script. Null if the validator does not support
* @see CActiveForm::enableClientValidation
* client-side validation.
* @since 1.1.7
* @see enableClientValidation
* @see \yii\web\ActiveForm::enableClientValidation
*/
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
{
...
@@ -214,13 +245,12 @@ abstract class CValidator extends CComponent
...
@@ -214,13 +245,12 @@ abstract class CValidator extends CComponent
/**
/**
* Returns a value indicating whether the validator applies to the specified scenario.
* Returns a value indicating whether the validator applies to the specified scenario.
* A validator applies to a scenario as long as any of the following conditions is met:
* A validator applies to a scenario as long as any of the following conditions is met:
*
<ul>
*
*
<li>the validator's "on" property is empty</li>
*
- the validator's `on` property is empty
*
<li>the validator's "on" property contains the specified scenario</li>
*
- the validator's `on` property contains the specified scenario
*
</ul>
*
* @param string $scenario scenario name
* @param string $scenario scenario name
* @return boolean whether the validator applies to the specified scenario.
* @return boolean whether the validator applies to the specified scenario.
* @since 1.0.2
*/
*/
public
function
applyTo
(
$scenario
)
public
function
applyTo
(
$scenario
)
{
{
...
@@ -228,9 +258,9 @@ abstract class CValidator extends CComponent
...
@@ -228,9 +258,9 @@ abstract class CValidator extends CComponent
}
}
/**
/**
* Adds an error about the specified attribute to the
active record
.
* Adds an error about the specified attribute to the
model object
.
* This is a helper method that performs message selection and internationalization.
* This is a helper method that performs message selection and internationalization.
* @param
C
Model $object the data object being validated
* @param
\yii\base\
Model $object the data object being validated
* @param string $attribute the attribute being validated
* @param string $attribute the attribute being validated
* @param string $message the error message
* @param string $message the error message
* @param array $params values for the placeholders in the error message
* @param array $params values for the placeholders in the error message
...
@@ -238,6 +268,7 @@ abstract class CValidator extends CComponent
...
@@ -238,6 +268,7 @@ abstract class CValidator extends CComponent
protected
function
addError
(
$object
,
$attribute
,
$message
,
$params
=
array
())
protected
function
addError
(
$object
,
$attribute
,
$message
,
$params
=
array
())
{
{
$params
[
'{attribute}'
]
=
$object
->
getAttributeLabel
(
$attribute
);
$params
[
'{attribute}'
]
=
$object
->
getAttributeLabel
(
$attribute
);
$params
[
'{value}'
]
=
$object
->
$attribute
;
$object
->
addError
(
$attribute
,
strtr
(
$message
,
$params
));
$object
->
addError
(
$attribute
,
strtr
(
$message
,
$params
));
}
}
...
@@ -248,11 +279,10 @@ abstract class CValidator extends CComponent
...
@@ -248,11 +279,10 @@ abstract class CValidator extends CComponent
* @param mixed $value the value to be checked
* @param mixed $value the value to be checked
* @param boolean $trim whether to perform trimming before checking if the string is empty. Defaults to false.
* @param boolean $trim whether to perform trimming before checking if the string is empty. Defaults to false.
* @return boolean whether the value is empty
* @return boolean whether the value is empty
* @since 1.0.9
*/
*/
protected
function
isEmpty
(
$value
,
$trim
=
false
)
protected
function
isEmpty
(
$value
,
$trim
=
false
)
{
{
return
$value
===
null
||
$value
===
array
()
||
$value
===
''
||
$trim
&&
is_scalar
(
$value
)
&&
trim
(
$value
)
===
''
;
return
$value
===
null
||
$value
===
array
()
||
$value
===
''
||
$trim
&&
is_scalar
(
$value
)
&&
trim
(
$value
)
===
''
;
}
}
}
}
upgrade.txt
View file @
c80c9dec
...
@@ -10,3 +10,6 @@
...
@@ -10,3 +10,6 @@
- `CList` is renamed to `Vector`, and `CMap` is renamed to `Dictionary`.
- `CList` is renamed to `Vector`, and `CMap` is renamed to `Dictionary`.
Other collection classes are dropped in favor of SPL classes.
Other collection classes are dropped in favor of SPL classes.
- `CFormModel` is removed. Please use `yii\base\Model` instead.
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