PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.2.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.2.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 / Buffer.php

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

77 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The class responsible for collecting and storing fully rendered pages.
4 *
5 * @since 0.1.0
6 *
7 * @package SolidWP\Performance
8 */
9
10 namespace SolidWP\Performance\Page_Cache;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * A class for collecting and storing rendered pages.
18 *
19 * @since 0.1.0
20 *
21 * @package SolidWP\Performance
22 */
23 class Buffer {
24
25 /**
26 * An instance of Cache.
27 *
28 * @since 0.1.0
29 *
30 * @var Cache
31 */
32 private Cache $cache;
33
34 /**
35 * The class constructor.
36 *
37 * @since 0.1.0
38 *
39 * @param Cache $cache An instance of Page_Cache\Cache.
40 */
41 public function __construct( Cache $cache ) {
42 $this->cache = $cache;
43 }
44
45 /**
46 * Registers the callback with Output Buffering.
47 *
48 * @since 0.1.0
49 *
50 * @return void
51 */
52 public function register(): void {
53 ob_start( [ $this, 'handle' ] );
54 }
55
56 /**
57 * The callback registered in the Output Buffer to save response.
58 *
59 * @since 0.1.0
60 *
61 * @param string $buffer The output created for the request.
62 *
63 * @see https://www.php.net/manual/en/function.ob-start.php
64 *
65 * @return string
66 */
67 public function handle( string $buffer ): string {
68 if ( is_admin() ) {
69 return $buffer;
70 }
71
72 $this->cache->save_output( $buffer );
73
74 return $buffer;
75 }
76 }
77