summaryrefslogtreecommitdiff
path: root/view/Versioning.php
diff options
context:
space:
mode:
Diffstat (limited to 'view/Versioning.php')
-rw-r--r--view/Versioning.php24
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
4class 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}