-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathWorkOS.php
More file actions
164 lines (140 loc) · 3.47 KB
/
WorkOS.php
File metadata and controls
164 lines (140 loc) · 3.47 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
<?php
namespace WorkOS;
/**
* Class WorkOS.
*
* This class allows users to get and set configuration for the package.
*/
class WorkOS
{
/**
* @var null|string WorkOS API key
*/
private static $apiKey = null;
/**
* @var null|string WorkOS Client ID
*/
private static $clientId = null;
/**
* @var string WorkOS base API URL.
*/
private static $apiBaseUrl = "https://api.workos.com/";
/**
* @var string SDK identifier
*/
private static $identifier = Version::SDK_IDENTIFIER;
/**
* @var string SDK version
*/
private static $version = Version::SDK_VERSION;
/**
* @return null|string WorkOS API key
*/
public static function getApiKey()
{
if (isset(self::$apiKey)) {
return self::$apiKey;
}
$envValue = self::getEnvVariable("WORKOS_API_KEY");
if ($envValue) {
self::$apiKey = $envValue;
return self::$apiKey;
}
$msg = "\$apiKey is required";
throw new \WorkOS\Exception\ConfigurationException($msg);
}
/**
* @param null|string $apiKey WorkOS API key
*/
public static function setApiKey($apiKey)
{
self::$apiKey = $apiKey;
}
/**
* @throws \WorkOS\Exception\ConfigurationException
*
* @return null|string WorkOS Client ID
*/
public static function getClientId()
{
if (isset(self::$clientId)) {
return self::$clientId;
}
$envValue = self::getEnvVariable("WORKOS_CLIENT_ID");
if ($envValue) {
self::$clientId = $envValue;
return self::$clientId;
}
$msg = "\$clientId is required";
throw new \WorkOS\Exception\ConfigurationException($msg);
}
/**
* @param string $clientId WorkOS Client ID
*/
public static function setClientId($clientId)
{
self::$clientId = $clientId;
}
/**
* @return string WorkOS base API URL
*/
public static function getApiBaseURL()
{
return self::$apiBaseUrl;
}
/**
* @param string $apiBaseUrl WorkOS base API URL
*/
public static function setApiBaseUrl($apiBaseUrl)
{
self::$apiBaseUrl = $apiBaseUrl;
}
/**
* @param string $identifier SDK identifier
*/
public static function setIdentifier($identifier)
{
self::$identifier = $identifier;
}
/**
* @return string SDK identifier
*/
public static function getIdentifier()
{
return self::$identifier;
}
/**
* @param string $version SDK version
*/
public static function setVersion($version)
{
self::$version = $version;
}
/**
* @return string SDK version
*/
public static function getVersion()
{
return self::$version;
}
/**
* Get environment variable with fallback to cached config sources
*
* @param string $key Environment variable name
* @return string|false The environment variable value or false if not found
*/
private static function getEnvVariable($key)
{
$value = getenv($key);
if ($value !== false && $value !== '') {
return $value;
}
if (isset($_ENV[$key]) && $_ENV[$key] !== '') {
return $_ENV[$key];
}
if (isset($_SERVER[$key]) && $_SERVER[$key] !== '') {
return $_SERVER[$key];
}
return false;
}
}