PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.9.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.9.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 / Cache_Delivery / Htaccess / Template_Loader.php

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

80 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Loads our custom htaccess configuration.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Cache_Delivery\Htaccess;
11
12 use RuntimeException;
13 use SolidWP\Performance\Page_Cache\Cache_Path;
14 use SolidWP\Performance\Page_Cache\Compression\Strategies\Gzip;
15 use SolidWP\Performance\Page_Cache\Compression\Strategies\Html;
16 use SolidWP\Performance\View\Contracts\View;
17 use SolidWP\Performance\View\Exceptions\FileNotFoundException;
18
19 /**
20 * Loads our custom htaccess configuration.
21 *
22 * @package SolidWP\Performance
23 */
24 final class Template_Loader {
25
26 public const VIEW = 'cache/htaccess';
27
28 /**
29 * @var View
30 */
31 private View $view;
32
33 /**
34 * @var Cache_Path
35 */
36 private Cache_Path $cache_path;
37
38 /**
39 * @param View $view The view renderer.
40 * @param Cache_Path $cache_path The cache path object.
41 */
42 public function __construct(
43 View $view,
44 Cache_Path $cache_path
45 ) {
46 $this->view = $view;
47 $this->cache_path = $cache_path;
48 }
49
50 /**
51 * Get our htaccess config template, with the dynamic values replaced.
52 *
53 * @throws FileNotFoundException If we can't find the view file.
54 * @throws RuntimeException If we can't find the document root.
55 *
56 * @return string
57 */
58 public function get(): string {
59 $page_cache_dir = $this->cache_path->get_page_cache_dir();
60
61 // Get the RewriteBase.
62 $home_root = parse_url( home_url() );
63 $base = trailingslashit( $home_root['path'] ?? '/' );
64
65 $root = swpsp_get_document_root();
66
67 // e.g. "wp-content/cache/solid-performance/page".
68 $cache_path = str_replace( $root, '', $page_cache_dir );
69
70 $args = [
71 'base' => $base,
72 'cache_path' => $cache_path,
73 'site_cache_path' => $this->cache_path->get_site_cache_dir(),
74 'extensions_regex' => sprintf( '%s|%s', Html::EXT, Gzip::EXT ),
75 ];
76
77 return $this->view->render_to_string( self::VIEW, $args );
78 }
79 }
80