ADmad\HybridAuth\Auth\HybridAuthAuthenticate::_getUser PHP Method

_getUser() protected method

If app user record is not found a 'HybridAuth.newUser' event is dispatched with profile info from HyridAuth. The event listener should create associated user record and return user entity as event result.
protected _getUser ( Hybrid_Provider_Model $adapter ) : array
$adapter Hybrid_Provider_Model Hybrid auth adapter instance.
return array User record
    protected function _getUser($adapter)
    {
        try {
            $providerProfile = $adapter->getUserProfile();
            $this->adapter($adapter);
            $this->profile($providerProfile);
        } catch (\Exception $e) {
            $adapter->logout();
            throw $e;
        }
        $config = $this->_config;
        $userModel = $this->_userModel;
        $user = null;
        $profile = $this->_query($providerProfile->identifier)->first();
        if ($profile) {
            $userId = $profile->get($config['profileModelFkField']);
            $user = $this->_userModel->find($config['finder'])->where([$userModel->aliasField($userModel->primaryKey()) => $userId])->first();
            // User record exists but finder conditions did not match,
            // so just update social profile record and return false.
            if (!$user) {
                $profile = $this->_profileEntity($profile);
                if (!$this->_profileModel->save($profile)) {
                    throw new \RuntimeException('Unable to save social profile.');
                }
                return false;
            }
        } elseif ($providerProfile->email) {
            $user = $this->_userModel->find($config['finder'])->where([$this->_userModel->aliasField($config['fields']['email']) => $providerProfile->email])->first();
        }
        $profile = $this->_profileEntity($profile);
        if (!$user) {
            $user = $this->_newUser($profile);
        }
        $profile->{$config['profileModelFkField']} = $user->{$userModel->primaryKey()};
        $profile = $this->_profileModel->save($profile);
        if (!$profile) {
            throw new \RuntimeException('Unable to save social profile.');
        }
        $user->set('social_profile', $profile);
        $user->unsetProperty($config['fields']['password']);
        return $user->toArray();
    }