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

118 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-WP-Nonce',
71 'X-XSRF-Token',
72 ]
73 );
74
75 $this->container->when( Header_Sanitizer::class )
76 ->needs( '$denied_headers' )
77 ->give( static fn(): array => $denied_headers );
78
79 $this->container->singleton(
80 self::SANITIZERS,
81 fn(): array => [
82 // You may add other sanitizers here.
83 $this->container->get( Header_Sanitizer::class ),
84 ]
85 );
86
87 $this->container->when( Collection::class )
88 ->needs( '$sanitizers' )
89 ->give( fn(): array => $this->container->get( self::SANITIZERS ) );
90 }
91
92 /**
93 * Register meta writer container definitions.
94 *
95 * @return void
96 */
97 private function register_writers(): void {
98 $this->container->when( Sanitized_Meta_Writer::class )
99 ->needs( Meta_Writer::class )
100 ->give( fn() => $this->container->get( Array_File_Writer::class ) );
101
102 $this->container->bind( Meta_Writer::class, fn() => $this->container->get( Sanitized_Meta_Writer::class ) );
103 }
104
105 /**
106 * Register meta reader container definitions.
107 *
108 * @return void
109 */
110 private function register_readers(): void {
111 $this->container->when( Sanitized_Meta_Reader::class )
112 ->needs( Meta_Reader::class )
113 ->give( fn() => $this->container->get( Array_File_Reader::class ) );
114
115 $this->container->bind( Meta_Reader::class, fn() => $this->container->get( Sanitized_Meta_Reader::class ) );
116 }
117 }
118