49 lines
1.2 KiB
PHP
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;
|
|
}
|
|
}
|