-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlugin.php
More file actions
95 lines (82 loc) · 2.19 KB
/
Copy pathPlugin.php
File metadata and controls
95 lines (82 loc) · 2.19 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
<?php
declare(strict_types=1);
namespace WPGraphQL\Logging;
use WPGraphQL\Logging\Events\QueryEventLifecycle;
use WPGraphQL\Logging\Logger\Database\DatabaseEntity;
/**
* Plugin class for WPGraphQL Logging.
*
* This class serves as the main entry point for the plugin, handling initialization, action and filter hooks.
*
* @package WPGraphQL\Logging
*/
final class Plugin {
/**
* The instance of the plugin.
*
* @var \WPGraphQL\Logging\Plugin|null
*/
protected static ?Plugin $instance = null;
/**
* Private constructor to prevent direct instantiation.
*/
protected function __construct() {
}
/**
* Constructor
*/
public static function init(): self {
if ( ! isset( self::$instance ) || ! ( is_a( self::$instance, self::class ) ) ) {
self::$instance = new self();
self::$instance->setup();
}
/**
* Fire off init action.
*
* @param \WPGraphQL\Logging\Plugin $instance the instance of the plugin class.
*/
do_action( 'wpgraphql_logging_init', self::$instance );
return self::$instance;
}
/**
* Initialize the plugin admin, frontend & api functionality.
*/
public function setup(): void {
QueryEventLifecycle::init();
}
/**
* Activation callback for the plugin.
*/
public static function activate(): void {
DatabaseEntity::create_table();
}
/**
* Deactivation callback for the plugin.
*/
public static function deactivate(): void {
// @TODO: Add configuration to determine if the table should be dropped on deactivation.
DatabaseEntity::drop_table();
}
/**
* Throw error on object clone.
* The whole idea of the singleton design pattern is that there is a single object
* therefore, we don't want the object to be cloned.
*
* @codeCoverageIgnore
*
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __METHOD__, 'The plugin Plugin class should not be cloned.', '0.0.1' );
}
/**
* Disable unserializing of the class.
*
* @codeCoverageIgnore
*/
public function __wakeup(): void {
// De-serializing instances of the class is forbidden.
_doing_it_wrong( __METHOD__, 'De-serializing instances of the plugin Main class is not allowed.', '0.0.1' );
}
}