Files
opensem/app/Repositories/Core/Cache.php
Ludovic CANDELLIER 36267139a1 [WIP] Setup of skeleton
2020-03-25 00:08:27 +01:00

49 lines
1.2 KiB
PHP

<?php
namespace App\Repositories\Core;
use TheSeer\DirectoryScanner\DirectoryScanner;
class Cache
{
public static function getAutoVersion($file)
{
$filePath = public_path() . $file;
if (!file_exists($filePath)) {
return '';
}
$version = filemtime($filePath);
return '?v=' . $version;
}
public static function getFilesVersion($folder, $type)
{
$folder = str_replace('.', '/', $folder);
// dump($folder);
// dump($type);
// exit;
$scanner = new DirectoryScanner;
$scanner->addInclude('*.'.$type);
// $scanner->addExclude('*filter*');
// $scanner->addExclude('./src/*');
$path = public_path() . '/' . $folder;
$data = [];
foreach ($scanner($path) as $i) {
// dump($i);
$sub = $i->getPath();
$sub = str_replace($path, '', $sub);
$sub = str_replace('\\', '/', $sub);
// dump($sub);
$filename = '/' . $folder . $sub . '/' . $i->getFilename();
// dump($filename);
$mtime = $i->getMTime();
$data[$filename] = $mtime;
}
return $data;
}
}