24use Wikimedia\AtEase\AtEase;
25use Wikimedia\Timestamp\ConvertibleTimestamp;
63 return is_file( $this->path );
72 AtEase::suppressWarnings();
73 $size = filesize( $this->path );
74 AtEase::restoreWarnings();
85 AtEase::suppressWarnings();
86 $timestamp = filemtime( $this->path );
87 AtEase::restoreWarnings();
88 if ( $timestamp !==
false ) {
89 $timestamp = ConvertibleTimestamp::convert( TS_MW, $timestamp );
114 $info[
'fileExists'] = $this->
exists();
116 if ( $info[
'fileExists'] ) {
117 $info[
'size'] = $this->
getSize();
120 $mime = mime_content_type( $this->path );
121 # MIME type according to file contents
122 $info[
'file-mime'] = (
$mime === false ) ?
'unknown/unknown' :
$mime;
124 $info[
'mime'] =
$mime;
126 if ( strpos(
$mime,
'/' ) !==
false ) {
127 [ $info[
'major_mime'], $info[
'minor_mime'] ] = explode(
'/',
$mime, 2 );
129 [ $info[
'major_mime'], $info[
'minor_mime'] ] = [
$mime,
'unknown' ];
152 $info[
'fileExists'] =
false;
154 $info[
'file-mime'] =
null;
155 $info[
'major_mime'] =
null;
156 $info[
'minor_mime'] =
null;
157 $info[
'mime'] =
null;
174 if ( $this->sha1Base36 !==
null && !$recache ) {
178 AtEase::suppressWarnings();
179 $this->sha1Base36 = sha1_file( $this->path );
180 AtEase::restoreWarnings();
182 if ( $this->sha1Base36 !==
false ) {
183 $this->sha1Base36 = Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 );
196 $i = strrpos(
$path,
'.' );
198 return strtolower( $i ? substr(
$path, $i + 1 ) :
'' );
210 $fsFile =
new self(
$path );
212 return $fsFile->getProps(
$ext );
226 $fsFile =
new self(
$path );
228 return $fsFile->getSha1Base36();
Class representing a non-directory file on the file system.
static getSha1Base36FromPath( $path)
Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding,...
static getPropsFromPath( $path, $ext=true)
Get an associative array containing information about a file in the local filesystem.
exists()
Checks if the file exists.
getTimestamp()
Get the file's last-modified timestamp.
getProps( $ext=true)
Get an associative array containing information about a file with the given storage path.
__construct( $path)
Sets up the file object.
string $sha1Base36
File SHA-1 in base 36.
getSize()
Get the file size in bytes.
getSha1Base36( $recache=false)
Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding,...
static placeholderProps()
Placeholder file properties to use for files that don't exist.
string $path
Path to file.
static extensionFromPath( $path)
Get the final file extension from a file system path.
getPath()
Returns the file system path.
if(!is_readable( $file)) $ext