0 follower

Final Class Yiisoft\Yii\AuthClient\Collection

InheritanceYiisoft\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'],
    ]
    ...
]

Method Details

Hide inherited methods

__construct() public method

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
) {
}

            
getClient() public method

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;
}

            
getClients() public method

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;
}

            
hasClient() public method

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);
}

            
setClients() public method

public void setClients ( array $clients )
$clients array

List of auth clients indexed by their names

                public function setClients(array $clients): void
{
    $this->clients = $clients;
}