diff options
| author | polo <ordipolo@gmx.fr> | 2026-07-26 19:29:53 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-07-26 19:29:53 +0200 |
| commit | 58514668410cb902dab613221a8e7f963cc36317 (patch) | |
| tree | 98d0ec77ba9689997e4af395679ce061b2bff3f9 /view/Versioning.php | |
| parent | fea733a16a666e9b7ecf4729b126d65d1ad9208d (diff) | |
| download | melaine-58514668410cb902dab613221a8e7f963cc36317.tar.gz melaine-58514668410cb902dab613221a8e7f963cc36317.tar.bz2 melaine-58514668410cb902dab613221a8e7f963cc36317.zip | |
versioning fichiers CSS et JS
Diffstat (limited to 'view/Versioning.php')
| -rw-r--r-- | view/Versioning.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/view/Versioning.php b/view/Versioning.php new file mode 100644 index 0000000..f75afe1 --- /dev/null +++ b/view/Versioning.php | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | <?php | ||
| 2 | // view/Versioning.php | ||
| 3 | |||
| 4 | class Versioning { | ||
| 5 | static function insertCSS(string $name): string | ||
| 6 | { | ||
| 7 | return '<link rel="stylesheet" href="' . self::versionedFileURL('css', $name) . '">' . "\n"; | ||
| 8 | } | ||
| 9 | static function insertJS(string $name, bool $module = false): string | ||
| 10 | { | ||
| 11 | return '<script ' . ($module ? 'type="module"' : '') . ' src="' . self::versionedFileURL('js', $name) . '"></script>' . "\n"; | ||
| 12 | } | ||
| 13 | |||
| 14 | static function versionedFileURL(string $type, string $filename, ?string $custom_path = null): string | ||
| 15 | { | ||
| 16 | $path = $custom_path ?? 'public/' . $type . '/' . $filename . '.' . $type; // si custom_path, $type et $filename ne servent à rien | ||
| 17 | |||
| 18 | if(file_exists(getcwd() . '/' . $path)){ | ||
| 19 | $version = substr(md5_file($path), 0, 8); | ||
| 20 | return $path . '?v=' . $version; | ||
| 21 | } | ||
| 22 | return $path; // sécurité fichier absent | ||
| 23 | } | ||
| 24 | } | ||
