PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.8.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.8.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 / Page_Cache / Meta / Provider.php

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

119 lines 3.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 cache meta.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Page_Cache\Meta;
11
12 use SolidWP\Performance\Contracts\Service_Provider;
13 use SolidWP\Performance\Page_Cache\Meta\Contracts\Meta_Reader;
14 use SolidWP\Performance\Page_Cache\Meta\Contracts\Meta_Writer;
15 use SolidWP\Performance\Page_Cache\Meta\Readers\Array_File_Reader;
16 use SolidWP\Performance\Page_Cache\Meta\Readers\Sanitized_Meta_Reader;
17 use SolidWP\Performance\Page_Cache\Meta\Sanitization\Collection;
18 use SolidWP\Performance\Page_Cache\Meta\Sanitization\Sanitizers\Header_Sanitizer;
19 use SolidWP\Performance\Page_Cache\Meta\Writers\Array_File_Writer;
20 use SolidWP\Performance\Page_Cache\Meta\Writers\Sanitized_Meta_Writer;
21
22 /**
23 * The Service Provider for cache meta.
24 *
25 * @package SolidWP\Performance
26 */
27 final class Provider extends Service_Provider {
28
29 public const SANITIZERS = 'solid_performance.page_cache.meta.sanitizers';
30
31 /**
32 * @inheritDoc
33 */
34 public function register(): void {
35 $this->register_sanitizers();
36 $this->register_writers();
37 $this->register_readers();
38 }
39
40 /**
41 * Register meta sanitizers in the container.
42 *
43 * @return void
44 */
45 private function register_sanitizers(): void {
46 /**
47 * Filters the denied response headers that will not be stored or served during
48 * a cached response.
49 *
50 * @param string[] $denied_headers
51 */
52 $denied_headers = apply_filters(
53 'solidwp/performance/meta/denied_headers',
54 [
55 'Connection',
56 'Content-Disposition',
57 'Content-Length',
58 'Pragma',
59 'Proxy-Authenticate',
60 'Server-Timing',
61 'Set-Cookie',
62 'Trailer',
63 'Transfer-Encoding',
64 'Upgrade',
65 'Vary',
66 'Via',
67 'WWW-Authenticate',
68 'Warning',
69 'X-CSRF-Token',
70 'X-Cache',
71 'X-WP-Nonce',
72 'X-XSRF-Token',
73 ]
74 );
75
76 $this->container->when( Header_Sanitizer::class )
77 ->needs( '$denied_headers' )
78 ->give( static fn(): array => $denied_headers );
79
80 $this->container->singleton(
81 self::SANITIZERS,
82 fn(): array => [
83 // You may add other sanitizers here.
84 $this->container->get( Header_Sanitizer::class ),
85 ]
86 );
87
88 $this->container->when( Collection::class )
89 ->needs( '$sanitizers' )
90 ->give( fn(): array => $this->container->get( self::SANITIZERS ) );
91 }
92
93 /**
94 * Register meta writer container definitions.
95 *
96 * @return void
97 */
98 private function register_writers(): void {
99 $this->container->when( Sanitized_Meta_Writer::class )
100 ->needs( Meta_Writer::class )
101 ->give( fn() => $this->container->get( Array_File_Writer::class ) );
102
103 $this->container->bind( Meta_Writer::class, fn() => $this->container->get( Sanitized_Meta_Writer::class ) );
104 }
105
106 /**
107 * Register meta reader container definitions.
108 *
109 * @return void
110 */
111 private function register_readers(): void {
112 $this->container->when( Sanitized_Meta_Reader::class )
113 ->needs( Meta_Reader::class )
114 ->give( fn() => $this->container->get( Array_File_Reader::class ) );
115
116 $this->container->bind( Meta_Reader::class, fn() => $this->container->get( Sanitized_Meta_Reader::class ) );
117 }
118 }
119