PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / trunk
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution vtrunk
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 / Cache_Delivery / Provider.php

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

92 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Registers Cache Delivery definitions functionality in the container.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Cache_Delivery;
11
12 use SolidWP\Performance\Contracts\Service_Provider;
13
14 /**
15 * Registers Cache Delivery definitions functionality in the container.
16 *
17 * @package SolidWP\Performance
18 */
19 final class Provider extends Service_Provider {
20
21 /**
22 * @inheritDoc
23 */
24 public function register(): void {
25 $this->register_htaccess();
26 $this->register_nginx();
27 $this->register_manager_collection();
28 $this->register_settings_listener();
29 }
30
31 /**
32 * Register htaccess cache delivery functionality.
33 *
34 * @return void
35 */
36 private function register_htaccess(): void {
37 $this->container->when( Htaccess\Manager::class )
38 ->needs( Contracts\Writable::class )
39 ->give( Htaccess\Writer::class );
40
41 $this->container->when( Htaccess\Manager::class )
42 ->needs( Contracts\Readable::class )
43 ->give( Htaccess\Reader::class );
44 }
45
46 /**
47 * Register Nginx cache delivery functionality.
48 *
49 * @return void
50 */
51 private function register_nginx(): void {
52 $this->container->when( Nginx\Manager::class )
53 ->needs( Contracts\Writable::class )
54 ->give( Nginx\Writer::class );
55
56 $this->container->when( Nginx\Manager::class )
57 ->needs( Contracts\Readable::class )
58 ->give( Nginx\Reader::class );
59 }
60
61 /**
62 * Register the managers that are part of the Manager Collection.
63 *
64 * @return void
65 */
66 private function register_manager_collection(): void {
67 $this->container->when( Manager_Collection::class )
68 ->needs( '$managers' )
69 ->give(
70 fn(): array => [
71 // Add any new managers indexed by their type.
72 Cache_Delivery_Type::HTACCESS => $this->container->get( Htaccess\Manager::class ),
73 Cache_Delivery_Type::NGINX => $this->container->get( Nginx\Manager::class ),
74 ]
75 );
76 }
77
78 /**
79 * Run events when the cache delivery method changes.
80 *
81 * @return void
82 */
83 private function register_settings_listener(): void {
84 add_action(
85 'solidwp/performance/settings/changed',
86 $this->container->callback( Settings_Listener::class, 'on_settings_change' ),
87 10,
88 2,
89 );
90 }
91 }
92