/**
* Make a new temporary file on the file system.
* Temporary files may be purged when the file object falls out of scope.
- *
+ *
* @param $prefix string
* @param $extension string
- * @return TempFSFile|null
+ * @return TempFSFile|null
*/
public static function factory( $prefix, $extension = '' ) {
+ wfProfileIn( __METHOD__ );
$base = wfTempDir() . '/' . $prefix . dechex( mt_rand( 0, 99999999 ) );
$ext = ( $extension != '' ) ? ".{$extension}" : "";
for ( $attempt = 1; true; $attempt++ ) {
break; // got it
}
if ( $attempt >= 15 ) {
+ wfProfileOut( __METHOD__ );
return null; // give up
}
}
$tmpFile = new self( $path );
$tmpFile->canDelete = true; // safely instantiated
+ wfProfileOut( __METHOD__ );
return $tmpFile;
}
/**
* Purge this file off the file system
- *
+ *
* @return bool Success
*/
public function purge() {
$this->canDelete = false;
}
+ /**
+ * Set flag clean up after the temporary file
+ *
+ * @return void
+ */
+ public function autocollect() {
+ $this->canDelete = true;
+ }
+
/**
* Cleans up after the temporary file by deleting it
*/