Yii Framework v1.1.10 绫诲弬鑰

CDbAuthManager

system.web.auth
缁ф壙 class CDbAuthManager » CAuthManager » CApplicationComponent » CComponent
瀹炵幇 IAuthManager, IApplicationComponent
婧愯嚜 1.0
鐗堟湰 $Id: CDbAuthManager.php 3515 2011-12-28 12:29:24Z mdomba $
婧愮爜 framework/web/auth/CDbAuthManager.php
CDbAuthManager浠h〃涓绉嶅湪鏁版嵁搴撻噷瀛樺偍鎺堟潈淇℃伅鐨勬巿鏉冪鐞嗗櫒銆

鏁版嵁搴撹繛鎺ユ槸鐢connectionID鎸囧畾鐨勩傛暟鎹簱鏋舵瀯搴旇鎻忚堪涓 鈥渇ramework/web/auth/*.sql鈥濄備綘鍙互閫氳繃璁剧疆itemTableitemChildTableassignmentTable鏉ヤ慨鏀 杩欎笁涓敤鏉ュ瓨鍌ㄩ獙璇佹暟鎹殑鏁版嵁琛ㄣ

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
assignmentTable string 淇濆瓨鎺堟潈椤圭洰浠诲姟鐨勬暟鎹〃鍚嶅瓧銆傞粯璁や负鈥楢uthAssignment鈥欍 CDbAuthManager
authItems array 杩斿洖鎸囧畾绫诲瀷鍜岀敤鎴风殑鎺堟潈椤圭洰銆 CDbAuthManager
behaviors array 杩欎釜搴旂敤缁勪欢闄勫姞鐨勮涓恒 杩欐琛屼负灏嗗湪搴旂敤缁勪欢璋冪敤init鏃堕檮鍔犲湪搴旂敤缁勪欢涓娿 璇峰弬鐓CModel::behaviors濡備綍鎸囧畾姝ゅ睘鎬у笺 CApplicationComponent
connectionID string CDbConnection搴旂敤缁勪欢鐨処D銆傞粯璁や负鈥榙b鈥欍 鏁版嵁搴撻噷闈㈠繀椤诲寘鍚潃鍦"framework/web/auth/*. CDbAuthManager
db CDbConnection 鏁版嵁搴撹繛鎺ュ璞°傞粯璁ゆ槸锛岃繖涓細鏍规嵁搴旂敤缁勪欢閲岄潰鍏鐨connectionIDID鑷姩 鍒濆鍖栫殑銆 CDbAuthManager
defaultRoles array 闅愬紡璧嬩簣缁欐墍鏈夌敤鎴风殑瑙掕壊鍚嶅瓧鍒楄〃銆 杩欎簺瑙掕壊涓嶉渶瑕佹樉寮忚祴浜堢粰鎵鏈夌敤鎴枫 褰撹皟鐢checkAccess锛屼細棣栧厛妫鏌ヨ繖浜涜鑹层 涓轰簡鑳藉鎻愰珮绋嬪簭鏁堢巼锛岃繖鏍风殑瑙掕壊瓒婂皯瓒婂ソ銆 涓涓吀鍨嬬殑鐢ㄦ硶鏄紝瀹氫箟涓涓渁uthenticated鈥濊鑹诧紝鐒跺悗 鎶婂畠鍏宠仈鍒颁竴涓笟鍔¢昏緫瑙勫垯锛岃繖涓鍒欐槸鐢ㄦ潵楠岃瘉褰撳墠鐢ㄦ埛鐨勩 鐒跺悗鍦ㄨ繖涓睘鎬у0鏄庘渁uthenticated鈥濅互渚垮簲鐢ㄥ埌 鎵鏈夌殑楠岃瘉鐢ㄦ埛銆 CAuthManager
isInitialized boolean 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
itemChildTable string 淇濆瓨鎺堟潈椤圭洰灞傜骇鍏崇郴鐨勬暟鎹〃鍚嶅瓧銆傞粯璁や负鈥楢uthItemChild鈥欍 CDbAuthManager
itemTable string 淇濆瓨鎺堟潈椤圭洰鐨勬暟鎹〃鍚嶅瓧銆傞粯璁や负鈥楢uthItem鈥欍 CDbAuthManager
operations array 杩斿洖鎿嶄綔銆 CAuthManager
roles array 杩斿洖瑙掕壊銆 CAuthManager
showErrors boolean 鍏佽涓氬姟瑙勫垯閿欒鎶ュ憡銆 CAuthManager
tasks array 杩斿洖浠诲姟銆 CAuthManager

鍙椾繚鎶ゅ睘鎬

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
dbConnection CDbConnection 鏁版嵁搴撹繛鎺ュ璞° CDbAuthManager

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
addItemChild() 灏嗕竴涓」鐩綔涓轰竴涓瓙椤圭洰娣诲姞銆 CDbAuthManager
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
assign() 灏嗘巿鏉冮」鐩祴浜堢粰鐢ㄦ埛銆 CDbAuthManager
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
checkAccess() 妫娴嬫寚瀹氱敤鎴风殑璁块棶鏉冮檺銆 CDbAuthManager
clearAll() 绉婚櫎鎵鏈夋巿鏉冩暟鎹 CDbAuthManager
clearAuthAssignments() 绉婚櫎鎵鏈夋巿鏉冧换鍔° CDbAuthManager
createAuthItem() 鍒涘缓涓涓巿鏉冮」鐩 CDbAuthManager
createOperation() 鍒涘缓涓涓搷浣溿 CAuthManager
createRole() 鍒涘缓涓涓鑹层 CAuthManager
createTask() 鍒涘缓涓涓换鍔° CAuthManager
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
executeBizRule() 鎵ц鎸囧畾鐨勪笟鍔¤鍒欍 CAuthManager
getAuthAssignment() 杩斿洖椤圭洰浠诲姟淇℃伅銆 CDbAuthManager
getAuthAssignments() 杩斿洖鎸囧畾鐢ㄦ埛鐨勯」鐩换鍔° CDbAuthManager
getAuthItem() 杩斿洖鎸囧畾鍚嶅瓧鐨勬巿鏉冮」鐩 CDbAuthManager
getAuthItems() 杩斿洖鎸囧畾绫诲瀷鍜岀敤鎴风殑鎺堟潈椤圭洰銆 CDbAuthManager
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIsInitialized() 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
getItemChildren() 杩斿洖杩欎釜椤圭洰鐨勬墍鏈夊瓙椤圭洰銆 CDbAuthManager
getOperations() 杩斿洖鎿嶄綔銆 CAuthManager
getRoles() 杩斿洖瑙掕壊銆 CAuthManager
getTasks() 杩斿洖浠诲姟銆 CAuthManager
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasItemChild() 杩斿洖涓涓艰鏄庤繖涓瓙椤圭洰鏄惁瀛樺湪 CDbAuthManager
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() 鍒濆鍖栬繖涓簲鐢ㄧ粍浠躲 CDbAuthManager
isAssigned() 杩斿洖鍊艰鏄庤繖涓」鐩槸鍚﹀凡缁忚祴浜堢粰鐢ㄦ埛銆 CDbAuthManager
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
removeAuthItem() 绉婚櫎鎸囧畾鐨勬巿鏉冮」鐩 CDbAuthManager
removeItemChild() 绉婚櫎瀛愰」鐩 CDbAuthManager
revoke() 鎾ゆ秷鐢ㄦ埛鐨勬巿鏉冧换鍔° CDbAuthManager
save() 灏嗘巿鏉冩暟鎹繚瀛樺埌鎸佷箙鍖栧瓨鍌ㄥ櫒銆 CDbAuthManager
saveAuthAssignment() 淇濆瓨淇敼杩囩殑鎺堟潈浠诲姟銆 CDbAuthManager
saveAuthItem() 灏嗘巿鏉冮」鐩繚瀛樺埌鎸佷箙鍖栧瓨鍌ㄥ櫒銆 CDbAuthManager

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
checkAccessRecursive() 妫娴嬫寚瀹氱敤鎴风殑璁块棶鏉冮檺銆 CDbAuthManager
checkItemChildType() 妫鏌ラ」鐩被鍨嬩互纭畾涓涓瓙椤圭洰宸茬粡璧嬩簣缁欎竴涓埗椤圭洰銆 CAuthManager
detectLoop() 妫娴嬫槸鍚﹀湪鎺堟潈椤圭洰灞傜骇涓瓨鍦ㄥ惊鐜 CDbAuthManager
getDbConnection() 杩斿洖鏁版嵁搴撹繛鎺ュ璞° CDbAuthManager
usingSqlite() CDbAuthManager

灞炴ц缁

assignmentTable 灞炴
public string $assignmentTable;

淇濆瓨鎺堟潈椤圭洰浠诲姟鐨勬暟鎹〃鍚嶅瓧銆傞粯璁や负鈥楢uthAssignment鈥欍

authItems 灞炴 鍙
public array getAuthItems(integer $type=NULL, mixed $userId=NULL)

杩斿洖鎸囧畾绫诲瀷鍜岀敤鎴风殑鎺堟潈椤圭洰銆

connectionID 灞炴
public string $connectionID;

CDbConnection搴旂敤缁勪欢鐨処D銆傞粯璁や负鈥榙b鈥欍 鏁版嵁搴撻噷闈㈠繀椤诲寘鍚潃鍦"framework/web/auth/*.sql"澹版槑鐨勬暟鎹〃銆

db 灞炴
public CDbConnection $db;

鏁版嵁搴撹繛鎺ュ璞°傞粯璁ゆ槸锛岃繖涓細鏍规嵁搴旂敤缁勪欢閲岄潰鍏鐨connectionIDID鑷姩 鍒濆鍖栫殑銆

dbConnection 灞炴 鍙

鏁版嵁搴撹繛鎺ュ璞°

itemChildTable 灞炴
public string $itemChildTable;

淇濆瓨鎺堟潈椤圭洰灞傜骇鍏崇郴鐨勬暟鎹〃鍚嶅瓧銆傞粯璁や负鈥楢uthItemChild鈥欍

itemTable 灞炴
public string $itemTable;

淇濆瓨鎺堟潈椤圭洰鐨勬暟鎹〃鍚嶅瓧銆傞粯璁や负鈥楢uthItem鈥欍

鏂规硶璇︾粏

addItemChild() 鏂规硶
public boolean addItemChild(string $itemName, string $childName)
$itemName string 鐖堕」鐩悕瀛
$childName string 瀛愰」鐩悕瀛
{return} boolean 娣诲姞鏄惁鎴愬姛銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#125 (鏄剧ず)
public function addItemChild($itemName,$childName)
{
    if(
$itemName===$childName)
        throw new 
CException(Yii::t('yii','Cannot add "{name}" as a child of itself.',
                array(
'{name}'=>$itemName)));

    
$rows=$this->db->createCommand()
        ->
select()
        ->
from($this->itemTable)
        ->
where('name=:name1 OR name=:name2', array(
            
':name1'=>$itemName,
            
':name2'=>$childName
        
))
        ->
queryAll();

    if(
count($rows)==2)
    {
        if(
$rows[0]['name']===$itemName)
        {
            
$parentType=$rows[0]['type'];
            
$childType=$rows[1]['type'];
        }
        else
        {
            
$childType=$rows[0]['type'];
            
$parentType=$rows[1]['type'];
        }
        
$this->checkItemChildType($parentType,$childType);
        if(
$this->detectLoop($itemName,$childName))
            throw new 
CException(Yii::t('yii','Cannot add "{child}" as a child of "{name}". A loop has been detected.',
                array(
'{child}'=>$childName,'{name}'=>$itemName)));

        
$this->db->createCommand()
            ->
insert($this->itemChildTable, array(
                
'parent'=>$itemName,
                
'child'=>$childName,
            ));

        return 
true;
    }
    else
        throw new 
CException(Yii::t('yii','Either "{parent}" or "{child}" does not exist.',array('{child}'=>$childName,'{parent}'=>$itemName)));
}

灏嗕竴涓」鐩綔涓轰竴涓瓙椤圭洰娣诲姞銆

assign() 鏂规硶
public CAuthAssignment assign(string $itemName, mixed $userId, string $bizRule=NULL, mixed $data=NULL)
$itemName string 椤圭洰鍚嶅瓧
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
$bizRule string 褰撹皟鐢checkAccess鏃讹紝 鍏蜂綋鐨勬巿鏉冮」鐩殑涓氬姟瑙勫垯銆
$data mixed 杩欎釜浠诲姟棰濆鐨勬暟鎹
{return} CAuthAssignment 鎺堟潈浠诲姟鐨勪俊鎭
婧愮爜锛 framework/web/auth/CDbAuthManager.php#248 (鏄剧ず)
public function assign($itemName,$userId,$bizRule=null,$data=null)
{
    if(
$this->usingSqlite() && $this->getAuthItem($itemName)===null)
        throw new 
CException(Yii::t('yii','The item "{name}" does not exist.',array('{name}'=>$itemName)));

    
$this->db->createCommand()
        ->
insert($this->assignmentTable, array(
            
'itemname'=>$itemName,
            
'userid'=>$userId,
            
'bizrule'=>$bizRule,
            
'data'=>serialize($data)
        ));
    return new 
CAuthAssignment($this,$itemName,$userId,$bizRule,$data);
}

灏嗘巿鏉冮」鐩祴浜堢粰鐢ㄦ埛銆

checkAccess() 鏂规硶
public void checkAccess(string $itemName, mixed $userId, array $params=array ( ))
$itemName string 闇瑕佹娴嬬殑璁块棶鎿嶄綔鍚嶅瓧
$userId mixed 鐢ㄦ埛ID銆傝繖涓彲浠ユ槸鏁板瓧锛屾垨鑰呮槸鍞竴璇嗗埆鐢ㄦ埛韬唤鐨 瀛楃涓层傝鎯呰鐪IWebUser::getId
$params array 閿悕锛嶉敭鍊煎锛屽皢鍏宠仈鍒扮敤鎴风殑浠诲姟鍜岃鑹蹭紶閫掔粰 涓氬姟瑙勫垯銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#71 (鏄剧ず)
public function checkAccess($itemName,$userId,$params=array())
{
    
$assignments=$this->getAuthAssignments($userId);
    return 
$this->checkAccessRecursive($itemName,$userId,$params,$assignments);
}

妫娴嬫寚瀹氱敤鎴风殑璁块棶鏉冮檺銆

checkAccessRecursive() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.3锛
protected boolean checkAccessRecursive(string $itemName, mixed $userId, array $params, array $assignments)
$itemName string 闇瑕佹娴嬬殑璁块棶鎿嶄綔鍚嶅瓧
$userId mixed 鐢ㄦ埛ID銆傝繖涓彲浠ユ槸鏁板瓧锛屾垨鑰呮槸鍞竴璇嗗埆鐢ㄦ埛韬唤鐨 瀛楃涓层傝鎯呰鐪IWebUser::getId
$params array 閿悕锛嶉敭鍊煎锛屽皢鍏宠仈鍒扮敤鎴风殑浠诲姟鍜岃鑹蹭紶閫掔粰 涓氬姟瑙勫垯銆
$assignments array 鎸囧畾鐢ㄦ埛鐨勪换鍔
{return} boolean 杩斿洖鍊艰鏄庣敤鎴锋槸鍚︽湁鏉冮檺杩涜鎿嶄綔銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#89 (鏄剧ず)
protected function checkAccessRecursive($itemName,$userId,$params,$assignments)
{
    if((
$item=$this->getAuthItem($itemName))===null)
        return 
false;
    
Yii::trace('Checking permission "'.$item->getName().'"','system.web.auth.CDbAuthManager');
    if(
$this->executeBizRule($item->getBizRule(),$params,$item->getData()))
    {
        if(
in_array($itemName,$this->defaultRoles))
            return 
true;
        if(isset(
$assignments[$itemName]))
        {
            
$assignment=$assignments[$itemName];
            if(
$this->executeBizRule($assignment->getBizRule(),$params,$assignment->getData()))
                return 
true;
        }
        
$parents=$this->db->createCommand()
            ->
select('parent')
            ->
from($this->itemChildTable)
            ->
where('child=:name', array(':name'=>$itemName))
            ->
queryColumn();
        foreach(
$parents as $parent)
        {
            if(
$this->checkAccessRecursive($parent,$userId,$params,$assignments))
                return 
true;
        }
    }
    return 
false;
}

妫娴嬫寚瀹氱敤鎴风殑璁块棶鏉冮檺銆 杩欎釜鏂规硶鏄checkAccess鍐呴儴璋冪敤銆

clearAll() 鏂规硶
public void clearAll()
婧愮爜锛 framework/web/auth/CDbAuthManager.php#544 (鏄剧ず)
public function clearAll()
{
    
$this->clearAuthAssignments();
    
$this->db->createCommand()->delete($this->itemChildTable);
    
$this->db->createCommand()->delete($this->itemTable);
}

绉婚櫎鎵鏈夋巿鏉冩暟鎹

clearAuthAssignments() 鏂规硶
public void clearAuthAssignments()
婧愮爜锛 framework/web/auth/CDbAuthManager.php#554 (鏄剧ず)
public function clearAuthAssignments()
{
    
$this->db->createCommand()->delete($this->assignmentTable);
}

绉婚櫎鎵鏈夋巿鏉冧换鍔°

createAuthItem() 鏂规硶
public CAuthItem createAuthItem(string $name, integer $type, string $description='', string $bizRule=NULL, mixed $data=NULL)
$name string 椤圭洰鍚嶅瓧銆傝繖涓竴涓槸鍞竴鏍囪瘑銆
$type integer 椤圭洰绫诲瀷锛0锛氭搷浣滐紝1锛氫换鍔★紝2锛氳鑹诧級銆
$description string 椤圭洰鎻忚堪
$bizRule string 鍏宠仈鍒伴」鐩殑涓氬姟瑙勫垯銆傝繖閲屾槸PHP浠g爜娈碉紝褰撹皟鐢checkAccess鏃 浼氭墽琛屻
$data mixed 椤圭洰鍏宠仈鐨勯澶栨暟鎹
{return} CAuthItem 鎺堟潈椤圭洰
婧愮爜锛 framework/web/auth/CDbAuthManager.php#431 (鏄剧ず)
public function createAuthItem($name,$type,$description='',$bizRule=null,$data=null)
{
    
$this->db->createCommand()
        ->
insert($this->itemTable, array(
            
'name'=>$name,
            
'type'=>$type,
            
'description'=>$description,
            
'bizrule'=>$bizRule,
            
'data'=>serialize($data)
        ));
    return new 
CAuthItem($this,$name,$type,$description,$bizRule,$data);
}

鍒涘缓涓涓巿鏉冮」鐩 浠h〃鍔ㄤ綔鏉冮檺鐨勬巿鏉冮」鐩紙濡傦紝鍒涘缓涓涓唴瀹癸級銆 瀹冩湁涓夌绫诲瀷锛氭搷浣滐紝浠诲姟锛岃鑹层 灞傜骇鎺堟潈椤圭洰銆傞珮灞傞」鐩户鎵 浣庡眰椤圭洰鐨勬潈闄愩

detectLoop() 鏂规硶
protected boolean detectLoop(string $itemName, string $childName)
$itemName string 鐖堕」鐩悕瀛
$childName string 娣诲姞鍒板眰绾х殑瀛愰」鐩悕瀛椼
{return} boolean 杩斿洖鍊艰鏄庢槸鍚﹀瓨鍦ㄥ惊鐜
婧愮爜锛 framework/web/auth/CDbAuthManager.php#565 (鏄剧ず)
protected function detectLoop($itemName,$childName)
{
    if(
$childName===$itemName)
        return 
true;
    foreach(
$this->getItemChildren($childName) as $child)
    {
        if(
$this->detectLoop($itemName,$child->getName()))
            return 
true;
    }
    return 
false;
}

妫娴嬫槸鍚﹀湪鎺堟潈椤圭洰灞傜骇涓瓨鍦ㄥ惊鐜

getAuthAssignment() 鏂规硶
public CAuthAssignment getAuthAssignment(string $itemName, mixed $userId)
$itemName string 椤圭洰鍚嶅瓧
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
{return} CAuthAssignment 椤圭洰浠诲姟淇℃伅銆傚鏋滄病鏈夎祴浜堢粰鐢ㄦ埛锛 鍒欒繑鍥瀗ull銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#302 (鏄剧ず)
public function getAuthAssignment($itemName,$userId)
{
    
$row=$this->db->createCommand()
        ->
select()
        ->
from($this->assignmentTable)
        ->
where('itemname=:itemname AND userid=:userid', array(
            
':itemname'=>$itemName,
            
':userid'=>$userId))
        ->
queryRow();
    if(
$row!==false)
    {
        if((
$data=@unserialize($row['data']))===false)
            
$data=null;
        return new 
CAuthAssignment($this,$row['itemname'],$row['userid'],$row['bizrule'],$data);
    }
    else
        return 
null;
}

杩斿洖椤圭洰浠诲姟淇℃伅銆

getAuthAssignments() 鏂规硶
public array getAuthAssignments(mixed $userId)
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
{return} array 鐢ㄦ埛鐨勯」鐩换鍔′俊鎭傚鏋滄病鏈夐」鐩祴浜堢粰鐢ㄦ埛锛 鍒欒繑鍥瀗ull銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#327 (鏄剧ず)
public function getAuthAssignments($userId)
{
    
$rows=$this->db->createCommand()
        ->
select()
        ->
from($this->assignmentTable)
        ->
where('userid=:userid', array(':userid'=>$userId))
        ->
queryAll();
    
$assignments=array();
    foreach(
$rows as $row)
    {
        if((
$data=@unserialize($row['data']))===false)
            
$data=null;
        
$assignments[$row['itemname']]=new CAuthAssignment($this,$row['itemname'],$row['userid'],$row['bizrule'],$data);
    }
    return 
$assignments;
}

杩斿洖鎸囧畾鐢ㄦ埛鐨勯」鐩换鍔°

getAuthItem() 鏂规硶
public CAuthItem getAuthItem(string $name)
$name string 椤圭洰鍚嶅瓧
{return} CAuthItem 鎺堟潈椤圭洰銆傚鏋滄壘涓嶅埌璇ラ」鐩紝鍒欒繑鍥瀗ull銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#475 (鏄剧ず)
public function getAuthItem($name)
{
    
$row=$this->db->createCommand()
        ->
select()
        ->
from($this->itemTable)
        ->
where('name=:name', array(':name'=>$name))
        ->
queryRow();

    if(
$row!==false)
    {
        if((
$data=@unserialize($row['data']))===false)
            
$data=null;
        return new 
CAuthItem($this,$row['name'],$row['type'],$row['description'],$row['bizrule'],$data);
    }
    else
        return 
null;
}

杩斿洖鎸囧畾鍚嶅瓧鐨勬巿鏉冮」鐩

getAuthItems() 鏂规硶
public array getAuthItems(integer $type=NULL, mixed $userId=NULL)
$type integer 椤圭洰绫诲瀷锛0锛氭搷浣滐紝1锛氫换鍔★紝2锛氳鑹诧級銆傞粯璁や负null锛 鎰忓懗鐫杩斿洖鎵鏈夌被鍨嬨
$userId mixed 鐢ㄦ埛ID銆傞粯璁や负null锛屾剰鍛崇潃鍗充娇娌℃湁璧嬩簣缁欑敤鎴凤紝 涔熻繑鍥炴墍鏈夌殑椤圭洰銆
{return} array 鎸囧畾绫诲瀷鐨勬巿鏉冮」鐩
婧愮爜锛 framework/web/auth/CDbAuthManager.php#368 (鏄剧ず)
public function getAuthItems($type=null,$userId=null)
{
    if(
$type===null && $userId===null)
    {
        
$command=$this->db->createCommand()
            ->
select()
            ->
from($this->itemTable);
    }
    else if(
$userId===null)
    {
        
$command=$this->db->createCommand()
            ->
select()
            ->
from($this->itemTable)
            ->
where('type=:type', array(':type'=>$type));
    }
    else if(
$type===null)
    {
        
$command=$this->db->createCommand()
            ->
select('name,type,description,t1.bizrule,t1.data')
            ->
from(array(
                
$this->itemTable.' t1',
                
$this->assignmentTable.' t2'
            
))
            ->
where('name=itemname AND userid=:userid', array(':userid'=>$userId));
    }
    else
    {
        
$command=$this->db->createCommand()
            ->
select('name,type,description,t1.bizrule,t1.data')
            ->
from(array(
                
$this->itemTable.' t1',
                
$this->assignmentTable.' t2'
            
))
            ->
where('name=itemname AND type=:type AND userid=:userid', array(
                
':type'=>$type,
                
':userid'=>$userId
            
));
    }
    
$items=array();
    foreach(
$command->queryAll() as $row)
    {
        if((
$data=@unserialize($row['data']))===false)
            
$data=null;
        
$items[$row['name']]=new CAuthItem($this,$row['name'],$row['type'],$row['description'],$row['bizrule'],$data);
    }
    return 
$items;
}

杩斿洖鎸囧畾绫诲瀷鍜岀敤鎴风殑鎺堟潈椤圭洰銆

getDbConnection() 鏂规硶
protected CDbConnection getDbConnection()
{return} CDbConnection 鏁版嵁搴撹繛鎺ュ璞°
婧愮爜锛 framework/web/auth/CDbAuthManager.php#581 (鏄剧ず)
protected function getDbConnection()
{
    if(
$this->db!==null)
        return 
$this->db;
    else if((
$this->db=Yii::app()->getComponent($this->connectionID)) instanceof CDbConnection)
        return 
$this->db;
    else
        throw new 
CException(Yii::t('yii','CDbAuthManager.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.',
            array(
'{id}'=>$this->connectionID)));
}

getItemChildren() 鏂规硶
public array getItemChildren(mixed $names)
$names mixed 鐖堕」鐩悕瀛椼傚彲浠ユ槸瀛楃涓叉垨鏁扮粍銆 鍚庤呬唬琛ㄩ」鐩悕瀛楀垪琛ㄣ
{return} array 鐖堕」鐩殑鎵鏈夊瓙椤圭洰銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#208 (鏄剧ず)
public function getItemChildren($names)
{
    if(
is_string($names))
        
$condition='parent='.$this->db->quoteValue($names);
    else if(
is_array($names) && $names!==array())
    {
        foreach(
$names as &$name)
            
$name=$this->db->quoteValue($name);
        
$condition='parent IN ('.implode(', ',$names).')';
    }

    
$rows=$this->db->createCommand()
        ->
select('name, type, description, bizrule, data')
        ->
from(array(
            
$this->itemTable,
            
$this->itemChildTable
        
))
        ->
where($condition.' AND name=child')
        ->
queryAll();

    
$children=array();
    foreach(
$rows as $row)
    {
        if((
$data=@unserialize($row['data']))===false)
            
$data=null;
        
$children[$row['name']]=new CAuthItem($this,$row['name'],$row['type'],$row['description'],$row['bizrule'],$data);
    }
    return 
$children;
}

杩斿洖杩欎釜椤圭洰鐨勬墍鏈夊瓙椤圭洰銆

hasItemChild() 鏂规硶
public boolean hasItemChild(string $itemName, string $childName)
$itemName string 鐖堕」鐩悕瀛
$childName string 瀛愰」鐩悕瀛
{return} boolean 瀛愰」鐩槸鍚﹀瓨鍦
婧愮爜锛 framework/web/auth/CDbAuthManager.php#191 (鏄剧ず)
public function hasItemChild($itemName,$childName)
{
    return 
$this->db->createCommand()
        ->
select('parent')
        ->
from($this->itemChildTable)
        ->
where('parent=:parent AND child=:child', array(
            
':parent'=>$itemName,
            
':child'=>$childName))
        ->
queryScalar() !== false;
}

杩斿洖涓涓艰鏄庤繖涓瓙椤圭洰鏄惁瀛樺湪

init() 鏂规硶
public void init()
婧愮爜锛 framework/web/auth/CDbAuthManager.php#57 (鏄剧ず)
public function init()
{
    
parent::init();
    
$this->_usingSqlite=!strncmp($this->getDbConnection()->getDriverName(),'sqlite',6);
}

鍒濆鍖栬繖涓簲鐢ㄧ粍浠躲 杩欎釜鏂规硶瑕嗙洊鐖剁被鏂规硶锛屽疄鐜颁簡鏁版嵁搴撹繛鎺ャ

isAssigned() 鏂规硶
public boolean isAssigned(string $itemName, mixed $userId)
$itemName string 椤圭洰鍚嶅瓧
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
{return} boolean 杩欎釜椤圭洰鏄惁宸茬粡璧嬩簣缁欑敤鎴枫
婧愮爜锛 framework/web/auth/CDbAuthManager.php#284 (鏄剧ず)
public function isAssigned($itemName,$userId)
{
    return 
$this->db->createCommand()
        ->
select('itemname')
        ->
from($this->assignmentTable)
        ->
where('itemname=:itemname AND userid=:userid', array(
            
':itemname'=>$itemName,
            
':userid'=>$userId))
        ->
queryScalar() !== false;
}

杩斿洖鍊艰鏄庤繖涓」鐩槸鍚﹀凡缁忚祴浜堢粰鐢ㄦ埛銆

removeAuthItem() 鏂规硶
public boolean removeAuthItem(string $name)
$name string 瑕佺Щ闄ょ殑椤圭洰鍚嶅瓧
{return} boolean 瀛樺偍鍣ㄥ瓨鍦ㄧ殑椤圭洰鏄惁宸茬粡绉婚櫎鎴愬姛銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#449 (鏄剧ず)
public function removeAuthItem($name)
{
    if(
$this->usingSqlite())
    {
        
$this->db->createCommand()
            ->
delete($this->itemChildTable'parent=:name1 OR child=:name2', array(
                
':name1'=>$name,
                
':name2'=>$name
        
));
        
$this->db->createCommand()
            ->
delete($this->assignmentTable'itemname=:name', array(
                
':name'=>$name,
        ));
    }

    return 
$this->db->createCommand()
        ->
delete($this->itemTable'name=:name', array(
            
':name'=>$name
        
)) > 0;
}

绉婚櫎鎸囧畾鐨勬巿鏉冮」鐩

removeItemChild() 鏂规硶
public boolean removeItemChild(string $itemName, string $childName)
$itemName string 鐖堕」鐩悕瀛
$childName string 瀛愰」鐩悕瀛
{return} boolean 绉婚櫎鏄惁鎴愬姛
婧愮爜锛 framework/web/auth/CDbAuthManager.php#176 (鏄剧ず)
public function removeItemChild($itemName,$childName)
{
    return 
$this->db->createCommand()
        ->
delete($this->itemChildTable'parent=:parent AND child=:child', array(
            
':parent'=>$itemName,
            
':child'=>$childName
        
)) > 0;
}

绉婚櫎瀛愰」鐩 瑕佹敞鎰忕殑鏄紝瀛愰」鐩槸娌℃湁琚垹闄ょ殑銆傚彧鏄畠璺熺埗椤圭洰鐨勫叧绯昏В銆

revoke() 鏂规硶
public boolean revoke(string $itemName, mixed $userId)
$itemName string 椤圭洰鍚嶅瓧
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
{return} boolean 鎾ゆ秷鏄惁鎴愬姛
婧愮爜锛 framework/web/auth/CDbAuthManager.php#269 (鏄剧ず)
public function revoke($itemName,$userId)
{
    return 
$this->db->createCommand()
        ->
delete($this->assignmentTable'itemname=:itemname AND userid=:userid', array(
            
':itemname'=>$itemName,
            
':userid'=>$userId
        
)) > 0;
}

鎾ゆ秷鐢ㄦ埛鐨勬巿鏉冧换鍔°

save() 鏂规硶
public void save()
婧愮爜锛 framework/web/auth/CDbAuthManager.php#537 (鏄剧ず)
public function save()
{
}

灏嗘巿鏉冩暟鎹繚瀛樺埌鎸佷箙鍖栧瓨鍌ㄥ櫒銆

saveAuthAssignment() 鏂规硶
public void saveAuthAssignment(CAuthAssignment $assignment)
$assignment CAuthAssignment 宸茬粡淇敼杩囩殑浠诲姟銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#348 (鏄剧ず)
public function saveAuthAssignment($assignment)
{
    
$this->db->createCommand()
        ->
update($this->assignmentTable, array(
            
'bizrule'=>$assignment->getBizRule(),
            
'data'=>serialize($assignment->getData()),
        ), 
'itemname=:itemname AND userid=:userid', array(
            
'itemname'=>$assignment->getItemName(),
            
'userid'=>$assignment->getUserId()
        ));
}

淇濆瓨淇敼杩囩殑鎺堟潈浠诲姟銆

saveAuthItem() 鏂规硶
public void saveAuthItem(CAuthItem $item, string $oldName=NULL)
$item CAuthItem 瑕佷繚瀛樼殑椤圭洰銆
$oldName string 鏃х殑椤圭洰鍚嶅瓧銆傚鏋滀负null锛屾剰鍛崇潃椤圭洰鍚嶅瓧娌℃湁鏀瑰彉銆
婧愮爜锛 framework/web/auth/CDbAuthManager.php#498 (鏄剧ず)
public function saveAuthItem($item,$oldName=null)
{
    if(
$this->usingSqlite() && $oldName!==null && $item->getName()!==$oldName)
    {
        
$this->db->createCommand()
            ->
update($this->itemChildTable, array(
                
'parent'=>$item->getName(),
            ), 
'parent=:whereName', array(
                
':whereName'=>$oldName,
            ));
        
$this->db->createCommand()
            ->
update($this->itemChildTable, array(
                
'child'=>$item->getName(),
            ), 
'child=:whereName', array(
                
':whereName'=>$oldName,
            ));
        
$this->db->createCommand()
            ->
update($this->assignmentTable, array(
                
'itemname'=>$item->getName(),
            ), 
'itemname=:whereName', array(
                
':whereName'=>$oldName,
            ));
    }

    
$this->db->createCommand()
        ->
update($this->itemTable, array(
            
'name'=>$item->getName(),
            
'type'=>$item->getType(),
            
'description'=>$item->getDescription(),
            
'bizrule'=>$item->getBizRule(),
            
'data'=>serialize($item->getData()),
        ), 
'name=:whereName', array(
            
':whereName'=>$oldName===null?$item->getName():$oldName,
        ));
}

灏嗘巿鏉冮」鐩繚瀛樺埌鎸佷箙鍖栧瓨鍌ㄥ櫒銆

usingSqlite() 鏂规硶
protected boolean usingSqlite()
{return} boolean 鏁版嵁搴撴槸鍚︽槸SQLite
婧愮爜锛 framework/web/auth/CDbAuthManager.php#595 (鏄剧ず)
protected function usingSqlite()
{
    return 
$this->_usingSqlite;
}

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.