= 5 ) { 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; // done wfSuppressWarnings(); $ok = unlink( $this->path ); wfRestoreWarnings(); return $ok; } /** * Clean up the temporary file only after an object goes out of scope * * @param $object Object * @return TempFSFile This object */ public function bind( $object ) { if ( is_object( $object ) ) { if ( !isset( $object->tempFSFileReferences ) ) { // Init first since $object might use __get() and return only a copy variable $object->tempFSFileReferences = array(); } $object->tempFSFileReferences[] = $this; } return $this; } /** * Set flag to not clean up after the temporary file * * @return TempFSFile This object */ public function preserve() { $this->canDelete = false; return $this; } /** * Set flag clean up after the temporary file * * @return TempFSFile This object */ public function autocollect() { $this->canDelete = true; return $this; } /** * Cleans up after the temporary file by deleting it */ function __destruct() { if ( $this->canDelete ) { wfSuppressWarnings(); unlink( $this->path ); wfRestoreWarnings(); } } }