PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.4.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.4.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.4.0, at src/Performance/Shutdown/Provider.php

84 lines 2.1 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\Shutdown\Rules\Query_Monitor_Rule;
16 use SolidWP\Performance\Update\Updater;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * The Service Provider for Terminal Shutdown tasks.
24 *
25 * @package SolidWP\Performance
26 */
27 final class Provider extends Service_Provider {
28
29 /**
30 * @inheritDoc
31 */
32 public function register(): void {
33 $this->register_priority_rules();
34
35 $this->container->singleton(
36 Shutdown_Handler::class,
37 fn() => new Shutdown_Handler(
38 // Add any terminable tasks to the collection to run on shutdown.
39 // Important: these will run in the order provided.
40 $this->container->get( Config::class ),
41 $this->container->get( Updater::class ),
42 $this->container->get( Batch_Purger::class ),
43 )
44 );
45
46 // Create an action that can be called manually.
47 add_action( 'solidwp/performance/terminate', $this->container->callback( Shutdown_Handler::class, 'handle' ) );
48
49 // Run early to get ahead of any potentially bad code that could kill execution.
50 add_action(
51 'shutdown',
52 static function (): void {
53 do_action( 'solidwp/performance/terminate' );
54 },
55 $this->container->get( Priority_Selector::class )->get_priority()
56 );
57
58 // Run this again in case any other code was updated in the shutdown action that could trigger our Terminable tasks.
59 add_action(
60 'shutdown',
61 static function (): void {
62 do_action( 'solidwp/performance/terminate' );
63 },
64 9999
65 );
66 }
67
68 /**
69 * Register priority rules to determine the initial shutdown hook priority depending on which
70 * other plugins are active.
71 *
72 * @return void
73 */
74 private function register_priority_rules(): void {
75 $this->container->when( Priority_Selector::class )
76 ->needs( '$rules' )
77 ->give(
78 fn(): array => [
79 $this->container->get( Query_Monitor_Rule::class ),
80 ]
81 );
82 }
83 }
84