PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.3.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.3.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 -70 trunk1.3.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,17 @@
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 78 Page_Cache\Purge\Provider::class,
92 - Preload\Provider::class,
93 79 Admin\Provider::class,
94 80 API\Provider::class,
95 81 Notices\Provider::class,
96 82 Pipelines\Provider::class,
97 83 Telemetry\Provider::class,
98 - Image_Transformation\Provider::class,
99 84 WP_CLI\Provider::class,
100 85 Shutdown\Provider::class,
101 - Dom\Provider::class,
102 - Cron\Provider::class,
103 86 ];
104 87
105 88 /**
106 89 * The singleton instance for the plugin.
@@ -118,22 +101,21 @@
118 101 Container $container
119 102 ) {
120 103 $this->plugin_file = $plugin_file;
121 104 $this->container = $container;
105 + $this->container->singleton( \SolidWP\Performance\Psr\Container\ContainerInterface::class, $this->container );
106 + $this->container->singleton( SolidWP\Performance\Psr\Container\ContainerInterface::class, $this->container );
122 107 $this->container->singleton( ContainerInterface::class, $this->container );
123 - $this->container->singleton( StellarContainerInterface::class, $this->container );
124 108
125 109 // Set container variables available to pre bootstrap providers.
126 110 $this->container->setVar( self::PLUGIN_FILE, $this->plugin_file );
127 111 $this->container->setVar( self::PLUGIN_VERSION, $this->get_plugin_version() );
128 - $this->container->setVar( self::CACHE_DIR, WP_CONTENT_DIR . '/cache/solid-performance' );
129 112 $this->container->setVar( self::ADVANCED_CACHE_PATH, WP_CONTENT_DIR . '/advanced-cache.php' );
130 113
131 - // Set the cache dir early so all providers can use it.
132 - $this->register_mandatory_definitions();
133 -
134 114 // Register pre bootstrap providers early.
135 - $this->register_early_providers();
115 + foreach ( $this->early_providers as $provider ) {
116 + $this->container->get( $provider )->register();
117 + }
136 118 }
137 119
138 120 /**
139 121 * Get the singleton instance of our plugin.
@@ -161,29 +143,15 @@
161 143 return self::$instance;
162 144 }
163 145
164 146 /**
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 147 * Initialize the plugin.
178 148 *
179 149 * @action plugins_loaded
180 150 *
181 - * @return Core
151 + * @return void
182 152 */
183 - public function init(): Core {
184 - $this->register_mandatory_definitions();
185 -
153 + public function init(): void {
186 154 // Set remaining container variables now that WordPress is fully bootstrapped.
187 155 $this->container->setVar( self::PLUGIN_DIR, plugin_dir_path( $this->plugin_file ) );
188 156 $this->container->setVar( self::PLUGIN_URL, plugin_dir_url( $this->plugin_file ) );
189 157 $this->container->setVar( self::PLUGIN_BASENAME, plugin_basename( $this->plugin_file ) );
@@ -191,10 +159,8 @@
191 159 // Register remaining providers now that WP is fully bootstrapped.
192 160 foreach ( $this->providers as $class ) {
193 161 $this->container->get( $class )->register( $this->container );
194 162 }
195 -
196 - return self::$instance;
197 163 }
198 164
199 165 /**
200 166 * Returns the container instance.
@@ -232,30 +198,8 @@
232 198 throw new RuntimeException( 'Cloning not allowed' );
233 199 }
234 200
235 201 /**
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 202 * Get the plugin's current version.
259 203 *
260 204 * @throws RuntimeException If we are unable to retrieve the plugin version.
261 205 *
@@ -262,13 +206,8 @@
262 206 * @return string
263 207 */
264 208 private function get_plugin_version(): string {
265 209 $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 210
272 211 $pattern = '/^ \* Version:\s*(.+)$/m';
273 212
274 213 if ( preg_match( $pattern, $content, $matches ) ) {