-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.php
More file actions
190 lines (169 loc) · 3.52 KB
/
Copy pathConfig.php
File metadata and controls
190 lines (169 loc) · 3.52 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
<?php
/**
* Pigeon Config
*
* @package StellarWP\Pigeon\Config
*/
declare( strict_types=1 );
namespace StellarWP\Pigeon;
use RuntimeException;
use StellarWP\ContainerContract\ContainerInterface;
use StellarWP\Pigeon\Contracts\Logger;
use StellarWP\Pigeon\Loggers\ActionScheduler_DB_Logger;
/**
* Pigeon Config
*
* @since TBD
*
* @package StellarWP\Pigeon\Config
*/
class Config {
/**
* Container object.
*
* @var ContainerInterface
*/
protected static ?ContainerInterface $container = null;
/**
* The hook prefix.
*
* @since TBD
*
* @var string
*/
protected static string $hook_prefix;
/**
* The logger.
*
* @since TBD
*
* @var ?Logger
*/
protected static ?Logger $logger = null;
/**
* The maximum table name length.
*
* @since TBD
*
* @var int
*/
protected static int $max_table_name_length = 64;
/**
* Get the container.
*
* @since TBD
*
* @throws RuntimeException If the container is not set.
*
* @return ContainerInterface
*/
public static function get_container(): ContainerInterface {
if ( self::$container === null ) {
throw new \RuntimeException( 'You must provide a container via StellarWP\Pigeon\Config::set_container() before attempting to fetch it.' );
}
return self::$container;
}
/**
* Gets the hook prefix.
*
* @since TBD
*
* @throws RuntimeException If the hook prefix is not set.
*
* @return string
*/
public static function get_hook_prefix(): string {
if ( ! static::$hook_prefix ) {
$class = __CLASS__;
throw new RuntimeException( "You must specify a hook prefix for your project with {$class}::set_hook_prefix()" );
}
return static::$hook_prefix;
}
/**
* Gets the logger.
*
* @since TBD
*
* @return Logger
*/
public static function get_logger(): Logger {
if ( ! static::$logger ) {
static::$logger = new ActionScheduler_DB_Logger();
}
return static::$logger;
}
/**
* Gets the maximum table name length.
*
* @return int
*/
public static function get_max_table_name_length(): int {
return static::$max_table_name_length;
}
/**
* Returns whether the container has been set.
*
* @return bool
*/
public static function has_container(): bool {
return self::$container !== null;
}
/**
* Set the container object.
*
* @param ContainerInterface $container Container object.
*/
public static function set_container( ContainerInterface $container ) {
self::$container = $container;
}
/**
* Sets the hook prefix.
*
* @param string $prefix The prefix to add to hooks.
*
* @throws RuntimeException If the hook prefix is empty.
*
* @return void
*/
public static function set_hook_prefix( string $prefix ): void {
if ( ! $prefix ) {
throw new RuntimeException( 'The hook prefix cannot be empty.' );
}
static::$hook_prefix = $prefix;
}
/**
* Sets the logger.
*
* @since TBD
*
* @param ?Logger $logger The logger.
*
* @return void
*/
public static function set_logger( ?Logger $logger ): void {
static::$logger = $logger;
}
/**
* Sets the maximum table name length.
*
* @since TBD
*
* @param int $length The maximum table name length.
*
* @return void
*/
public static function set_max_table_name_length( int $length ): void {
static::$max_table_name_length = $length;
}
/**
* Resets the config.
*
* @return void
*/
public static function reset(): void {
static::$container = null;
static::$hook_prefix = '';
static::$logger = null;
static::$max_table_name_length = 64;
}
}