38 parent::__construct(
$path );
40 if ( self::$pathsCollect === null ) {
41 self::$pathsCollect = [];
42 register_shutdown_function( [ __CLASS__,
'purgeAllOnShutdown' ] );
54 public static function factory( $prefix, $extension =
'' ) {
55 $ext = ( $extension !=
'' ) ?
".{$extension}" :
'';
58 while ( $attempts-- ) {
60 MediaWiki\suppressWarnings();
61 $newFileHandle = fopen(
$path,
'x' );
62 MediaWiki\restoreWarnings();
63 if ( $newFileHandle ) {
64 fclose( $newFileHandle );
65 $tmpFile =
new self(
$path );
66 $tmpFile->autocollect();
82 $this->canDelete =
false;
83 MediaWiki\suppressWarnings();
84 $ok = unlink( $this->path );
85 MediaWiki\restoreWarnings();
87 unset( self::$pathsCollect[$this->path] );
98 public function bind( $object ) {
99 if ( is_object( $object ) ) {
100 if ( !isset( $object->tempFSFileReferences ) ) {
102 $object->tempFSFileReferences = [];
104 $object->tempFSFileReferences[] = $this;
116 $this->canDelete =
false;
118 unset( self::$pathsCollect[$this->path] );
129 $this->canDelete =
true;
142 foreach ( self::$pathsCollect
as $path ) {
143 MediaWiki\suppressWarnings();
145 MediaWiki\restoreWarnings();
153 if ( $this->canDelete ) {
static factory($prefix, $extension= '')
Make a new temporary file on the file system.
string $path
Path to file.
bool $canDelete
Garbage collect the temp file.
This class is used to hold the location and do limited manipulation of files stored temporarily (this...
autocollect()
Set flag clean up after the temporary file.
__destruct()
Cleans up after the temporary file by deleting it.
wfRandomString($length=32)
Get a random string containing a number of pseudo-random hex characters.
wfTempDir()
Tries to get the system directory for temporary files.
static array $pathsCollect
Map of (path => 1) for paths to delete on shutdown.
preserve()
Set flag to not clean up after the temporary file.
purge()
Purge this file off the file system.
static purgeAllOnShutdown()
Try to make sure that all files are purged on error.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Class representing a non-directory file on the file system.
bind($object)
Clean up the temporary file only after an object goes out of scope.