17 private const ALGO =
'md4';
23 private static $instance;
35 if ( !self::$instance ) {
36 self::$instance =
new self;
39 return self::$instance;
49 private function getFileContentsHashInternal( $filePath ) {
51 $mtime = @filemtime( $filePath );
52 if ( $mtime ===
false ) {
56 $cacheKey = $this->cache->makeGlobalKey( __CLASS__, $filePath, $mtime, self::ALGO );
57 return $this->cache->getWithSetCallback(
59 $this->cache::TTL_DAY,
60 static function () use ( $filePath ) {
62 $contents = @file_get_contents( $filePath );
63 if ( $contents ===
false ) {
68 return hash( self::ALGO, $contents );
84 if ( !is_array( $filePaths ) ) {
85 $filePaths = (array)$filePaths;
88 if ( count( $filePaths ) === 1 ) {
89 $hash = $instance->getFileContentsHashInternal( $filePaths[0] );
95 foreach ( $filePaths as $filePath ) {
96 $hashes[] = $instance->getFileContentsHashInternal( $filePath ) ?:
'';
99 $hashes = implode(
'', $hashes );
100 return $hashes ? hash( self::ALGO, $hashes ) :
false;