28 private const ALGO =
'md4';
34 private static $instance;
46 if ( !self::$instance ) {
47 self::$instance =
new self;
50 return self::$instance;
60 private function getFileContentsHashInternal( $filePath ) {
62 $mtime = @filemtime( $filePath );
63 if ( $mtime ===
false ) {
67 $cacheKey = $this->cache->makeGlobalKey( __CLASS__, $filePath, $mtime, self::ALGO );
68 return $this->cache->getWithSetCallback(
70 $this->cache::TTL_DAY,
71 static function () use ( $filePath ) {
73 $contents = @file_get_contents( $filePath );
74 if ( $contents ===
false ) {
79 return hash( self::ALGO, $contents );
93 $instance = self::singleton();
95 if ( !is_array( $filePaths ) ) {
96 $filePaths = (array)$filePaths;
99 if ( count( $filePaths ) === 1 ) {
100 $hash = $instance->getFileContentsHashInternal( $filePaths[0] );
106 foreach ( $filePaths as $filePath ) {
107 $hashes[] = $instance->getFileContentsHashInternal( $filePath ) ?:
'';
110 $hashes = implode(
'', $hashes );
111 return $hashes ? hash( self::ALGO, $hashes ) :
false;
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 ...