Yii Framework v1.1.10 绫诲弬鑰

CPhpAuthManager

system.web.auth
缁ф壙 class CPhpAuthManager » CAuthManager » CApplicationComponent » CComponent
瀹炵幇 IAuthManager, IApplicationComponent
婧愯嚜 1.0
鐗堟湰 $Id: CPhpAuthManager.php 3515 2011-12-28 12:29:24Z mdomba $
婧愮爜 framework/web/auth/CPhpAuthManager.php
CPhpAuthManager浠h〃鎺堟潈淇℃伅瀛樺偍鍦ㄤ竴涓狿HP鏂囦欢鐨勬巿鏉冪鐞嗗櫒銆

鎺堟潈鏁版嵁鍦ㄦ寚瀹氱殑鏂囦欢authFile 閲岄潰淇濆瓨锛忓姞杞斤紝 榛樿鏄檖rotected/data/auth.php鈥樸

CPhpAuthManager涓昏鏄簲鐢ㄥ湪鎺堟潈鏁版嵁涓嶅鐨勬儏鍐典笅 锛堝锛屼釜浜哄崥瀹㈢郴缁熺殑鎺堟潈淇℃伅锛夈 濡傛灉鏄瘮杈冨鏉傜殑鎺堟潈鏁版嵁锛屽簲璇ヤ娇鐢CDbAuthManager

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
authFile string 鍖呭惈鎺堟潈鏁版嵁鐨凱HP鏂囦欢璺緞銆 濡傛灉娌℃湁璁剧疆锛屽畠浼氫娇鐢ㄢ榩rotected/data/auth. CPhpAuthManager
authItems array 杩斿洖鎸囧畾绫诲瀷鍜岀敤鎴风殑鎺堟潈椤圭洰銆 CPhpAuthManager
behaviors array 杩欎釜搴旂敤缁勪欢闄勫姞鐨勮涓恒 杩欐琛屼负灏嗗湪搴旂敤缁勪欢璋冪敤init鏃堕檮鍔犲湪搴旂敤缁勪欢涓娿 璇峰弬鐓CModel::behaviors濡備綍鎸囧畾姝ゅ睘鎬у笺 CApplicationComponent
defaultRoles array 闅愬紡璧嬩簣缁欐墍鏈夌敤鎴风殑瑙掕壊鍚嶅瓧鍒楄〃銆 杩欎簺瑙掕壊涓嶉渶瑕佹樉寮忚祴浜堢粰鎵鏈夌敤鎴枫 褰撹皟鐢checkAccess锛屼細棣栧厛妫鏌ヨ繖浜涜鑹层 涓轰簡鑳藉鎻愰珮绋嬪簭鏁堢巼锛岃繖鏍风殑瑙掕壊瓒婂皯瓒婂ソ銆 涓涓吀鍨嬬殑鐢ㄦ硶鏄紝瀹氫箟涓涓渁uthenticated鈥濊鑹诧紝鐒跺悗 鎶婂畠鍏宠仈鍒颁竴涓笟鍔¢昏緫瑙勫垯锛岃繖涓鍒欐槸鐢ㄦ潵楠岃瘉褰撳墠鐢ㄦ埛鐨勩 鐒跺悗鍦ㄨ繖涓睘鎬у0鏄庘渁uthenticated鈥濅互渚垮簲鐢ㄥ埌 鎵鏈夌殑楠岃瘉鐢ㄦ埛銆 CAuthManager
isInitialized boolean 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
operations array 杩斿洖鎿嶄綔銆 CAuthManager
roles array 杩斿洖瑙掕壊銆 CAuthManager
showErrors boolean 鍏佽涓氬姟瑙勫垯閿欒鎶ュ憡銆 CAuthManager
tasks array 杩斿洖浠诲姟銆 CAuthManager

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
addItemChild() 娣诲姞涓涓巿鏉冮」鐩綔涓哄彟涓涓巿鏉冮」鐨勫瓙鎺堟潈椤圭洰銆 CPhpAuthManager
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
assign() 涓虹敤鎴峰垎閰嶄竴涓巿鏉冮」鐩 CPhpAuthManager
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
checkAccess() 妫鏌ユ寚瀹氱敤鎴风殑鎵ц鏉冮檺銆 CPhpAuthManager
clearAll() 绉婚櫎鎵鏈夋巿鏉冩暟鎹 CPhpAuthManager
clearAuthAssignments() 绉婚櫎鎵鏈夋巿鏉冨垎閰嶄俊鎭 CPhpAuthManager
createAuthItem() 鍒涘缓涓涓巿鏉冮」鐩 CPhpAuthManager
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() 杩斿洖椤圭洰浠诲姟淇℃伅銆 CPhpAuthManager
getAuthAssignments() 杩斿洖鎸囧畾鐢ㄦ埛鐨勯」鐩换鍔° CPhpAuthManager
getAuthItem() 杩斿洖鎸囧畾鍚嶅瓧鐨勬巿鏉冮」鐩 CPhpAuthManager
getAuthItems() 杩斿洖鎸囧畾绫诲瀷鍜岀敤鎴风殑鎺堟潈椤圭洰銆 CPhpAuthManager
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIsInitialized() 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
getItemChildren() 杩斿洖鎸囧畾椤圭洰鐨勫瓙椤圭洰 CPhpAuthManager
getOperations() 杩斿洖鎿嶄綔銆 CAuthManager
getRoles() 杩斿洖瑙掕壊銆 CAuthManager
getTasks() 杩斿洖浠诲姟銆 CAuthManager
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasItemChild() 杩斿洖鍊艰鏄庣埗鎺堟潈椤圭洰鏄惁鍖呭惈瀛愭巿鏉冮」鐩 CPhpAuthManager
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() 鍒濆鍖栧簲鐢ㄧ粍浠躲 CPhpAuthManager
isAssigned() 杩斿洖鍊艰鏄庤繖涓」鐩槸鍚﹀凡缁忚祴浜堢粰鐢ㄦ埛銆 CPhpAuthManager
load() 鍔犺浇鎺堟潈鏁版嵁銆 CPhpAuthManager
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
removeAuthItem() 绉婚櫎鎸囧畾鐨勬巿鏉冮」鐩 CPhpAuthManager
removeItemChild() 绉婚櫎瀛愰」鐩 CPhpAuthManager
revoke() 鎾ゆ秷鐢ㄦ埛鐨勬巿鏉冧换鍔° CPhpAuthManager
save() 灏嗘巿鏉冩暟鎹繚瀛樺埌鎸佷箙鍖栧瓨鍌ㄥ櫒銆 CPhpAuthManager
saveAuthAssignment() 淇濆瓨淇敼鐨勬巿鏉冧俊鎭 CPhpAuthManager
saveAuthItem() 灏嗘巿鏉冮」鐩繚瀛樺埌鎸佷箙鍖栧瓨鍌ㄥ櫒銆 CPhpAuthManager

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
checkItemChildType() 妫鏌ラ」鐩被鍨嬩互纭畾涓涓瓙椤圭洰宸茬粡璧嬩簣缁欎竴涓埗椤圭洰銆 CAuthManager
detectLoop() 妫鏌ユ巿鏉冮」鐩眰绾ф槸鍚﹀瓨鍦ㄥ惊鐜 CPhpAuthManager
loadFromFile() 浠嶱HP鏂囦欢鍔犺浇鎺堟潈鏁版嵁銆 CPhpAuthManager
saveToFile() 淇濆瓨鎺堟潈鏁版嵁鍒癙HP鏂囦欢銆 CPhpAuthManager

