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 / Reader.php

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

65 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The .htaccess reader.
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\Cache_Delivery\Contracts\Readable;
14 use SolidWP\Performance\Cache_Delivery\Exceptions\CacheDeliveryReadException;
15 use SolidWP\Performance\Filesystem\Filesystem;
16
17 /**
18 * The .htaccess reader.
19 *
20 * @package SolidWP\Performance
21 */
22 final class Reader implements Readable {
23
24 /**
25 * @var Htaccess_File
26 */
27 private Htaccess_File $htaccess;
28
29 /**
30 * @var Filesystem
31 */
32 private Filesystem $filesystem;
33
34 /**
35 * @param Htaccess_File $htaccess The htaccess file object.
36 * @param Filesystem $filesystem The filesystem component.
37 */
38 public function __construct(
39 Htaccess_File $htaccess,
40 Filesystem $filesystem
41 ) {
42 $this->htaccess = $htaccess;
43 $this->filesystem = $filesystem;
44 }
45
46 /**
47 * Acquire a read lock and read the contents of the .htaccess file.
48 *
49 * @throws CacheDeliveryReadException When we are unable to open or lock the .htaccess file for reading.
50 *
51 * @return string
52 */
53 public function read(): string {
54 try {
55 if ( ! $this->htaccess->exists() ) {
56 return '';
57 }
58
59 return $this->filesystem->read( $this->htaccess->get_file_path() );
60 } catch ( RuntimeException $e ) {
61 throw new CacheDeliveryReadException( $e->getMessage(), $e->getCode(), $e );
62 }
63 }
64 }
65