@@ -16,15 +16,15 @@ |
||
16 | 16 | * @param boolean $overwrite 是否覆盖已有文件 |
17 | 17 | * @return boolean |
18 | 18 | */ |
19 | - static public function write($path, $data, $overwrite = true){ |
|
19 | + static public function write($path, $data, $overwrite = true) { |
|
20 | 20 | $path = str_replace('\\', '/', $path); |
21 | 21 | $fileDir = dirname($path); |
22 | 22 | $tmpFile = tempnam($fileDir, 'safe_writer_'); |
23 | 23 | false !== @file_put_contents($tmpFile, $data) or \PhpBoot\abort("write to file: $tmpFile failed"); |
24 | - if($overwrite){ |
|
24 | + if ($overwrite) { |
|
25 | 25 | @unlink($path); //删除原始文件 |
26 | 26 | } |
27 | - if(!rename($tmpFile, $path)){ |
|
27 | + if (!rename($tmpFile, $path)) { |
|
28 | 28 | @unlink($tmpFile); //删除原始文件 |
29 | 29 | \PhpBoot\abort("write to file: $tmpFile failed"); |
30 | 30 | return false; |
@@ -8,17 +8,17 @@ |
||
8 | 8 | private $file; |
9 | 9 | public function lock($key, $ttl) |
10 | 10 | { |
11 | - if($this->locked){ |
|
11 | + if ($this->locked) { |
|
12 | 12 | \PhpBoot\abort("relock $key"); |
13 | 13 | } |
14 | 14 | $path = sys_get_temp_dir().'/lock_252a8fdc9b944af99a9bc53d2aea08f1_'.$key; |
15 | 15 | $this->file = @fopen($path, 'a'); |
16 | 16 | if (!$this->file || !flock($this->file, LOCK_EX | LOCK_NB)) { |
17 | - if($this->file){ |
|
17 | + if ($this->file) { |
|
18 | 18 | fclose($this->file); |
19 | 19 | } |
20 | 20 | return false; |
21 | - } else { |
|
21 | + }else { |
|
22 | 22 | $this->locked = true; |
23 | 23 | } |
24 | 24 | return true; |