@@ -47,7 +47,6 @@ private function init($namespace, $directory)
47
47
}
48
48
49
49
$ this ->directory = $ dir ;
50
- $ this ->tmp = $ this ->directory .uniqid ('' , true );
51
50
}
52
51
53
52
/**
@@ -81,19 +80,21 @@ protected function doDelete(array $ids)
81
80
82
81
private function write ($ file , $ data , $ expiresAt = null )
83
82
{
84
- if ( false === @ file_put_contents ( $ this -> tmp , $ data )) {
85
- return false ;
86
- }
87
- if ( null !== $ expiresAt ) {
88
- @ touch ( $ this -> tmp , $ expiresAt );
89
- }
83
+ set_error_handler ( __CLASS__ . ' ::throwError ' );
84
+ try {
85
+ if ( null === $ this -> tmp ) {
86
+ $ this -> tmp = $ this -> directory . uniqid ( '' , true );
87
+ }
88
+ file_put_contents ( $ this -> tmp , $ data );
90
89
91
- if (@rename ($ this ->tmp , $ file )) {
92
- return true ;
93
- }
94
- @unlink ($ this ->tmp );
90
+ if (null !== $ expiresAt ) {
91
+ touch ($ this ->tmp , $ expiresAt );
92
+ }
95
93
96
- return false ;
94
+ return rename ($ this ->tmp , $ file );
95
+ } finally {
96
+ restore_error_handler ();
97
+ }
97
98
}
98
99
99
100
private function getFile ($ id , $ mkdir = false )
@@ -107,4 +108,20 @@ private function getFile($id, $mkdir = false)
107
108
108
109
return $ dir .substr ($ hash , 2 , 20 );
109
110
}
111
+
112
+ /**
113
+ * @internal
114
+ */
115
+ public static function throwError ($ type , $ message , $ file , $ line )
116
+ {
117
+ throw new \ErrorException ($ message , 0 , $ type , $ file , $ line );
118
+ }
119
+
120
+ public function __destruct ()
121
+ {
122
+ parent ::__destruct ();
123
+ if (null !== $ this ->tmp && file_exists ($ this ->tmp )) {
124
+ unlink ($ this ->tmp );
125
+ }
126
+ }
110
127
}
0 commit comments