-
Notifications
You must be signed in to change notification settings - Fork 0
/
OAuthProviderFactory.php
51 lines (45 loc) · 1.38 KB
/
OAuthProviderFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Rad\OAuthentication;
use Rad\Utility\Inflection;
/**
* OAuth Provider Factory
*
* @package Rad\OAuthentication
*/
class OAuthProviderFactory
{
/**
* Create OAuth provider
*
* @param string $oAuthProvider
*
* @return AbstractOAuthProvider
* @throws Exception
*/
public static function create($oAuthProvider)
{
if (strpos($oAuthProvider, '\\') !== false) {
if (class_exists($oAuthProvider)) {
$providerInstance = new $oAuthProvider();
if (!($providerInstance instanceof AbstractOAuthProvider)) {
throw new Exception(
sprintf(
'OAuth provider "%s" must be extend "AbstractOAuthProvider".',
$oAuthProvider
)
);
}
return $providerInstance;
} else {
throw new Exception(sprintf('OAuth provider "%s" does not exist.', $oAuthProvider));
}
}
$oAuthClass = 'Rad\\OAuthentication\\Provider\\' .
Inflection::camelize($oAuthProvider) . 'Provider';
if (class_exists($oAuthClass)) {
return new $oAuthClass();
} else {
throw new Exception(sprintf('OAuth provider "%s" does not exist.', $oAuthClass));
}
}
}