Tries to find account, otherwise creates new account.

@param BaseClientInterface $client

@return Account
@throws \yii\base\InvalidConfigException
482977
protected static function fetchAccount(BaseClientInterface $client) {
    $account = self::find()->byClient($client)->one();

    if (null === $account) {
      /** @var Account $account */
      $account = Yii::createObject([
        'class' => Account::className(),
        'provider' => $client->getId(),
        'clientId' => $client->getUserAttributes()['id'],
        'data' => Json::encode($client->getUserAttributes()),
      ]);
      $account->save(false);
    }

    return $account;
  }
1278637
protected function getClient() {
        if ($this->client === null) {
            $this->client = new Client($this->getParam('accountId'), $this->getParam('applicationKey'));
        }

        return $this->client;
    }
487323
public function execute(Client $client)
    {
        if (!$this->request instanceof Request) {
            throw new \InvalidArgumentException('request is not an instanceof \GuzzleHttp\Message\Request');
        }

        $this->copyClientDefaults($client);

        return $client->send($this->request);
    }
343616
public function findOneByClientAndRefreshToken(ApiClientInterface $client, $refreshToken)
    {
        $qb = $this->createQueryBuilder();

        $qb->field('client.id')->equals($client->getId());
        $qb->field('refreshCode')->equals($refreshToken);
        $qb->limit(1);

        return $qb->getQuery()->getSingleResult();
    }
692976
public function remove(Client $client)
    {
        $clientId = $client->getId();
        if (!isset($this->clients[$clientId])) {
            return $this;
        }

        $requestId = $client->getRequest();
        $this->removeClientForRequest($clientId, $requestId);
        unset($this->clients[$clientId]);

        return $this;
    }
125653
protected function authOpenId($client)
    {
        $request = Yii::$app->getRequest();
        $mode = $request->get('openid_mode', $request->post('openid_mode'));

        if (empty($mode)) {
            $url = $client->buildAuthUrl();
            return Yii::$app->getResponse()->redirect($url);
        }

        switch ($mode) {
            case 'id_res':
                if ($client->validate()) {
                    return $this->authSuccess($client);
                }
                throw new HttpException(400, 'Unable to complete the authentication because the required data was not received.');
            case 'cancel':
                return $this->authCancel($client);
            default:
                throw new HttpException(400);
        }
    }
596007
protected function createClient($client)
    {
        try {
            new \ReflectionClass($client);
        } catch (\ReflectionException $e) {
            throw new FoundationException(sprintf("Could not load class '%s'.", $client), null, $e);
        }

        $client_instance = new $client();

        return $client_instance;
    }
58164
public function registerClient(ClientInterface $client)
    {
        $client->initialize($this);
        $this->client_holder->add($client);
        $this->hasLogger() && $this->getLogger()->debug(
            "Pomm: Registering new client",
            [
                'type' => $client->getClientType(),
                'identifier' => $client->getClientIdentifier(),
            ]
        );

        return $this;
    }
721575
protected function getClient(): HttpClient
    {
        if ($this->client === null) {
            $this->client = new HttpClient($this->getClientConfig());
        }

        return $this->client;
    }
816285
private function getClient(): Client
    {
        if (null !== $this->client) {
            return $this->client;
        }

        return $this->client = new Client(
            $this->config['carrier'],
            $this->config['key'],
            $this->config['cache'],
            $this->config['debug']
        );
    }
559008
public function client($client = null)
    {
        if (!func_num_args()) {
            return $this->_client;
        }
        $this->_client = $client;
        return $this;
    }
35994
protected function getClientId($client)
    {
        if ($client instanceof Client) {
            if (!empty($client->id)) {
                $id = $client->id;
            } elseif (!empty($client->email)) {
                $id = $this->api->searchClientId($client->email);
            } else {
                throw new YouHostingException("You need to provide either a client ID (recommended) or client e-mail to search for");
            }
        } elseif (is_numeric($client)) {
            $id = $client;
        } else {
            $id = $this->api->searchClientId($client);
        }

        return (int)$id;
    }
1163609
protected static function fetchAccount(BaseClientInterface $client)
    {
        $account = UserSocialAccount::find()->byClient($client)->one();
        if (null === $account) {
            $account = Yii::createObject(['class' => static::class, 'provider' => $client->getId(), 'client_id' => $client->getUserAttributes()['id'], 'data' => json_encode($client->getUserAttributes())]);
            $account->save(false);
        }

        return $account;
    }
915498
protected function loadClient(array $client, ContainerBuilder $container)
    {
        $dsnResolver = function ($dsn) use ($container) {
            $usedEnvs = null;
            if (method_exists($container, 'resolveEnvPlaceholders')) {
                $container->resolveEnvPlaceholders($dsn, null, $usedEnvs);
            }

            if ($usedEnvs) {
                return new RedisEnvDsn($dsn);
            }

            $parsedDsn = new RedisDsn($dsn);

            if ($parsedDsn->isValid()) {
                return $parsedDsn;
            }

            throw new \InvalidArgumentException(sprintf('Given Redis DSN "%s" is invalid.', $dsn));
        };

        $client['dsns'] = array_map($dsnResolver, $client['dsns']);

        switch ($client['type']) {
            case 'predis':
                $this->loadPredisClient($client, $container);
                break;
            case 'phpredis':
                $this->loadPhpredisClient($client, $container);
                break;
        }
    }
858811
public function oauthClientClass($instance = false)
	{
		if (! isset($this->oauth_client_class)) {
			throw new \InvalidArgumentException(static::class . ' does not implement an OAuth Client class definition.');
		}

		return $instance ? new  $this->oauth_client_class : $this->oauth_client_class;
	}
769897
protected function createClient()
    {
        return new Client([
            'base_uri' => $this->baseUrl,
            'handler'  => $this->handlerStack,
            RequestOptions::HTTP_ERRORS => false,
            RequestOptions::AUTH => [$this->app->getClientId(), $this->app->getClientSecret()],
            RequestOptions::TIMEOUT => $this->requestTimeout,
        ]);
    }
794907
public function client($client = null)
    {
        if ($client === null) {
            return $this->getClient();
        }

        return $this->setClient($client);
    }