本文整理匯總了PHP中Symfony\Component\Security\Core\User\UserProviderInterface::createUser方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserProviderInterface::createUser方法的具體用法?PHP UserProviderInterface::createUser怎麽用?PHP UserProviderInterface::createUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Security\Core\User\UserProviderInterface
的用法示例。
在下文中一共展示了UserProviderInterface::createUser方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createUser
/**
* Create a user with the provided username.
*
* @param string $username
*
* @return UserInterface $user
*/
protected function createUser($username)
{
if (!$this->userProvider instanceof UserFactoryInterface) {
throw new AuthenticationServiceException("UserProvider must implement UserFactoryInterface to create unknown users.");
}
$user = $this->userProvider->createUser($username);
if (!$user instanceof UserInterface) {
throw new AuthenticationServiceException("The user provider must return a UserInterface object.");
}
return $user;
}
示例2: createUser
/**
* @throws AuthenticationServiceException
*
* @param string $username
* @param array $attributes
*
* @return UserInterface
*/
protected function createUser($username, array $attributes = array())
{
if (!$this->userProvider instanceof UserFactoryInterface) {
throw new AuthenticationServiceException('UserProvider must implement UserFactoryInterface to create unknown users.');
}
try {
$user = $this->userProvider->createUser($username, $this->createdUsersRoles, $attributes);
if (!$user instanceof UserInterface) {
throw new AuthenticationServiceException('The user provider must create an UserInterface object.');
}
} catch (\Exception $repositoryProblem) {
throw new AuthenticationServiceException($repositoryProblem->getMessage(), $username, 0, $repositoryProblem);
}
return $user;
}
示例3: createUser
/**
* Creates a new User.
*
* @param array $data
* @param bool $isOAuth
*
* @return UserInterface $user
*/
protected function createUser(array $data, UserProviderInterface $userManager)
{
$userIdentityfield = $this->container->getParameter('rch_jwt_user.user_identity_field');
$user = $userManager->createUser()->setUsername($data[$userIdentityfield])->setEmail($data[$userIdentityfield])->setEnabled(true)->setPlainPassword($data['password']);
if (isset($data['facebook_id'])) {
$user->setFacebookId($data['facebook_id']);
}
try {
$userManager->updateUser($user);
} catch (\Exception $e) {
$message = $e->getMessage() ?: 'An error occured while creating the user.';
throw new UserException(422, $message, $e);
}
return $user;
}