blob: fec81a194490e7f410906a3a819e4887281cfc77 (
plain)
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
52
53
54
55
|
<?php
if (! class_exists ( "PostmanAuthenticationManagerFactory" )) {
require_once 'PostmanGoogleAuthenticationManager.php';
require_once 'PostmanMicrosoftAuthenticationManager.php';
require_once 'PostmanNonOAuthAuthenticationManager.php';
require_once 'PostmanYahooAuthenticationManager.php';
//
class PostmanAuthenticationManagerFactory {
private $logger;
// singleton instance
public static function getInstance() {
static $inst = null;
if ($inst === null) {
$inst = new PostmanAuthenticationManagerFactory ();
}
return $inst;
}
private function __construct() {
$this->logger = new PostmanLogger ( get_class ( $this ) );
}
public function createAuthenticationManager() {
$transport = PostmanTransportRegistry::getInstance ()->getSelectedTransport ();
return $this->createManager ( $transport );
}
private function createManager(PostmanZendModuleTransport $transport) {
$options = PostmanOptions::getInstance ();
$authorizationToken = PostmanOAuthToken::getInstance ();
$authenticationType = $options->getAuthenticationType ();
$hostname = $options->getHostname ();
$clientId = $options->getClientId ();
$clientSecret = $options->getClientSecret ();
$senderEmail = $options->getMessageSenderEmail ();
$scribe = $transport->getScribe ();
$redirectUrl = $scribe->getCallbackUrl ();
if ($transport->isOAuthUsed ( $options->getAuthenticationType () )) {
if ($transport->isServiceProviderGoogle ( $hostname )) {
$authenticationManager = new PostmanGoogleAuthenticationManager ( $clientId, $clientSecret, $authorizationToken, $redirectUrl, $senderEmail );
} else if ($transport->isServiceProviderMicrosoft ( $hostname )) {
$authenticationManager = new PostmanMicrosoftAuthenticationManager ( $clientId, $clientSecret, $authorizationToken, $redirectUrl );
} else if ($transport->isServiceProviderYahoo ( $hostname )) {
$authenticationManager = new PostmanYahooAuthenticationManager ( $clientId, $clientSecret, $authorizationToken, $redirectUrl );
} else {
assert ( false );
}
} else {
$authenticationManager = new PostmanNonOAuthAuthenticationManager ();
}
$this->logger->debug ( 'Created ' . get_class ( $authenticationManager ) );
return $authenticationManager;
}
}
}
|