灞炴ц缁

authFile 灞炴
public string $authFile;

鍖呭惈鎺堟潈鏁版嵁鐨凱HP鏂囦欢璺緞銆 濡傛灉娌℃湁璁剧疆锛屽畠浼氫娇鐢ㄢ榩rotected/data/auth.php鈥欎綔涓烘暟鎹枃浠躲 濡傛灉闇瑕佷慨鏀规巿鏉冩暟鎹紝瑕佺‘淇濈綉缁滄湇鍔¤繘绋嬪璇ユ枃浠 鏈夊啓鐨勬潈闄愩

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

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

鏂规硶璇︾粏

addItemChild() 鏂规硶
public boolean addItemChild(string $itemName, string $childName)
$itemName string 鐖堕」鐩悕瀛
$childName string 瀛愰」鐩悕瀛
{return} boolean 鏄惁娣诲姞鎴愬姛
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#98 (鏄剧ず)
public function addItemChild($itemName,$childName)
{
    if(!isset(
$this->_items[$childName],$this->_items[$itemName]))
        throw new 
CException(Yii::t('yii','Either "{parent}" or "{child}" does not exist.',array('{child}'=>$childName,'{name}'=>$itemName)));
    
$child=$this->_items[$childName];
    
$item=$this->_items[$itemName];
    
$this->checkItemChildType($item->getType(),$child->getType());
    if(
$this->detectLoop($itemName,$childName))
        throw new 
CException(Yii::t('yii','Cannot add "{child}" as a child of "{parent}". A loop has been detected.',
            array(
'{child}'=>$childName,'{parent}'=>$itemName)));
    if(isset(
$this->_children[$itemName][$childName]))
        throw new 
CException(Yii::t('yii','The item "{parent}" already has a child "{child}".',
            array(
'{child}'=>$childName,'{parent}'=>$itemName)));
    
$this->_children[$itemName][$childName]=$this->_items[$childName];
    return 
true;
}

