本文整理汇总了PHP中kernel::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP kernel::getInstance方法的具体用法?PHP kernel::getInstance怎么用?PHP kernel::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kernel
的用法示例。
在下文中一共展示了kernel::getInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isRegisterActive
public static function isRegisterActive()
{
$meta = MetaManager::getInstance()->retrieveMeta(kernel::getInstance('SecurityManager'))->getAll();
if (isset($meta['register']) && $meta['register'] == 'true') {
return 1;
}
return 0;
}
示例2: register
public static function register($params)
{
/* verify permissions again */
$meta = MetaManager::getInstance()->retrieveMeta(kernel::getInstance('SecurityManager'))->getAll();
if (isset($meta['register']) && $meta['register'] == 'false') {
return 'unable to register';
}
$procManager = ProcManager::getInstance();
$savedLoginContext = $procManager->getCurrentProcess()->getLoginContext();
try {
$name = $params[0];
$surname = $params[1];
$username = $params[2];
$password = $params[3];
$email = $params[4];
if (!$name || !$surname || !$username || !$password || !$email) {
return 'incomplete';
}
$myUManager = UMManager::getInstance();
// check existence
$exists = false;
try {
$myUManager->getUserByName($username);
$exists = true;
} catch (EyeNoSuchUserException $e) {
}
if ($exists) {
throw new EyeUserAlreadyExistsException('User with name "' . $username . '" already exists.');
}
$meta = new BasicMetaData();
$meta->set('eyeos.user.email', $email);
$userIds = MetaManager::getInstance()->searchMeta(new EyeosUser(), $meta);
if (count($userIds) != 0) {
throw new EyeUserAlreadyExistsException('User with email "' . $email . '" already exists.');
}
//create the user
$user = $myUManager->getNewUserInstance();
$user->setName($username);
$user->setPassword($password, true);
$user->setPrimaryGroupId($myUManager->getGroupByName(SERVICE_UM_DEFAULTUSERSGROUP)->getId());
$myUManager->createUser($user);
//login in the system with new user, if this works, for sure the user exists, even with the
//most complex and strange errors
$myUManager = UMManager::getInstance();
$subject = new Subject();
$loginContext = new LoginContext('eyeos-login', $subject);
$cred = new EyeosPasswordCredential();
$cred->setUsername($username);
$cred->setPassword($password, true);
$subject->getPrivateCredentials()->append($cred);
$loginContext->login();
//we are logged in, so we are going to change the credentials of login
$procManager = ProcManager::getInstance();
$procList = $procManager->getProcessesList();
$currentProcess = $procManager->getCurrentProcess();
$procManager->setProcessLoginContext($currentProcess->getPid(), $loginContext);
foreach ($procList as $key => $value) {
if (strtolower($value) == 'login') {
//we are in another login in execution, this is a refresh, lets see
//if the login was correct with the old login.
$loginProcess = $procManager->getProcessByPid($key);
$procManager->setProcessLoginContext($loginProcess->getPid(), $loginContext);
}
}
// save basic metadata from form
$userMeta = MetaManager::getInstance()->retrieveMeta($user);
$userMeta->set('eyeos.user.firstname', strip_tags($name));
$userMeta->set('eyeos.user.lastname', strip_tags($surname));
$userMeta->set('eyeos.user.email', $email);
$userMeta = MetaManager::getInstance()->storeMeta($user, $userMeta);
return 'success';
} catch (Exception $e) {
// ROLLBACK
// restore login context (root probably)
$procManager->setProcessLoginContext($procManager->getCurrentProcess()->getPid(), $savedLoginContext);
//// delete invalid user created
// if (isset($user) && $user instanceof IPrincipal) {
// try {
// UMManager::getInstance()->deletePrincipal($user);
// } catch (Exception $e2) {}
// }
throw $e;
}
}