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
solid-performance / src / Performance / Shutdown / Provider.php

Provider.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.3.0, at src/Performance/Shutdown/Provider.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Service Provider for Terminal Shutdown tasks.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Shutdown;
11
12 use SolidWP\Performance\Config\Config;
13 use SolidWP\Performance\Contracts\Service_Provider;
14 use SolidWP\Performance\Page_Cache\Purge\Batch\Batch_Purger;
15 use SolidWP\Performance\Update\Updater;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * The Service Provider for Terminal Shutdown tasks.
23 *
24 * @package SolidWP\Performance
25 */
26 final class Provider extends Service_Provider {
27
28 /**
29 * @inheritDoc
30 */
31 public function register(): void {
32 $this->container->singleton(
33 Shutdown_Handler::class,
34 fn() => new Shutdown_Handler(
35 // Add any terminable tasks to the collection to run on shutdown.
36 // Important: these will run in the order provided.
37 $this->container->get( Config::class ),
38 $this->container->get( Updater::class ),
39 $this->container->get( Batch_Purger::class ),
40 )
41 );
42
43 // Create an action that can be called manually.
44 add_action( 'solidwp/performance/terminate', $this->container->callback( Shutdown_Handler::class, 'handle' ) );
45
46 // Run early to get ahead of any potentially bad code that could kill execution.
47 add_action(
48 'shutdown',
49 static function (): void {
50 do_action( 'solidwp/performance/terminate' );
51 },
52 1
53 );
54
55 // Run this again in case any other code was updated in the shutdown action that could trigger our Terminable tasks.
56 add_action(
57 'shutdown',
58 static function (): void {
59 do_action( 'solidwp/performance/terminate' );
60 },
61 9999
62 );
63 }
64 }
65