| 1 |
<?php |
| 2 |
/** |
| 3 |
* Represents a config file for a particular cache delivery strategy. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Cache_Delivery\Contracts; |
| 11 |
|
| 12 |
use RuntimeException; |
| 13 |
|
| 14 |
/** |
| 15 |
* Represents a config file for a particular cache delivery strategy. |
| 16 |
* |
| 17 |
* @package SolidWP\Performance |
| 18 |
*/ |
| 19 |
abstract class Config_File { |
| 20 |
|
| 21 |
/** |
| 22 |
* Memoization cache for the file path. |
| 23 |
* |
| 24 |
* @var string|null |
| 25 |
*/ |
| 26 |
protected ?string $filepath = null; |
| 27 |
|
| 28 |
/** |
| 29 |
* Get the server path to the cache delivery strategy config file. |
| 30 |
* |
| 31 |
* @throws RuntimeException If something goes seriously wrong finding the path. |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
abstract public function get_file_path(): string; |
| 36 |
|
| 37 |
/** |
| 38 |
* Check if the cache delivery file exists. |
| 39 |
* |
| 40 |
* @throws RuntimeException If something goes seriously wrong finding the path. |
| 41 |
* |
| 42 |
* @return bool |
| 43 |
*/ |
| 44 |
public function exists(): bool { |
| 45 |
return file_exists( $this->get_file_path() ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Check if the cache delivery file exists and is writable. |
| 50 |
* |
| 51 |
* @throws RuntimeException If something goes seriously wrong finding the path. |
| 52 |
* |
| 53 |
* @return bool |
| 54 |
*/ |
| 55 |
public function is_writable(): bool { |
| 56 |
return is_writable( $this->get_file_path() ); |
| 57 |
} |
| 58 |
} |
| 59 |
|