本文整理汇总了PHP中eZUser::setUserCache方法的典型用法代码示例。如果您正苦于以下问题:PHP eZUser::setUserCache方法的具体用法?PHP eZUser::setUserCache怎么用?PHP eZUser::setUserCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZUser
的用法示例。
在下文中一共展示了eZUser::setUserCache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: instance
/**
* Returns a shared instance of the eZUser class pr $id value.
* If user can not be fetched, then anonymous user is returned and
* a warning trown, if anonymous user can not be fetched, then NoUser
* is returned and another warning is thrown.
*
* @param int|false $id On false: Gets current user id from session
* or from {@link eZUser::anonymousId()} if not set.
* @return eZUser
*/
static function instance($id = false)
{
if (!empty($GLOBALS["eZUserGlobalInstance_{$id}"])) {
return $GLOBALS["eZUserGlobalInstance_{$id}"];
}
$userId = $id;
$currentUser = null;
$http = eZHTTPTool::instance();
$anonymousUserID = self::anonymousId();
$sessionHasStarted = eZSession::hasStarted();
// If not specified get the current user
if ($userId === false) {
if ($sessionHasStarted) {
$userId = $http->sessionVariable('eZUserLoggedInID');
if (!is_numeric($userId)) {
$userId = $anonymousUserID;
eZSession::setUserID($userId);
$http->setSessionVariable('eZUserLoggedInID', $userId);
}
} else {
$userId = $anonymousUserID;
eZSession::setUserID($userId);
}
}
// Check user cache (this effectivly fetches user from cache)
// user not found if !isset( isset( $userCache['info'][$userId] ) )
$userCache = self::getUserCacheByUserId($userId);
if (isset($userCache['info'][$userId])) {
$userArray = $userCache['info'][$userId];
if (is_numeric($userArray['contentobject_id'])) {
$currentUser = new eZUser($userArray);
$currentUser->setUserCache($userCache);
}
}
$ini = eZINI::instance();
// Check if:
// - the user has not logged out,
// - the user is not logged in,
// - and if a automatic single sign on plugin is enabled.
if (!self::$userHasLoggedOut && is_object($currentUser) && !$currentUser->isRegistered()) {
$ssoHandlerArray = $ini->variable('UserSettings', 'SingleSignOnHandlerArray');
if (!empty($ssoHandlerArray)) {
$ssoUser = false;
foreach ($ssoHandlerArray as $ssoHandler) {
$className = 'eZ' . $ssoHandler . 'SSOHandler';
if (class_exists($className)) {
$impl = new $className();
$ssoUser = $impl->handleSSOLogin();
// If a user was found via SSO, then use it
if ($ssoUser !== false) {
$currentUser = $ssoUser;
$userId = $currentUser->attribute('contentobject_id');
$userInfo = array();
$userInfo[$userId] = array('contentobject_id' => $userId, 'login' => $currentUser->attribute('login'), 'email' => $currentUser->attribute('email'), 'password_hash' => $currentUser->attribute('password_hash'), 'password_hash_type' => $currentUser->attribute('password_hash_type'));
eZSession::setUserID($userId);
$http->setSessionVariable('eZUserLoggedInID', $userId);
eZUser::updateLastVisit($userId);
eZUser::setCurrentlyLoggedInUser($currentUser, $userId);
eZHTTPTool::redirect(eZSys::wwwDir() . eZSys::indexFile(false) . eZSys::requestURI() . eZSys::queryString(), array(), 302);
eZExecution::cleanExit();
}
} else {
eZDebug::writeError("Undefined ssoHandler class: {$className}", __METHOD__);
}
}
}
}
if ($userId != $anonymousUserID) {
$sessionInactivityTimeout = $ini->variable('Session', 'ActivityTimeout');
if (!isset($GLOBALS['eZSessionIdleTime'])) {
eZUser::updateLastVisit($userId);
} else {
$sessionIdle = $GLOBALS['eZSessionIdleTime'];
if ($sessionIdle > $sessionInactivityTimeout) {
eZUser::updateLastVisit($userId);
}
}
}
if (!$currentUser) {
$currentUser = eZUser::fetch(self::anonymousId());
eZDebug::writeWarning('User not found, returning anonymous');
}
if (!$currentUser) {
$currentUser = new eZUser(array('id' => -1, 'login' => 'NoUser'));
eZDebug::writeWarning('Anonymous user not found, returning NoUser');
}
$GLOBALS["eZUserGlobalInstance_{$id}"] = $currentUser;
return $currentUser;
}