35 private static $references;
43 parent::__construct(
$path );
45 if ( self::$pathsCollect ===
null ) {
47 self::$pathsCollect = [];
48 register_shutdown_function( self::purgeAllOnShutdown( ... ) );
64 public static function factory( $prefix, $extension =
'', $tmpDirectory =
null ) {
65 return (
new TempFSFileFactory( $tmpDirectory ) )->newTempFSFile( $prefix, $extension );
76 $tmpDir = array_map(
'getenv', [
'TMPDIR',
'TMP',
'TEMP' ] );
77 $tmpDir[] = sys_get_temp_dir();
78 $tmpDir[] = ini_get(
'upload_tmp_dir' );
79 foreach ( $tmpDir as $tmp ) {
80 if ( $tmp !=
'' && is_dir( $tmp ) && is_writable( $tmp ) ) {
85 throw new RuntimeException(
86 'No writable temporary directory could be found. ' .
87 'Please explicitly specify a writable directory in configuration.' );
96 $this->canDelete =
false;
98 $ok = @unlink( $this->path );
100 unset( self::$pathsCollect[$this->path] );
111 public function bind( $object ) {
112 if ( is_object( $object ) ) {
114 if ( self::$references ===
null ) {
115 self::$references =
new WeakMap;
117 self::$references[$object] = $this;
129 $this->canDelete =
false;
131 unset( self::$pathsCollect[$this->path] );
142 $this->canDelete =
true;
157 foreach ( self::$pathsCollect as
$path => $unused ) {
167 if ( $this->canDelete ) {
174class_alias( TempFSFile::class,
'TempFSFile' );