koel/app/Services/Helper.php

32 lines
747 B
PHP
Raw Normal View History

2018-08-29 06:15:11 +00:00
<?php
namespace App\Services;
use SplFileInfo;
use Throwable;
class Helper
2018-08-29 06:15:11 +00:00
{
/**
* Get a unique hash from a file path.
* This hash can then be used as the Song record's ID.
*/
public static function getFileHash(string $path): string
2018-08-29 06:15:11 +00:00
{
2020-12-22 20:11:22 +00:00
return md5(config('app.key') . $path);
2018-08-29 06:15:11 +00:00
}
public static function getModifiedTime(string|SplFileInfo $file): int
{
$file = is_string($file) ? new SplFileInfo($file) : $file;
// Workaround for #344, where getMTime() fails for certain files with Unicode names on Windows.
try {
return $file->getMTime();
} catch (Throwable) {
// Just use current stamp for mtime.
return time();
}
}
2018-08-29 06:15:11 +00:00
}