15 private const ALGO =
'md4';
21 private static $instance;
33 if ( !self::$instance ) {
34 self::$instance =
new self;
37 return self::$instance;
47 private function getFileContentsHashInternal( $filePath ) {
49 $mtime = @filemtime( $filePath );
50 if ( $mtime ===
false ) {
54 $cacheKey = $this->cache->makeGlobalKey( __CLASS__, $filePath, $mtime, self::ALGO );
55 return $this->cache->getWithSetCallback(
57 $this->cache::TTL_DAY,
58 static function () use ( $filePath ) {
60 $contents = @file_get_contents( $filePath );
61 if ( $contents ===
false ) {
66 return hash( self::ALGO, $contents );
80 $instance = self::singleton();
82 if ( !is_array( $filePaths ) ) {
83 $filePaths = (array)$filePaths;
86 if ( count( $filePaths ) === 1 ) {
87 $hash = $instance->getFileContentsHashInternal( $filePaths[0] );
93 foreach ( $filePaths as $filePath ) {
94 $hashes[] = $instance->getFileContentsHashInternal( $filePath ) ?:
'';
97 $hashes = implode(
'', $hashes );
98 return $hashes ? hash( self::ALGO, $hashes ) :
false;
Generate hash digests of file contents to help with cache invalidation.
static singleton()
Get the singleton instance of this class.
static getFileContentsHash( $filePaths)
Get a hash of the combined contents of one or more files, either by retrieving a previously-computed ...