wiki-grav/plugins/login-oauth2/classes/ProviderFactory.php

39 lines
1.1 KiB
PHP

<?php
namespace Grav\Plugin\Login\OAuth2;
use Grav\Plugin\Login\OAuth2\Providers\ProviderInterface;
class ProviderFactory
{
/**
* @param string $provider
* @param array $options
* @return ProviderInterface
*/
public static function create($provider, array $options = []): ProviderInterface
{
$provider_classname = 'Grav\\Plugin\\Login\\OAuth2\\Providers\\' . ucfirst($provider) . 'Provider';
if (!class_exists($provider_classname)) {
throw new \RuntimeException('Invalid OAuth2 provider:' . $provider);
}
$class = new $provider_classname();
$class->initProvider($options);
return $class;
}
public static function checkIfActive($provider, array $options = []): bool
{
$provider_classname = 'Grav\\Plugin\\Login\\OAuth2\\Providers\\' . ucfirst($provider) . 'Provider';
if (!class_exists($provider_classname)) {
throw new \RuntimeException('Invalid OAuth2 provider:' . $provider);
}
return $provider_classname::checkIfActive($options);
}
}