Class yii\authclient\Collection
Inheritance | yii\authclient\Collection » yii\base\Component |
---|---|
Available since extension's version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/src/Collection.php |
Collection is a storage for all auth clients in the application.
Example application configuration:
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\Google',
'clientId' => 'google_client_id',
'clientSecret' => 'google_client_secret',
],
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => 'facebook_client_id',
'clientSecret' => 'facebook_client_secret',
],
],
]
...
]
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$clients | yii\authclient\ClientInterface[] | List of auth clients. | yii\authclient\Collection |
$httpClient | \yii\httpclient\Client|array|string | HTTP client instance or configuration for the $clients. | yii\authclient\Collection |
Public Methods
Method | Description | Defined By |
---|---|---|
getClient() | yii\authclient\Collection | |
getClients() | yii\authclient\Collection | |
hasClient() | Checks if client exists in the hub. | yii\authclient\Collection |
setClients() | yii\authclient\Collection |
Protected Methods
Method | Description | Defined By |
---|---|---|
createClient() | Creates auth client instance from its array configuration. | yii\authclient\Collection |
Property Details
List of auth clients. This property is read-only.
HTTP client instance or configuration for the $clients. If set, this value will be passed as 'httpClient' config option while instantiating particular client object. This option is useful for adjusting HTTP client configuration for the entire list of auth clients.
Method Details
Creates auth client instance from its array configuration.
protected yii\authclient\ClientInterface createClient ( $id, $config ) | ||
$id | string |
Auth client id. |
$config | array |
Auth client instance configuration. |
return | yii\authclient\ClientInterface |
Auth client instance. |
---|
protected function createClient($id, $config)
{
$config['id'] = $id;
if (!isset($config['httpClient']) && $this->httpClient !== null) {
$config['httpClient'] = $this->httpClient;
}
return Yii::createObject($config);
}
public yii\authclient\ClientInterface getClient ( $id ) | ||
$id | string |
Service id. |
return | yii\authclient\ClientInterface |
Auth client instance. |
---|---|---|
throws | \yii\base\InvalidParamException |
on non existing client request. |
public function getClient($id)
{
if (!array_key_exists($id, $this->_clients)) {
throw new InvalidParamException("Unknown auth client '{$id}'.");
}
if (!is_object($this->_clients[$id])) {
$this->_clients[$id] = $this->createClient($id, $this->_clients[$id]);
}
return $this->_clients[$id];
}
public yii\authclient\ClientInterface[] getClients ( ) | ||
return | yii\authclient\ClientInterface[] |
List of auth clients. |
---|
public function getClients()
{
$clients = [];
foreach ($this->_clients as $id => $client) {
$clients[$id] = $this->getClient($id);
}
return $clients;
}
Checks if client exists in the hub.
public boolean hasClient ( $id ) | ||
$id | string |
Client id. |
return | boolean |
Whether client exist. |
---|
public function hasClient($id)
{
return array_key_exists($id, $this->_clients);
}
public void setClients ( array $clients ) | ||
$clients | array |
List of auth clients |
public function setClients(array $clients)
{
$this->_clients = $clients;
}