PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.2.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.2.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
← All changes | src/Performance/Core.php +9 -71 trunk1.2.0 View file →
@@ -13,11 +13,9 @@
13 13
14 14 use InvalidArgumentException;
15 15 use RuntimeException;
16 16 use SolidWP\Performance\Contracts\Service_Provider;
17 -use SolidWP\Performance\Page_Cache\Cache_Path;
18 -use SolidWP\Performance\Psr\Container\ContainerInterface;
19 -use SolidWP\Performance\StellarWP\ContainerContract\ContainerInterface as StellarContainerInterface;
17 +use SolidWP\Performance\StellarWP\ContainerContract\ContainerInterface;
20 18
21 19 if ( ! defined( 'ABSPATH' ) ) {
22 20 exit;
23 21 }
@@ -35,9 +33,8 @@
35 33 public const PLUGIN_DIR = 'solid_performance.plugin_dir';
36 34 public const PLUGIN_URL = 'solid_performance.plugin_url';
37 35 public const PLUGIN_BASENAME = 'solid_performance.plugin_basename';
38 36 public const PLUGIN_VERSION = 'solid_performance.plugin_version';
39 - public const CACHE_DIR = 'solid_performance.cache_dir';
40 37 public const ADVANCED_CACHE_PATH = 'solid_performance.advanced_cache_path';
41 38
42 39 /**
43 40 * The server path to the plugin's main file.
@@ -61,19 +58,12 @@
61 58 *
62 59 * @var array<int, class-string<Service_Provider>>
63 60 */
64 61 private array $early_providers = [
65 - Log\Provider::class,
66 - Memoize\Provider::class,
67 62 Config\Provider::class,
63 + Update\Provider::class,
68 64 View\Provider::class,
69 - Cache_Delivery\Provider::class,
70 - Page_Cache\Request_Context\Provider::class,
71 - Page_Cache\Meta\Provider::class,
72 65 Page_Cache\Provider::class,
73 -
74 - // This should always be last, to ensure dependencies have been built.
75 - Update\Provider::class,
76 66 ];
77 67
78 68 /**
79 69 * An array of providers to register within the container after
@@ -83,24 +73,16 @@
83 73 *
84 74 * @var array<int, class-string<Service_Provider>>
85 75 */
86 76 private array $providers = [
87 - Database\Provider::class,
88 - Storage\Provider::class,
89 - Lock\Provider::class,
90 77 Assets\Provider::class,
91 - Page_Cache\Purge\Provider::class,
92 - Preload\Provider::class,
93 78 Admin\Provider::class,
94 79 API\Provider::class,
95 80 Notices\Provider::class,
96 81 Pipelines\Provider::class,
97 82 Telemetry\Provider::class,
98 - Image_Transformation\Provider::class,
99 83 WP_CLI\Provider::class,
100 84 Shutdown\Provider::class,
101 - Dom\Provider::class,
102 - Cron\Provider::class,
103 85 ];
104 86
105 87 /**
106 88 * The singleton instance for the plugin.
@@ -118,22 +100,21 @@
118 100 Container $container
119 101 ) {
120 102 $this->plugin_file = $plugin_file;
121 103 $this->container = $container;
104 + $this->container->singleton( \SolidWP\Performance\Psr\Container\ContainerInterface::class, $this->container );
105 + $this->container->singleton( SolidWP\Performance\Psr\Container\ContainerInterface::class, $this->container );
122 106 $this->container->singleton( ContainerInterface::class, $this->container );
123 - $this->container->singleton( StellarContainerInterface::class, $this->container );
124 107
125 108 // Set container variables available to pre bootstrap providers.
126 109 $this->container->setVar( self::PLUGIN_FILE, $this->plugin_file );
127 110 $this->container->setVar( self::PLUGIN_VERSION, $this->get_plugin_version() );
128 - $this->container->setVar( self::CACHE_DIR, WP_CONTENT_DIR . '/cache/solid-performance' );
129 111 $this->container->setVar( self::ADVANCED_CACHE_PATH, WP_CONTENT_DIR . '/advanced-cache.php' );
130 112
131 - // Set the cache dir early so all providers can use it.
132 - $this->register_mandatory_definitions();
133 -
134 113 // Register pre bootstrap providers early.
135 - $this->register_early_providers();
114 + foreach ( $this->early_providers as $provider ) {
115 + $this->container->get( $provider )->register();
116 + }
136 117 }
137 118
138 119 /**
139 120 * Get the singleton instance of our plugin.
@@ -161,29 +142,15 @@
161 142 return self::$instance;
162 143 }
163 144
164 145 /**
165 - * Reload service provider container definitions.
166 - *
167 - * @return Core
168 - */
169 - public function reload(): Core {
170 - $this->register_mandatory_definitions();
171 - $this->register_early_providers();
172 -
173 - return $this->init();
174 - }
175 -
176 - /**
177 146 * Initialize the plugin.
178 147 *
179 148 * @action plugins_loaded
180 149 *
181 - * @return Core
150 + * @return void
182 151 */
183 - public function init(): Core {
184 - $this->register_mandatory_definitions();
185 -
152 + public function init(): void {
186 153 // Set remaining container variables now that WordPress is fully bootstrapped.
187 154 $this->container->setVar( self::PLUGIN_DIR, plugin_dir_path( $this->plugin_file ) );
188 155 $this->container->setVar( self::PLUGIN_URL, plugin_dir_url( $this->plugin_file ) );
189 156 $this->container->setVar( self::PLUGIN_BASENAME, plugin_basename( $this->plugin_file ) );
@@ -191,10 +158,8 @@
191 158 // Register remaining providers now that WP is fully bootstrapped.
192 159 foreach ( $this->providers as $class ) {
193 160 $this->container->get( $class )->register( $this->container );
194 161 }
195 -
196 - return self::$instance;
197 162 }
198 163
199 164 /**
200 165 * Returns the container instance.
@@ -232,30 +197,8 @@
232 197 throw new RuntimeException( 'Cloning not allowed' );
233 198 }
234 199
235 200 /**
236 - * Mandatory container definitions that run both early and on init.
237 - *
238 - * @return void
239 - */
240 - private function register_mandatory_definitions(): void {
241 - $this->container->when( Cache_Path::class )
242 - ->needs( '$cache_dir' )
243 - ->give( static fn ( $c ) => $c->get( self::CACHE_DIR ) );
244 - }
245 -
246 - /**
247 - * Register early loaded bootstrap providers.
248 - *
249 - * @return void
250 - */
251 - private function register_early_providers(): void {
252 - foreach ( $this->early_providers as $provider ) {
253 - $this->container->get( $provider )->register( $this->container );
254 - }
255 - }
256 -
257 - /**
258 201 * Get the plugin's current version.
259 202 *
260 203 * @throws RuntimeException If we are unable to retrieve the plugin version.
261 204 *
@@ -262,13 +205,8 @@
262 205 * @return string
263 206 */
264 207 private function get_plugin_version(): string {
265 208 $content = file_get_contents( $this->plugin_file, false, null, 0, 8 * KB_IN_BYTES );
266 -
267 - // Prevent race condition if the solid-performance file is already deleted.
268 - if ( ! $content ) {
269 - return '0.0.0';
270 - }
271 209
272 210 $pattern = '/^ \* Version:\s*(.+)$/m';
273 211
274 212 if ( preg_match( $pattern, $content, $matches ) ) {