forked from Nchalenko/okta-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.php
More file actions
202 lines (176 loc) · 5.59 KB
/
Copy pathClient.php
File metadata and controls
202 lines (176 loc) · 5.59 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
/******************************************************************************
* Copyright 2017 Okta, Inc. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Okta;
use Http\Client\HttpClient;
use Okta\Cache\CacheManager;
use Okta\Cache\MemoryManager;
use Okta\DataStore\DefaultDataStore;
use Okta\Utilities\AuthorizationMode;
/**
* Class Client
* @package Okta
*/
class Client
{
/**
* @var null|Client $instance The current instance of Client.
*/
private static $instance = null;
/**
* @var string $token The API token for your Okta organization.
*/
private $token;
/**
* @var string $organizationUrl The full url of your organization, (eg. https://dev-123456.okta.com).
*/
private $organizationUrl;
/**
* @var HttpClient $httpClient An instance of HttpClient to use for communicating with Okta.
*/
private $httpClient;
/**
* @var string $integrationUserAgent The integrations UserAgent string to add to the base UserAgent.
*/
private $integrationUserAgent;
/**
* @var CacheManager $cacheManager The CacheManager Instance to use for caching.
*/
private $cacheManager;
/**
* @var AuthorizationMode $authorizationMode The authorization mode to use for api calls.
*/
private $authorizationMode;
public $dataStore;
public $yamlParser;
/**
* Create a new instance of Client.
*
* @param string $token
* @param string $organizationUrl
* @param HttpClient|NULL $httpClient
* @param string|NULL $integrationUserAgent
* @param CacheManager|NULL $cacheManager
* @param AuthorizationMode|NULL $authorizationMode
*/
public function __construct(
string $token,
string $organizationUrl,
?HttpClient $httpClient = null,
string $integrationUserAgent = null,
?CacheManager $cacheManager = null,
?AuthorizationMode $authorizationMode = null
) {
$this->token = $token;
$this->organizationUrl = $organizationUrl;
$this->httpClient = $httpClient;
$this->integrationUserAgent = $integrationUserAgent;
$this->cacheManager = $cacheManager;
$this->authorizationMode = $authorizationMode;
$this->dataStore = new DefaultDataStore(
$this->token,
$this->organizationUrl,
$this->httpClient,
$this->authorizationMode
);
if(null === $this->cacheManager) {
$this->cacheManager = new MemoryManager();
}
self::$instance = $this;
}
/**
* Get the Organization url from the client.
*
* @return string
*/
public function getOrganizationUrl(): string
{
return $this->organizationUrl;
}
/**
* Get the Integration User Agent string.
*
* @return string
*/
public function getIntegrationUserAgent(): string
{
return $this->integrationUserAgent;
}
/**
* Get the DataStore Instance.
*
* @return DefaultDataStore
*/
public function getDataStore(): DefaultDataStore
{
return $this->dataStore;
}
/**
* Get the Cache Manager from the Client.
*
* @return CacheManager
*/
public function getCacheManager(): CacheManager
{
return $this->cacheManager;
}
/**
* Get the Token from the Client.
*
* @return string
*/
public function getToken(): string
{
return $this->token;
}
/**
* Get the authorization mode for api calls
*
* @return AuthorizationMode
*/
public function getAuthorizationMode(): AuthorizationMode
{
return $this->authorizationMode;
}
/**
* Get the current instance of the Client object.
*
* @throws \RuntimeException
* @return Client
*/
public static function getInstance(): Client
{
if (null === self::$instance) {
$msg = 'The client has not be instantiated yet, please
build the client with the ClientBuilder first.
If you are using Private Key authorization mode.
Please also confirm that your scopes are set correcty for your application.';
throw new \RuntimeException(
$msg
);
}
return self::$instance;
}
/**
* Destroys the Client object.
*
* @return void
*/
public static function destroy()
{
self::$instance = null;
}
}