1.注册一个信号,同时传递参数(可以传递多个参数);
\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
2.在需要的地方接收信号,去对应的方法里面去执行函数,函数的参数是由emit发放传递过来的(可以多次调用注册的信号);
\OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_Team', 'post_deleteUser');
\OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_Agent', 'post_deleteUser');
3.定义具体的方法,在具体类下(OC_Team)定义具体的方法’post_deleteUser’;
class OC_Team{//OC_Team类
public static function post_deleteUser($parameters) {
$uid = $parameters['uid'];
foreach (OC_Team::getAdminsByUid($uid) as $tid) {
OC_Team::removeAdminFromTeam($uid, $tid);
}
foreach (OC_Team::getTeamsofUser($uid) as $tid) {
OC_Team::removeMemberFromTeam($uid, $tid);
}
return true;
}
}
//在具体类下(OC_Agent)定义具体的方法'post_deleteUser';
class OC_Agent{//OC_Agent类
public static function post_deleteUser($params)
{
$uid = $params['uid'];
$agentID = self::getUserAgent($uid);
self::removeAgentAdminUser($agentID, $uid);
self::removeAgentUser($agentID, $uid);
}
}