MediaWiki master
Wikimedia\FileBackend\FSFile\FSFile Class Reference

Class representing a non-directory file on the file system. More...

Inherited by Wikimedia\FileBackend\FSFile\TempFSFile.

Public Member Functions

 __construct ( $path)
 Sets up the file object.
 
 exists ()
 Checks if the file exists.
 
 getPath ()
 Returns the file system path.
 
 getProps ( $ext=true)
 Get an associative array containing information about a file with the given storage path.
 
 getSha1Base36 ( $recache=false)
 Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.
 
 getSize ()
 Get the file size in bytes.
 
 getTimestamp ()
 Get the file's last-modified timestamp.
 

Static Public Member Functions

static extensionFromPath ( $path)
 Get the final file extension from a file system path.
 
static getPropsFromPath ( $path, $ext=true)
 Get an associative array containing information about a file in the local filesystem.
 
static getSha1Base36FromPath ( $path)
 Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.
 
static placeholderProps ()
 Placeholder file properties to use for files that don't exist.
 

Protected Attributes

string $path
 Path to file.
 
string $sha1Base36
 File SHA-1 in base 36.
 

Detailed Description

Class representing a non-directory file on the file system.

Definition at line 34 of file FSFile.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\FileBackend\FSFile\FSFile::__construct ( $path)

Sets up the file object.

Parameters
string$pathPath to temporary file on local disk

Reimplemented in Wikimedia\FileBackend\FSFile\TempFSFile.

Definition at line 46 of file FSFile.php.

References Wikimedia\FileBackend\FSFile\FSFile\$path.

Member Function Documentation

◆ exists()

Wikimedia\FileBackend\FSFile\FSFile::exists ( )

Checks if the file exists.

Returns
bool

Definition at line 64 of file FSFile.php.

Referenced by Wikimedia\FileBackend\FSFile\FSFile\getProps().

◆ extensionFromPath()

static Wikimedia\FileBackend\FSFile\FSFile::extensionFromPath ( $path)
static

Get the final file extension from a file system path.

Parameters
string$path
Returns
string

Definition at line 197 of file FSFile.php.

References Wikimedia\FileBackend\FSFile\FSFile\$path.

◆ getPath()

Wikimedia\FileBackend\FSFile\FSFile::getPath ( )

Returns the file system path.

Returns
string

Definition at line 55 of file FSFile.php.

References Wikimedia\FileBackend\FSFile\FSFile\$path.

◆ getProps()

Wikimedia\FileBackend\FSFile\FSFile::getProps ( $ext = true)

Get an associative array containing information about a file with the given storage path.

Resulting array fields include:

  • fileExists
  • size (filesize in bytes)
  • mime (as major/minor)
  • file-mime (as major/minor)
  • sha1 (in base 36)
  • major_mime
  • minor_mime
Parameters
string | bool$extThe file extension, or true to extract it from the filename. Set it to false to ignore the extension. Currently unused.
Returns
array

Definition at line 114 of file FSFile.php.

References Wikimedia\FileBackend\FSFile\FSFile\exists(), Wikimedia\FileBackend\FSFile\FSFile\getSha1Base36(), Wikimedia\FileBackend\FSFile\FSFile\getSize(), and Wikimedia\FileBackend\FSFile\FSFile\placeholderProps().

◆ getPropsFromPath()

static Wikimedia\FileBackend\FSFile\FSFile::getPropsFromPath ( $path,
$ext = true )
static

Get an associative array containing information about a file in the local filesystem.

Parameters
string$pathAbsolute local filesystem path
string | bool$extThe file extension, or true to extract it from the filename. Set it to false to ignore the extension.
Returns
array

Definition at line 211 of file FSFile.php.

References Wikimedia\FileBackend\FSFile\FSFile\$path.

◆ getSha1Base36()

Wikimedia\FileBackend\FSFile\FSFile::getSha1Base36 ( $recache = false)

Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.

160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36 fairly neatly.

Parameters
bool$recache
Returns
bool|string False on failure

Definition at line 175 of file FSFile.php.

References Wikimedia\FileBackend\FSFile\FSFile\$sha1Base36.

Referenced by Wikimedia\FileBackend\FSFile\FSFile\getProps().

◆ getSha1Base36FromPath()

static Wikimedia\FileBackend\FSFile\FSFile::getSha1Base36FromPath ( $path)
static

Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.

160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36 fairly neatly.

Parameters
string$path
Returns
false|string False on failure

Definition at line 227 of file FSFile.php.

References Wikimedia\FileBackend\FSFile\FSFile\$path.

◆ getSize()

Wikimedia\FileBackend\FSFile\FSFile::getSize ( )

Get the file size in bytes.

Returns
int|bool

Definition at line 73 of file FSFile.php.

Referenced by Wikimedia\FileBackend\FSFile\FSFile\getProps().

◆ getTimestamp()

Wikimedia\FileBackend\FSFile\FSFile::getTimestamp ( )

Get the file's last-modified timestamp.

Returns
string|bool TS_MW timestamp or false on failure

Definition at line 86 of file FSFile.php.

◆ placeholderProps()

static Wikimedia\FileBackend\FSFile\FSFile::placeholderProps ( )
static

Placeholder file properties to use for files that don't exist.

Resulting array fields include:

  • fileExists
  • size (filesize in bytes)
  • mime (as major/minor)
  • file-mime (as major/minor)
  • sha1 (in base 36)
  • major_mime
  • minor_mime
Returns
array

Definition at line 152 of file FSFile.php.

Referenced by Wikimedia\FileBackend\FSFile\FSFile\getProps().

Member Data Documentation

◆ $path

◆ $sha1Base36

string Wikimedia\FileBackend\FSFile\FSFile::$sha1Base36
protected

File SHA-1 in base 36.

Definition at line 39 of file FSFile.php.

Referenced by Wikimedia\FileBackend\FSFile\FSFile\getSha1Base36().


The documentation for this class was generated from the following file: