| @@ -35,9 +35,8 @@ | ||
| 35 | 35 | public const PLUGIN_DIR = 'solid_performance.plugin_dir'; |
| 36 | 36 | public const PLUGIN_URL = 'solid_performance.plugin_url'; |
| 37 | 37 | public const PLUGIN_BASENAME = 'solid_performance.plugin_basename'; |
| 38 | 38 | public const PLUGIN_VERSION = 'solid_performance.plugin_version'; |
| 39 | - public const CACHE_DIR = 'solid_performance.cache_dir'; | |
| 40 | 39 | public const ADVANCED_CACHE_PATH = 'solid_performance.advanced_cache_path'; |
| 41 | 40 | |
| 42 | 41 | /** |
| 43 | 42 | * The server path to the plugin's main file. |
| @@ -62,18 +61,13 @@ | ||
| 62 | 61 | * @var array<int, class-string<Service_Provider>> |
| 63 | 62 | */ |
| 64 | 63 | private array $early_providers = [ |
| 65 | 64 | Log\Provider::class, |
| 66 | - Memoize\Provider::class, | |
| 67 | 65 | Config\Provider::class, |
| 66 | + Update\Provider::class, | |
| 68 | 67 | View\Provider::class, |
| 69 | - Cache_Delivery\Provider::class, | |
| 70 | - Page_Cache\Request_Context\Provider::class, | |
| 71 | 68 | Page_Cache\Meta\Provider::class, |
| 72 | 69 | Page_Cache\Provider::class, |
| 73 | - | |
| 74 | - // This should always be last, to ensure dependencies have been built. | |
| 75 | - Update\Provider::class, | |
| 76 | 70 | ]; |
| 77 | 71 | |
| 78 | 72 | /** |
| 79 | 73 | * An array of providers to register within the container after |
| @@ -94,13 +88,10 @@ | ||
| 94 | 88 | API\Provider::class, |
| 95 | 89 | Notices\Provider::class, |
| 96 | 90 | Pipelines\Provider::class, |
| 97 | 91 | Telemetry\Provider::class, |
| 98 | - Image_Transformation\Provider::class, | |
| 99 | 92 | WP_CLI\Provider::class, |
| 100 | 93 | Shutdown\Provider::class, |
| 101 | - Dom\Provider::class, | |
| 102 | - Cron\Provider::class, | |
| 103 | 94 | ]; |
| 104 | 95 | |
| 105 | 96 | /** |
| 106 | 97 | * The singleton instance for the plugin. |
| @@ -124,16 +115,19 @@ | ||
| 124 | 115 | |
| 125 | 116 | // Set container variables available to pre bootstrap providers. |
| 126 | 117 | $this->container->setVar( self::PLUGIN_FILE, $this->plugin_file ); |
| 127 | 118 | $this->container->setVar( self::PLUGIN_VERSION, $this->get_plugin_version() ); |
| 128 | - $this->container->setVar( self::CACHE_DIR, WP_CONTENT_DIR . '/cache/solid-performance' ); | |
| 129 | 119 | $this->container->setVar( self::ADVANCED_CACHE_PATH, WP_CONTENT_DIR . '/advanced-cache.php' ); |
| 130 | 120 | |
| 131 | 121 | // Set the cache dir early so all providers can use it. |
| 132 | - $this->register_mandatory_definitions(); | |
| 122 | + $this->container->when( Cache_Path::class ) | |
| 123 | + ->needs( '$cache_dir' ) | |
| 124 | + ->give( WP_CONTENT_DIR . '/cache' ); | |
| 133 | 125 | |
| 134 | 126 | // Register pre bootstrap providers early. |
| 135 | - $this->register_early_providers(); | |
| 127 | + foreach ( $this->early_providers as $provider ) { | |
| 128 | + $this->container->get( $provider )->register(); | |
| 129 | + } | |
| 136 | 130 | } |
| 137 | 131 | |
| 138 | 132 | /** |
| 139 | 133 | * Get the singleton instance of our plugin. |
| @@ -161,29 +155,15 @@ | ||
| 161 | 155 | return self::$instance; |
| 162 | 156 | } |
| 163 | 157 | |
| 164 | 158 | /** |
| 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 | 159 | * Initialize the plugin. |
| 178 | 160 | * |
| 179 | 161 | * @action plugins_loaded |
| 180 | 162 | * |
| 181 | - * @return Core | |
| 163 | + * @return void | |
| 182 | 164 | */ |
| 183 | - public function init(): Core { | |
| 184 | - $this->register_mandatory_definitions(); | |
| 185 | - | |
| 165 | + public function init(): void { | |
| 186 | 166 | // Set remaining container variables now that WordPress is fully bootstrapped. |
| 187 | 167 | $this->container->setVar( self::PLUGIN_DIR, plugin_dir_path( $this->plugin_file ) ); |
| 188 | 168 | $this->container->setVar( self::PLUGIN_URL, plugin_dir_url( $this->plugin_file ) ); |
| 189 | 169 | $this->container->setVar( self::PLUGIN_BASENAME, plugin_basename( $this->plugin_file ) ); |
| @@ -191,10 +171,8 @@ | ||
| 191 | 171 | // Register remaining providers now that WP is fully bootstrapped. |
| 192 | 172 | foreach ( $this->providers as $class ) { |
| 193 | 173 | $this->container->get( $class )->register( $this->container ); |
| 194 | 174 | } |
| 195 | - | |
| 196 | - return self::$instance; | |
| 197 | 175 | } |
| 198 | 176 | |
| 199 | 177 | /** |
| 200 | 178 | * Returns the container instance. |
| @@ -232,30 +210,8 @@ | ||
| 232 | 210 | throw new RuntimeException( 'Cloning not allowed' ); |
| 233 | 211 | } |
| 234 | 212 | |
| 235 | 213 | /** |
| 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 | 214 | * Get the plugin's current version. |
| 259 | 215 | * |
| 260 | 216 | * @throws RuntimeException If we are unable to retrieve the plugin version. |
| 261 | 217 | * |
| @@ -262,13 +218,8 @@ | ||
| 262 | 218 | * @return string |
| 263 | 219 | */ |
| 264 | 220 | private function get_plugin_version(): string { |
| 265 | 221 | $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 | 222 | |
| 272 | 223 | $pattern = '/^ \* Version:\s*(.+)$/m'; |
| 273 | 224 | |
| 274 | 225 | if ( preg_match( $pattern, $content, $matches ) ) { |