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
|
<?php /** * The main plugin class. * * @since 2.0.0 * * @package SolidWP\Mail */
namespace SolidWP\Mail;
use InvalidArgumentException; use SolidWP\Mail\Psr\Container\ContainerInterface as PsrContainerInterface; use SolidWP\Mail\StellarWP\Assets\Config as Assets_Config; use SolidWP\Mail\StellarWP\ContainerContract\ContainerInterface; use SolidWP\Mail\StellarWP\Validation\Config;
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * The primary class responsible for booting up the plugin. * * @since 2.0.0 * * @package SolidWP\Mail */ class Core {
public const PLUGIN_FILE = 'solid_mail.file';
/** * The server path to the plugin's main file * * @since 2.0.0 * * @var string */ private string $plugin_file;
/** * The centralized container. * * @since 2.0.0 * * @var Container */ private Container $container;
/** * An array of providers to register within the container. * * @var array<int,string> */ private array $providers = [ Admin\Provider::class, Hooks\Provider::class, Migration\Provider::class, Repository\Provider::class, Telemetry\Provider::class, Assets::class, ];
/** * The singleton instance for the plugin. * * @var Core */ private static self $instance;
/** * @param string $plugin_file The full server path to the main plugin file. * @param Container $container The container instance */ private function __construct( string $plugin_file, Container $container ) { $this->plugin_file = $plugin_file; $this->container = $container;
$this->container->singleton( PsrContainerInterface::class, $this->container ); $this->container->singleton( ContainerInterface::class, $this->container ); }
/** * Get the singleton instance of our plugin * * @param string|null $plugin_file The full server path to the main plugin file * @param Container|null $container The container instance. * * @return Core */ public static function instance( ?string $plugin_file = null, ?Container $container = null ): Core { if ( ! isset( self::$instance ) ) { if ( ! $plugin_file ) { throw new InvalidArgumentException( 'You must provide a $plugin_file path' ); }
if ( ! $container ) { throw new InvalidArgumentException( sprintf( 'You must provide a %s instance!', Container::class ) ); }
self::$instance = new self( $plugin_file, $container ); }
return self::$instance; }
/** * Initialize the plugin. * * @since 2.0.0 * @action plugins_loaded * * @return void */ public function init(): void { $this->container->setVar( self::PLUGIN_FILE, $this->plugin_file ); $this->container->setVar( 'LOGS_PER_PAGE', 10 );
// init validator. $this->init_validator_object(); $this->init_assets_object();
// Register all providers foreach ( $this->providers as $class ) { $this->container->get( $class )->register( $this->container ); } }
/** * Returns the container instance * * @return Container */ public function container(): Container { return $this->container; }
/** * Initializes the validator class. * * This method sets up the configuration for the validator class by setting the service container * and hook prefix, and then initializing the configuration. * * @return void */ protected function init_validator_object() { Config::setServiceContainer( $this->container ); Config::setHookPrefix( 'solidwp_mail_' ); Config::initialize(); }
/** * Initializes the asset libraries for SolidWP Mail. * * This function configures the asset settings for SolidWP Mail by setting the * hook prefix, path, version, and relative asset path using the StellarWP\Assets\Config class. * * @return void */ protected function init_assets_object() { Assets_Config::set_hook_prefix( 'solidwp_mail_' ); Assets_Config::set_path( WPSMTP_PATH ); Assets_Config::set_version( WPSMTP_VERSION ); Assets_Config::set_relative_asset_path( 'assets/' ); } }
|