Final Class Yiisoft\Yii\AuthClient\Collection
| Inheritance | Yiisoft\Yii\AuthClient\Collection |
|---|
Collection is a storage for all auth clients in the application.
Example application configuration:
'authClients' => [
'google' => [
'class' => Yiisoft\Yii\AuthClient\Clients\Google::class,
'setClientId()' => ['google_client_id'],
'setClientSecret()' => ['google_client_secret'],
],
'facebook' => [
'class' => Yiisoft\Yii\AuthClient\Clients\Facebook::class,
'setClientId()' => ['facebook_client_id'],
'setClientSecret()' => ['facebook_client_secret'],
]
...
]
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\AuthClient\Collection | |
| getClient() | Yiisoft\Yii\AuthClient\Collection | |
| getClients() | Yiisoft\Yii\AuthClient\Collection | |
| hasClient() | Checks if client exists in the hub. | Yiisoft\Yii\AuthClient\Collection |
| setClients() | Yiisoft\Yii\AuthClient\Collection |
Method Details
| public mixed __construct ( array $clients ) | ||
| $clients | array | |
public function __construct(
/**
* @var array|OAuth2Interface[] list of OAuth2 clients with their configuration in format: 'clientName' => [...]
*/
private array $clients
) {
}
| public Yiisoft\Yii\AuthClient\OAuth2 getClient ( string $name ) | ||
| $name | string | |
public function getClient(string $name): OAuth2
{
if (!$this->hasClient($name)) {
throw new InvalidArgumentException("Unknown auth client '{$name}'.");
}
$client = $this->clients[$name];
if (!($client instanceof OAuth2)) {
throw new RuntimeException(
'The Client should be an OAuth2 Interface.'
);
}
return $client;
}
| public array getClients ( ) |
public function getClients(): array
{
$clients = [];
/**
* @var OAuth2 $client
* @var string $name
* @var array $this->clients
*/
foreach ($this->clients as $name => $client) {
$clients[$name] = $this->getClient($name);
}
return $clients;
}
Checks if client exists in the hub.
| public boolean hasClient ( string $name ) | ||
| $name | string |
Client id. |
| return | boolean |
Whether client exist. |
|---|---|---|
public function hasClient(string $name): bool
{
return array_key_exists($name, $this->clients);
}
| public void setClients ( array $clients ) | ||
| $clients | array |
List of auth clients indexed by their names |
public function setClients(array $clients): void
{
$this->clients = $clients;
}
Signup or Login in order to comment.