MediaWiki  1.34.0
TempFSFileFactory.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use TempFSFile;
6 
12  private $tmpDirectory;
13 
18  public function __construct( $tmpDirectory = null ) {
19  $this->tmpDirectory = $tmpDirectory;
20  }
21 
30  public function newTempFSFile( $prefix, $extension = '' ) {
31  $ext = ( $extension != '' ) ? ".{$extension}" : '';
33  if ( !is_string( $tmpDirectory ) ) {
35  }
36 
37  $attempts = 5;
38  while ( $attempts-- ) {
39  $hex = sprintf( '%06x%06x', mt_rand( 0, 0xffffff ), mt_rand( 0, 0xffffff ) );
40  $path = "$tmpDirectory/$prefix$hex$ext";
41  \Wikimedia\suppressWarnings();
42  $newFileHandle = fopen( $path, 'x' );
43  \Wikimedia\restoreWarnings();
44  if ( $newFileHandle ) {
45  fclose( $newFileHandle );
46  $tmpFile = new TempFSFile( $path );
47  $tmpFile->autocollect();
48  // Safely instantiated, end loop.
49  return $tmpFile;
50  }
51  }
52 
53  // Give up
54  return null; // @codeCoverageIgnore
55  }
56 }
MediaWiki\FileBackend\FSFile\TempFSFileFactory\__construct
__construct( $tmpDirectory=null)
Definition: TempFSFileFactory.php:18
MediaWiki\FileBackend\FSFile\TempFSFileFactory
Definition: TempFSFileFactory.php:10
TempFSFile
This class is used to hold the location and do limited manipulation of files stored temporarily (this...
Definition: TempFSFile.php:35
TempFSFile\getUsableTempDirectory
static getUsableTempDirectory()
Definition: TempFSFile.php:80
$path
$path
Definition: NoLocalSettings.php:25
$ext
if(!is_readable( $file)) $ext
Definition: router.php:48
MediaWiki\FileBackend\FSFile\TempFSFileFactory\newTempFSFile
newTempFSFile( $prefix, $extension='')
Make a new temporary file on the file system.
Definition: TempFSFileFactory.php:30
MediaWiki\FileBackend\FSFile\TempFSFileFactory\$tmpDirectory
string null $tmpDirectory
Definition: TempFSFileFactory.php:12
MediaWiki\FileBackend\FSFile
Definition: TempFSFileFactory.php:3