koel/app/Services/Helper.php

26 lines
633 B
PHP
Raw Normal View History

2018-08-29 06:15:11 +00:00
<?php
namespace App\Services;
use SplFileInfo;
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.
2022-08-08 16:00:59 +00:00
return attempt(static fn () => $file->getMTime()) ?? time();
}
2018-08-29 06:15:11 +00:00
}