本文整理汇总了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;
}