23 private const ALGO =
'md4';
29 private static $instance;
41 if ( !self::$instance ) {
42 self::$instance =
new self;
45 return self::$instance;
55 private function getFileContentsHashInternal( $filePath ) {
57 $mtime = @filemtime( $filePath );
58 if ( $mtime ===
false ) {
62 $cacheKey = $this->cache->makeGlobalKey( __CLASS__, $filePath, $mtime, self::ALGO );
63 return $this->cache->getWithSetCallback(
65 $this->cache::TTL_DAY,
66 static function () use ( $filePath ) {
68 $contents = @file_get_contents( $filePath );
69 if ( $contents ===
false ) {
74 return hash( self::ALGO, $contents );
88 $instance = self::singleton();
90 if ( !is_array( $filePaths ) ) {
91 $filePaths = (array)$filePaths;
94 if ( count( $filePaths ) === 1 ) {
95 $hash = $instance->getFileContentsHashInternal( $filePaths[0] );
101 foreach ( $filePaths as $filePath ) {
102 $hashes[] = $instance->getFileContentsHashInternal( $filePath ) ?:
'';
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 ...