娣诲姞涓涓巿鏉冮」鐩綔涓哄彟涓涓巿鏉冮」鐨勫瓙鎺堟潈椤圭洰銆

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/CPhpAuthManager.php#174 (鏄剧ず)
public function assign($itemName,$userId,$bizRule=null,$data=null)
{
    if(!isset(
$this->_items[$itemName]))
        throw new 
CException(Yii::t('yii','Unknown authorization item "{name}".',array('{name}'=>$itemName)));
    else if(isset(
$this->_assignments[$userId][$itemName]))
        throw new 
CException(Yii::t('yii','Authorization item "{item}" has already been assigned to user "{user}".',
            array(
'{item}'=>$itemName,'{user}'=>$userId)));
    else
        return 
$this->_assignments[$userId][$itemName]=new CAuthAssignment($this,$itemName,$userId,$bizRule,$data);
}

涓虹敤鎴峰垎閰嶄竴涓巿鏉冮」鐩

checkAccess() 鏂规硶
public boolean checkAccess(string $itemName, mixed $userId, array $params=array ( ))
$itemName string 闇瑕佹潈闄愭鏌ョ殑鎺堟潈椤瑰悕绉
$userId mixed 鐢ㄦ埛ID銆傚畠搴旇鏄竴涓暣鏁版垨涓涓瓧绗︿覆,浠h〃鐢ㄦ埛鐨勫敮涓鏍囪瘑 璇︽儏璇峰弬鑰IWebUser::getId
$params array 鍒嗛厤缁欑敤鎴风殑浠诲姟鎴栬鑹茬殑 锛堥敭锛嶅煎锛夊舰寮忕殑涓氬姟瑙勫垯銆
{return} boolean 鐢ㄦ埛鏄惁鏈夋潈鎵ц鎿嶄綔銆
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#66 (鏄剧ず)
public function checkAccess($itemName,$userId,$params=array())
{
    if(!isset(
$this->_items[$itemName]))
        return 
false;
    
$item=$this->_items[$itemName];
    
Yii::trace('Checking permission "'.$item->getName().'"','system.web.auth.CPhpAuthManager');
    if(
$this->executeBizRule($item->getBizRule(),$params,$item->getData()))
    {
        if(
in_array($itemName,$this->defaultRoles))
            return 
true;
        if(isset(
$this->_assignments[$userId][$itemName]))
        {
            
$assignment=$this->_assignments[$userId][$itemName];
            if(
$this->executeBizRule($assignment->getBizRule(),$params,$assignment->getData()))
                return 
true;
        }
        foreach(
$this->_children as $parentName=>$children)
        {
            if(isset(
$children[$itemName]) && $this->checkAccess($parentName,$userId,$params))
                return 
true;
        }
    }
    return 
false;
}

妫鏌ユ寚瀹氱敤鎴风殑鎵ц鏉冮檺銆

clearAll() 鏂规硶
public void clearAll()
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#444 (鏄剧ず)
public function clearAll()
{
    
$this->clearAuthAssignments();
    
$this->_children=array();
    
$this->_items=array();
}

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

