1 | <?php |
||
2 | /** |
||
3 | * Created by PhpStorm. |
||
4 | * User: execut |
||
5 | * Date: 9/27/16 |
||
6 | * Time: 2:36 PM |
||
7 | */ |
||
8 | |||
9 | namespace execut\import\components\source; |
||
10 | |||
11 | |||
12 | use yii\base\Component; |
||
13 | |||
14 | class File extends Component |
||
15 | { |
||
16 | public $fileName = null; |
||
17 | public $filePath = null; |
||
18 | public $folder = null; |
||
19 | protected $content = null; |
||
20 | 3 | public function getContent() { |
|
21 | 3 | if ($this->filePath !== null && $this->content === null) { |
|
22 | 1 | return file_get_contents($this->filePath); |
|
23 | } |
||
24 | |||
25 | 2 | return $this->content; |
|
26 | } |
||
27 | |||
28 | 3 | public function setContent($content) { |
|
29 | 3 | $this->content = $content; |
|
30 | 3 | if ($this->filePath !== null) { |
|
31 | 3 | file_put_contents($this->filePath, $this->content); |
|
32 | } |
||
33 | 3 | } |
|
34 | |||
35 | 10 | public function __destruct() |
|
36 | { |
||
37 | 10 | if ($this->filePath !== null && file_exists($this->filePath)) { |
|
38 | 5 | unlink($this->filePath); |
|
39 | 5 | @rmdir(dirname($this->filePath)); |
|
0 ignored issues
–
show
|
|||
40 | } |
||
41 | } |
||
42 | } |
If you suppress an error, we recommend checking for the error condition explicitly: