Config.php
3.63 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
<?php
/**
* A helper class to provide configuration options for the library.
*
* @since 1.0.0
*
* @package StellarWP\Telemetry
*
* @license GPL-2.0-or-later
* Modified by learndash on 20-September-2023 using Strauss.
* @see https://github.com/BrianHenryIE/strauss
*/
namespace StellarWP\Learndash\StellarWP\Telemetry;
use StellarWP\Learndash\StellarWP\ContainerContract\ContainerInterface;
/**
* A configuration class to help set up the library.
*
* @since 1.0.0
*
* @package StellarWP\Telemetry
*/
class Config {
/**
* Container object.
*
* @since 1.0.0
*
* @var \StellarWP\Learndash\StellarWP\ContainerContract\ContainerInterface
*/
protected static $container;
/**
* Prefix for hook names.
*
* @since 1.0.0
*
* @var string
*/
protected static $hook_prefix = '';
/**
* Unique ID for the stellarwp slug.
*
* @since 1.0.0
*
* @var string
*/
protected static $stellar_slug = '';
/**
* The url of the telemetry server.
*
* @since 1.0.0
*
* @var string
*/
protected static $server_url = 'https://telemetry.stellarwp.com/api/v1';
/**
* Get the container.
*
* @since 1.0.0
*
* @throws \RuntimeException Throws exception if container is not set.
*
* @return \StellarWP\Learndash\StellarWP\ContainerContract\ContainerInterface
*/
public static function get_container() {
if ( null === self::$container ) {
throw new \RuntimeException( 'You must provide a container via StellarWP\Telemetry\Config::set_container() before attempting to fetch it.' );
}
return self::$container;
}
/**
* Gets the hook prefix.
*
* @since 1.0.0
*
* @return string
*/
public static function get_hook_prefix() {
return static::$hook_prefix;
}
/**
* Gets the telemetry server url.
*
* @since 1.0.0
*
* @return string
*/
public static function get_server_url() {
return static::$server_url;
}
/**
* Gets the stellar slug server url.
*
* @since 1.0.0
*
* @return string
*/
public static function get_stellar_slug() {
return static::$stellar_slug;
}
/**
* Returns whether the container has been set.
*
* @since 1.0.0
*
* @return bool
*/
public static function has_container() {
return null !== self::$container;
}
/**
* Resets this class back to the defaults.
*
* @since 1.0.0
*
* @return void
*/
public static function reset() {
static::$hook_prefix = '';
static::$server_url = 'https://telemetry.stellarwp.com/api/v1';
static::$stellar_slug = '';
}
/**
* Set the container object.
*
* @since 1.0.0
*
* @param \StellarWP\Learndash\StellarWP\ContainerContract\ContainerInterface $container Container object.
*
* @return void
*/
public static function set_container( ContainerInterface $container ) {
self::$container = $container;
}
/**
* Sets the hook prefix.
*
* @since 1.0.0
*
* @param string $prefix The prefix to use for hooks.
*
* @return void
*/
public static function set_hook_prefix( string $prefix ) {
// Make sure the prefix always ends with a separator.
if ( substr( $prefix, -1 ) !== '/' ) {
$prefix = $prefix . '/';
}
static::$hook_prefix = $prefix;
}
/**
* Sets the stellar slug.
*
* @since 1.0.0
*
* @param string $stellar_slug The unique slug to identify the plugin with the server.
*
* @return void
*/
public static function set_stellar_slug( string $stellar_slug ) {
static::$stellar_slug = $stellar_slug;
}
/**
* Sets the telemetry server url.
*
* @since 1.0.0
*
* @param string $url The url of the telemetry server.
*
* @return void
*/
public static function set_server_url( string $url ) {
static::$server_url = $url;
}
}