clearAuthAssignments() 鏂规硶
public void clearAuthAssignments()
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#454 (鏄剧ず)
public function clearAuthAssignments()
{
    
$this->_assignments=array();
}

绉婚櫎鎵鏈夋巿鏉冨垎閰嶄俊鎭

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/CPhpAuthManager.php#284 (鏄剧ず)
public function createAuthItem($name,$type,$description='',$bizRule=null,$data=null)
{
    if(isset(
$this->_items[$name]))
        throw new 
CException(Yii::t('yii','Unable to add an item whose name is the same as an existing item.'));
    return 
$this->_items[$name]=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/CPhpAuthManager.php#465 (鏄剧ず)
protected function detectLoop($itemName,$childName)
{
    if(
$childName===$itemName)
        return 
true;
    if(!isset(
$this->_children[$childName], $this->_items[$itemName]))
        return 
false;

    foreach(
$this->_children[$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/CPhpAuthManager.php#220 (鏄剧ず)
public function getAuthAssignment($itemName,$userId)
{
    return isset(
$this->_assignments[$userId][$itemName])?$this->_assignments[$userId][$itemName]:null;
}

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

getAuthAssignments() 鏂规硶
public array getAuthAssignments(mixed $userId)
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
{return} array 鐢ㄦ埛鐨勯」鐩换鍔′俊鎭傚鏋滄病鏈夐」鐩祴浜堢粰鐢ㄦ埛锛 鍒欒繑鍥瀗ull銆
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#231 (鏄剧ず)
public function getAuthAssignments($userId)
{
    return isset(
$this->_assignments[$userId])?$this->_assignments[$userId]:array();
}

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

getAuthItem() 鏂规硶
public CAuthItem getAuthItem(string $name)
$name string 椤圭洰鍚嶅瓧
{return} CAuthItem 鎺堟潈椤圭洰銆傚鏋滄壘涓嶅埌璇ラ」鐩紝鍒欒繑鍥瀗ull銆
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#316 (鏄剧ず)
public function getAuthItem($name)
{
    return isset(
$this->_items[$name])?$this->_items[$name]: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/CPhpAuthManager.php#244 (鏄剧ず)
public function getAuthItems($type=null,$userId=null)
{
    if(
$type===null && $userId===null)
        return 
$this->_items;
    
$items=array();
    if(
$userId===null)
    {
        foreach(
$this->_items as $name=>$item)
        {
            if(
$item->getType()==$type)
                
$items[$name]=$item;
        }
    }
    else if(isset(
$this->_assignments[$userId]))
    {
        foreach(
$this->_assignments[$userId] as $assignment)
        {
            
$name=$assignment->getItemName();
            if(isset(
$this->_items[$name]) && ($type===null || $this->_items[$name]->getType()==$type))
                
$items[$name]=$this->_items[$name];
        }
    }
    return 
$items;
}

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

getItemChildren() 鏂规硶
public array getItemChildren(mixed $names)
$names mixed 鐖堕」鐩悕瀛椼傚彲浠ユ槸瀛楃涓叉垨鑰呮暟缁勩 濡傛灉鏄悗鑰咃紝閭d箞瀹冩槸椤圭洰鍚嶅瓧鍒楄〃銆
{return} array 鐖堕」鐩殑鎵鏈夊瓙椤圭洰
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#150 (鏄剧ず)
public function getItemChildren($names)
{
    if(
is_string($names))
        return isset(
$this->_children[$names]) ? $this->_children[$names] : array();

    
$children=array();
    foreach(
$names as $name)
    {
        if(isset(
$this->_children[$name]))
            
$children=array_merge($children,$this->_children[$name]);
    }
    return 
$children;
}

杩斿洖鎸囧畾椤圭洰鐨勫瓙椤圭洰

hasItemChild() 鏂规硶
public boolean hasItemChild(string $itemName, string $childName)
$itemName string 鐖堕」鐩悕瀛
$childName string 瀛愰」鐩悕瀛
{return} boolean 瀛愰」鐩槸鍚﹀瓨鍦
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#139 (鏄剧ず)
public function hasItemChild($itemName,$childName)
{
    return isset(
$this->_children[$itemName][$childName]);
}

杩斿洖鍊艰鏄庣埗鎺堟潈椤圭洰鏄惁鍖呭惈瀛愭巿鏉冮」鐩

init() 鏂规硶
public void init()
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#49 (鏄剧ず)
public function init()
{
    
parent::init();
    if(
$this->authFile===null)
        
$this->authFile=Yii::getPathOfAlias('application.data.auth').'.php';
    
$this->load();
}

鍒濆鍖栧簲鐢ㄧ粍浠躲 杩欎釜鏂规硶鏄鐩栫埗绫荤殑鏂规硶锛屼粠PHP鏂囦欢 鍔犺浇鎺堟潈鏁版嵁銆

isAssigned() 鏂规硶
public boolean isAssigned(string $itemName, mixed $userId)
$itemName string 椤圭洰鍚嶅瓧
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
{return} boolean 杩欎釜椤圭洰鏄惁宸茬粡璧嬩簣缁欑敤鎴枫
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#208 (鏄剧ず)
public function isAssigned($itemName,$userId)
{
    return isset(
$this->_assignments[$userId][$itemName]);
}

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

load() 鏂规硶
public void load()
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#412 (鏄剧ず)
public function load()
{
    
$this->clearAll();

    
$items=$this->loadFromFile($this->authFile);

    foreach(
$items as $name=>$item)
        
$this->_items[$name]=new CAuthItem($this,$name,$item['type'],$item['description'],$item['bizRule'],$item['data']);

    foreach(
$items as $name=>$item)
    {
        if(isset(
$item['children']))
        {
            foreach(
$item['children'] as $childName)
            {
                if(isset(
$this->_items[$childName]))
                    
$this->_children[$name][$childName]=$this->_items[$childName];
            }
        }
        if(isset(
$item['assignments']))
        {
            foreach(
$item['assignments'] as $userId=>$assignment)
            {
                
$this->_assignments[$userId][$name]=new CAuthAssignment($this,$name,$userId,$assignment['bizRule'],$assignment['data']);
            }
        }
    }
}

鍔犺浇鎺堟潈鏁版嵁銆

loadFromFile() 鏂规硶
protected array loadFromFile(string $file)
$file string 鏂囦欢璺緞銆
{return} array 鎺堟潈鏁版嵁銆
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#486 (鏄剧ず)
protected function loadFromFile($file)
{
    if(
is_file($file))
        return require(
$file);
    else
        return array();
}

浠嶱HP鏂囦欢鍔犺浇鎺堟潈鏁版嵁銆

鍙傝

removeAuthItem() 鏂规硶
public boolean removeAuthItem(string $name)
$name string 瑕佺Щ闄ょ殑椤圭洰鍚嶅瓧
{return} boolean 瀛樺偍鍣ㄥ瓨鍦ㄧ殑椤圭洰鏄惁宸茬粡绉婚櫎鎴愬姛銆
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#296 (鏄剧ず)
public function removeAuthItem($name)
{
    if(isset(
$this->_items[$name]))
    {
        foreach(
$this->_children as &$children)
            unset(
$children[$name]);
        foreach(
$this->_assignments as &$assignments)
            unset(
$assignments[$name]);
        unset(
$this->_items[$name]);
        return 
true;
    }
    else
        return 
false;
}

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

removeItemChild() 鏂规硶
public boolean removeItemChild(string $itemName, string $childName)
$itemName string 鐖堕」鐩悕瀛
$childName string 瀛愰」鐩悕瀛
{return} boolean 鏄惁鍒犻櫎鎴愬姛
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#122 (鏄剧ず)
public function removeItemChild($itemName,$childName)
{
    if(isset(
$this->_children[$itemName][$childName]))
    {
        unset(
$this->_children[$itemName][$childName]);
        return 
true;
    }
    else
        return 
false;
}

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

revoke() 鏂规硶
public boolean revoke(string $itemName, mixed $userId)
$itemName string 椤圭洰鍚嶅瓧
$userId mixed 鐢ㄦ埛ID锛堣鎯呰鍙傝IWebUser::getId锛夈
{return} boolean 鎾ゆ秷鏄惁鎴愬姛
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#191 (鏄剧ず)
public function revoke($itemName,$userId)
{
    if(isset(
$this->_assignments[$userId][$itemName]))
    {
        unset(
$this->_assignments[$userId][$itemName]);
        return 
true;
    }
    else
        return 
false;
}

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

save() 鏂规硶
public void save()
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#374 (鏄剧ず)
public function save()
{
    
$items=array();
    foreach(
$this->_items as $name=>$item)
    {
        
$items[$name]=array(
            
'type'=>$item->getType(),
            
'description'=>$item->getDescription(),
            
'bizRule'=>$item->getBizRule(),
            
'data'=>$item->getData(),
        );
        if(isset(
$this->_children[$name]))
        {
            foreach(
$this->_children[$name] as $child)
                
$items[$name]['children'][]=$child->getName();
        }
    }

    foreach(
$this->_assignments as $userId=>$assignments)
    {
        foreach(
$assignments as $name=>$assignment)
        {
            if(isset(
$items[$name]))
            {
                
$items[$name]['assignments'][$userId]=array(
                    
'bizRule'=>$assignment->getBizRule(),
                    
'data'=>$assignment->getData(),
                );
            }
        }
    }

    
$this->saveToFile($items,$this->authFile);
}

灏嗘巿鏉冩暟鎹繚瀛樺埌鎸佷箙鍖栧瓨鍌ㄥ櫒銆 濡傛灉鎺堟潈鏁版嵁鏈変换浣曟敼鍙橈紝 璇风‘淇濅綘璋冪敤鐨勮繖涓柟娉曡兘灏嗘敼鍙樻暟鎹繚瀛樺埌鎸佷箙瀛樺偍銆

saveAuthAssignment() 鏂规硶
public void saveAuthAssignment(CAuthAssignment $assignment)
$assignment CAuthAssignment 宸茬粡淇敼鐨勬巿鏉冧俊鎭
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#365 (鏄剧ず)
public function saveAuthAssignment($assignment)
{
}

淇濆瓨淇敼鐨勬巿鏉冧俊鎭

saveAuthItem() 鏂规硶
public void saveAuthItem(CAuthItem $item, string $oldName=NULL)
$item CAuthItem 瑕佷繚瀛樼殑椤圭洰銆
$oldName string 鏃х殑椤圭洰鍚嶅瓧銆傚鏋滀负null锛屾剰鍛崇潃椤圭洰鍚嶅瓧娌℃湁鏀瑰彉銆
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#326 (鏄剧ず)
public function saveAuthItem($item,$oldName=null)
{
    if(
$oldName!==null && ($newName=$item->getName())!==$oldName// name changed
    
{
        if(isset(
$this->_items[$newName]))
            throw new 
CException(Yii::t('yii','Unable to change the item name. The name "{name}" is already used by another item.',array('{name}'=>$newName)));
        if(isset(
$this->_items[$oldName]) && $this->_items[$oldName]===$item)
        {
            unset(
$this->_items[$oldName]);
            
$this->_items[$newName]=$item;
            if(isset(
$this->_children[$oldName]))
            {
                
$this->_children[$newName]=$this->_children[$oldName];
                unset(
$this->_children[$oldName]);
            }
            foreach(
$this->_children as &$children)
            {
                if(isset(
$children[$oldName]))
                {
                    
$children[$newName]=$children[$oldName];
                    unset(
$children[$oldName]);
                }
            }
            foreach(
$this->_assignments as &$assignments)
            {
                if(isset(
$assignments[$oldName]))
                {
                    
$assignments[$newName]=$assignments[$oldName];
                    unset(
$assignments[$oldName]);
                }
            }
        }
    }
}

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

saveToFile() 鏂规硶
protected void saveToFile(array $data, string $file)
$data array 鎺堟潈鏁版嵁
$file string 鏂囦欢璺緞銆
婧愮爜锛 framework/web/auth/CPhpAuthManager.php#500 (鏄剧ず)
protected function saveToFile($data,$file)
{
    
file_put_contents($file,"<?php\nreturn ".var_export($data,true).";\n");
}

淇濆瓨鎺堟潈鏁版嵁鍒癙HP鏂囦欢銆

鍙傝

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