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
ded8c22b
Commit
ded8c22b
authored
May 10, 2013
by
Alexander Kochetov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exception types corrected
parent
56757cdd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
13 deletions
+18
-13
DbManager.php
framework/rbac/DbManager.php
+4
-2
Manager.php
framework/rbac/Manager.php
+3
-3
PhpManager.php
framework/rbac/PhpManager.php
+11
-8
No files found.
framework/rbac/DbManager.php
View file @
ded8c22b
...
...
@@ -12,6 +12,7 @@ use yii\db\Connection;
use
yii\db\Query
;
use
yii\base\Exception
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidCallException
;
/**
* DbManager represents an authorization manager that stores authorization information in database.
...
...
@@ -133,7 +134,8 @@ class DbManager extends Manager
* @param string $itemName the parent item name
* @param string $childName the child item name
* @return boolean whether the item is added successfully
* @throws Exception if either parent or child doesn't exist or if a loop has been detected.
* @throws Exception if either parent or child doesn't exist.
* @throws InvalidCallException if a loop has been detected.
*/
public
function
addItemChild
(
$itemName
,
$childName
)
{
...
...
@@ -158,7 +160,7 @@ class DbManager extends Manager
}
$this
->
checkItemChildType
(
$parentType
,
$childType
);
if
(
$this
->
detectLoop
(
$itemName
,
$childName
))
{
throw
new
Exception
(
"Cannot add '
$childName
' as a child of '
$itemName
'. A loop has been detected."
);
throw
new
InvalidCall
Exception
(
"Cannot add '
$childName
' as a child of '
$itemName
'. A loop has been detected."
);
}
$this
->
db
->
createCommand
()
->
insert
(
$this
->
itemChildTable
,
array
(
...
...
framework/rbac/Manager.php
View file @
ded8c22b
...
...
@@ -9,7 +9,7 @@ namespace yii\rbac;
use
Yii
;
use
yii\base\Component
;
use
yii\base\Exception
;
use
yii\base\
InvalidParam
Exception
;
/**
* Manager is the base class for authorization manager classes.
...
...
@@ -155,13 +155,13 @@ abstract class Manager extends Component implements IManager
* Checks the item types to make sure a child can be added to a parent.
* @param integer $parentType parent item type
* @param integer $childType child item type
* @throws Exception if the item cannot be added as a child due to its incompatible type.
* @throws
InvalidParam
Exception if the item cannot be added as a child due to its incompatible type.
*/
protected
function
checkItemChildType
(
$parentType
,
$childType
)
{
static
$types
=
array
(
'operation'
,
'task'
,
'role'
);
if
(
$parentType
<
$childType
)
{
throw
new
Exception
(
"Cannot add an item of type '
$types[$childType]
' to an item of type '
$types[$parentType]
'."
);
throw
new
InvalidParam
Exception
(
"Cannot add an item of type '
$types[$childType]
' to an item of type '
$types[$parentType]
'."
);
}
}
}
framework/rbac/PhpManager.php
View file @
ded8c22b
...
...
@@ -9,6 +9,8 @@ namespace yii\rbac;
use
Yii
;
use
yii\base\Exception
;
use
yii\base\InvalidCallException
;
use
yii\base\InvalidParamException
;
/**
* PhpManager represents an authorization manager that stores authorization
...
...
@@ -103,7 +105,8 @@ class PhpManager extends Manager
* @param string $itemName the parent item name
* @param string $childName the child item name
* @return boolean whether the item is added successfully
* @throws Exception if either parent or child doesn't exist or if a loop has been detected.
* @throws Exception if either parent or child doesn't exist.
* @throws InvalidCallException if item already has a child with $itemName or if a loop has been detected.
*/
public
function
addItemChild
(
$itemName
,
$childName
)
{
...
...
@@ -116,10 +119,10 @@ class PhpManager extends Manager
$item
=
$this
->
_items
[
$itemName
];
$this
->
checkItemChildType
(
$item
->
getType
(),
$child
->
getType
());
if
(
$this
->
detectLoop
(
$itemName
,
$childName
))
{
throw
new
Exception
(
"Cannot add '
$childName
' as a child of '
$itemName
'. A loop has been detected."
);
throw
new
InvalidCall
Exception
(
"Cannot add '
$childName
' as a child of '
$itemName
'. A loop has been detected."
);
}
if
(
isset
(
$this
->
_children
[
$itemName
][
$childName
]))
{
throw
new
Exception
(
"The item '
$itemName
' already has a child '
$childName
'."
);
throw
new
InvalidCall
Exception
(
"The item '
$itemName
' already has a child '
$childName
'."
);
}
$this
->
_children
[
$itemName
][
$childName
]
=
$this
->
_items
[
$childName
];
return
true
;
...
...
@@ -182,14 +185,14 @@ class PhpManager extends Manager
* for this particular authorization item.
* @param mixed $data additional data associated with this assignment
* @return Assignment the authorization assignment information.
* @throws Exception if the item does not exist or if the item has already been assigned to the user
* @throws
InvalidParam
Exception if the item does not exist or if the item has already been assigned to the user
*/
public
function
assign
(
$userId
,
$itemName
,
$bizRule
=
null
,
$data
=
null
)
{
if
(
!
isset
(
$this
->
_items
[
$itemName
]))
{
throw
new
Exception
(
"Unknown authorization item '
$itemName
'."
);
throw
new
InvalidParam
Exception
(
"Unknown authorization item '
$itemName
'."
);
}
elseif
(
isset
(
$this
->
_assignments
[
$userId
][
$itemName
]))
{
throw
new
Exception
(
"Authorization item '
$itemName
' has already been assigned to user '
$userId
'."
);
throw
new
InvalidParam
Exception
(
"Authorization item '
$itemName
' has already been assigned to user '
$userId
'."
);
}
else
{
return
$this
->
_assignments
[
$userId
][
$itemName
]
=
new
Assignment
(
$this
,
$userId
,
$itemName
,
$bizRule
,
$data
);
}
...
...
@@ -336,14 +339,14 @@ class PhpManager extends Manager
* Saves an authorization item to persistent storage.
* @param Item $item the item to be saved.
* @param string $oldName the old item name. If null, it means the item name is not changed.
* @throws Exception if an item with the same name already taken
* @throws
InvalidParam
Exception if an item with the same name already taken
*/
public
function
saveItem
(
$item
,
$oldName
=
null
)
{
if
(
$oldName
!==
null
&&
(
$newName
=
$item
->
getName
())
!==
$oldName
)
// name changed
{
if
(
isset
(
$this
->
_items
[
$newName
]))
{
throw
new
Exception
(
"Unable to change the item name. The name '
$newName
' is already used by another item."
);
throw
new
InvalidParam
Exception
(
"Unable to change the item name. The name '
$newName
' is already used by another item."
);
}
if
(
isset
(
$this
->
_items
[
$oldName
])
&&
$this
->
_items
[
$oldName
]
===
$item
)
{
unset
(
$this
->
_items
[
$oldName
]);
...
...
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