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
a9003015
Commit
a9003015
authored
Jul 26, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Validator::except.
parent
b1047e7f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
7 deletions
+28
-7
ApplicationComponent.php
framework/base/ApplicationComponent.php
+8
-2
ErrorHandler.php
framework/base/ErrorHandler.php
+2
-0
Validator.php
framework/validators/Validator.php
+18
-5
No files found.
framework/base/ApplicationComponent.php
View file @
a9003015
...
...
@@ -15,12 +15,18 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
abstract
class
ApplicationComponent
extends
Component
class
ApplicationComponent
extends
Component
{
/**
*
Initializes the application component.
*
@var string unique ID of this application component
*/
public
$id
;
public
function
init
()
{
parent
::
init
();
if
(
$this
->
id
===
null
)
{
$this
->
id
=
get_class
(
$this
);
}
}
}
framework/base/ErrorHandler.php
View file @
a9003015
...
...
@@ -283,8 +283,10 @@ class ErrorHandler extends ApplicationComponent
{
$category
=
get_class
(
$exception
);
if
(
$exception
instanceof
HttpException
)
{
/** @var $exception HttpException */
$category
.=
'\\'
.
$exception
->
statusCode
;
}
elseif
(
$exception
instanceof
\ErrorException
)
{
/** @var $exception \ErrorException */
$category
.=
'\\'
.
$exception
->
getSeverity
();
}
\Yii
::
error
((
string
)
$exception
,
$category
);
...
...
framework/validators/Validator.php
View file @
a9003015
...
...
@@ -93,6 +93,11 @@ abstract class Validator extends \yii\base\Component
*/
public
$on
;
/**
* @var array list of scenarios that the validator should not be applied to.
* Each array value refers to a scenario name with the same name as its array key.
*/
public
$except
;
/**
* @var boolean whether this validation rule should be skipped if the attribute being validated
* already has some validation error according to the previous rules. Defaults to true.
*/
...
...
@@ -144,6 +149,17 @@ abstract class Validator extends \yii\base\Component
$params
[
'on'
]
=
array
();
}
if
(
isset
(
$params
[
'except'
]))
{
if
(
is_array
(
$params
[
'except'
]))
{
$except
=
$params
[
'except'
];
}
else
{
$except
=
preg_split
(
'/[\s,]+/'
,
$params
[
'except'
],
-
1
,
PREG_SPLIT_NO_EMPTY
);
}
$params
[
'except'
]
=
empty
(
$on
)
?
array
()
:
array_combine
(
$except
,
$except
);
}
else
{
$params
[
'except'
]
=
array
();
}
if
(
method_exists
(
$object
,
$type
))
{
// method-based validator
$config
=
array
(
...
...
@@ -225,11 +241,8 @@ abstract class Validator extends \yii\base\Component
*/
public
function
applyTo
(
$scenario
,
$attribute
=
null
)
{
if
(
$attribute
===
null
)
{
return
empty
(
$this
->
on
)
||
isset
(
$this
->
on
[
$scenario
]);
}
else
{
return
(
empty
(
$this
->
on
)
||
isset
(
$this
->
on
[
$scenario
]))
&&
in_array
(
$attribute
,
$this
->
attributes
,
true
);
}
$applies
=
!
isset
(
$this
->
except
[
$scenario
])
&&
(
empty
(
$this
->
on
)
||
isset
(
$this
->
on
[
$scenario
]));
return
$attribute
===
null
?
$applies
:
$applies
&&
in_array
(
$attribute
,
$this
->
attributes
,
true
);
}
/**
...
...
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