39
39
class Looker {
40
40
private Client $ authenticatedClient ;
41
41
private Configuration $ apiConfig ;
42
- private LookerConfiguration $ config ;
42
+ private LookerConfiguration $ lookerConfig ;
43
+ private array $ clientConfig ;
43
44
44
- public function __construct (LookerConfiguration $ config ) {
45
- $ this ->config = $ config ;
45
+ public function __construct (LookerConfiguration $ lookerConfig , array $ clientConfig = []) {
46
+ $ this ->lookerConfig = $ lookerConfig ;
47
+ $ this ->clientConfig = $ clientConfig ;
46
48
$ this ->login ();
47
49
}
48
50
49
51
public function login (): void {
50
52
$ this ->apiConfig = new Configuration ();
51
- $ this ->apiConfig ->setHost ($ this ->config ->getHost ());
53
+ $ this ->apiConfig ->setHost ($ this ->lookerConfig ->getHost ());
52
54
53
- if ($ this ->config ->getAccessToken () === '' ) {
55
+ if ($ this ->lookerConfig ->getAccessToken () === '' ) {
54
56
$ apiInstance = new ApiAuthApi (
55
- new Client (),
57
+ new Client ($ this -> clientConfig ),
56
58
$ this ->apiConfig
57
59
);
58
60
59
61
try {
60
- $ result = $ apiInstance ->login ($ this ->config ->getClientId (), $ this ->config ->getClientSecret ());
61
- $ this ->config ->setAccessToken ($ result ->getAccessToken ());
62
- $ this ->config ->setAccessTokenRenewed (true );
62
+ $ result = $ apiInstance ->login ($ this ->lookerConfig ->getClientId (), $ this ->lookerConfig ->getClientSecret ());
63
+ $ this ->lookerConfig ->setAccessToken ($ result ->getAccessToken ());
64
+ $ this ->lookerConfig ->setAccessTokenRenewed (true );
63
65
} catch (\Throwable $ e ) {
64
66
echo 'Exception when calling ApiAuthApi->login: ' , $ e ->getMessage (), PHP_EOL ;
65
67
}
@@ -68,26 +70,26 @@ public function login(): void {
68
70
$ this ->authenticatedClient = new Client ([
69
71
'verify ' => false ,
70
72
'headers ' => [
71
- 'Authorization ' => 'token ' . $ this ->config ->getAccessToken (),
73
+ 'Authorization ' => 'token ' . $ this ->lookerConfig ->getAccessToken (),
72
74
],
73
75
]);
74
76
75
- if ($ this ->config ->isAccessTokenRenewed ()) {
76
- $ this ->config ->storeAccessToken ($ this ->config ->getAccessToken ());
77
- $ this ->config ->setAccessTokenRenewed (false );
77
+ if ($ this ->lookerConfig ->isAccessTokenRenewed ()) {
78
+ $ this ->lookerConfig ->storeAccessToken ($ this ->lookerConfig ->getAccessToken ());
79
+ $ this ->lookerConfig ->setAccessTokenRenewed (false );
78
80
}
79
81
}
80
82
81
83
public function invalidateAccessToken (): void {
82
- $ this ->config ->setAccessToken ('' );
84
+ $ this ->lookerConfig ->setAccessToken ('' );
83
85
}
84
86
85
87
public function getAuthenticatedClient (): Client {
86
88
return $ this ->authenticatedClient ;
87
89
}
88
90
89
91
public function getAccessToken (): string {
90
- return $ this ->config ->getAccessToken ();
92
+ return $ this ->lookerConfig ->getAccessToken ();
91
93
}
92
94
93
95
public function __get (string $ name ) {
@@ -96,7 +98,11 @@ public function __get(string $name) {
96
98
return new $ class ($ this , $ this ->authenticatedClient , $ this ->apiConfig );
97
99
}
98
100
99
- public function getConfig (): LookerConfiguration {
100
- return $ this ->config ;
101
+ public function getLookerConfig (): LookerConfiguration {
102
+ return $ this ->lookerConfig ;
103
+ }
104
+
105
+ public function getClientConfig (): array {
106
+ return $ this ->clientConfig ;
101
107
}
102
108
}
0 commit comments