silviooosilva /
CacheerPHP
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Silviooosilva\CacheerPhp\Helpers; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Class FlushHelper |
||
| 7 | * |
||
| 8 | * @author SÃlvio Silva <https://github.com/silviooosilva> |
||
| 9 | * @package Silviooosilva\CacheerPhp |
||
| 10 | * |
||
| 11 | * Builds deterministic file paths for last-flush timestamps per store type. |
||
| 12 | */ |
||
| 13 | class FlushHelper |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Returns a path to store a last-flush timestamp. |
||
| 17 | * @param string $storeType e.g., 'redis' or 'db' |
||
| 18 | * @param string $identifier e.g., namespace or table name |
||
| 19 | * @return string |
||
| 20 | */ |
||
| 21 | public static function pathFor(string $storeType, string $identifier): string |
||
| 22 | { |
||
| 23 | $root = EnvHelper::getRootPath(); |
||
| 24 | $dir = $root . DIRECTORY_SEPARATOR . 'CacheerPHP' . DIRECTORY_SEPARATOR . 'Flush'; |
||
| 25 | if (!is_dir($dir)) { |
||
| 26 | @mkdir($dir, 0755, true); |
||
|
0 ignored issues
–
show
|
|||
| 27 | } |
||
| 28 | $safeId = preg_replace('/[^a-zA-Z0-9_-]+/', '_', $identifier); |
||
| 29 | return $dir . DIRECTORY_SEPARATOR . $storeType . '_' . $safeId . '.time'; |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 |
If you suppress an error, we recommend checking for the error condition explicitly: