execut /
yii2-import
| 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 | 2 | public function getContent() { |
|
| 21 | 2 | if ($this->filePath !== null && $this->content === null) { |
|
| 22 | 1 | return file_get_contents($this->filePath); |
|
| 23 | } |
||
| 24 | |||
| 25 | 1 | return $this->content; |
|
| 26 | } |
||
| 27 | |||
| 28 | 2 | public function setContent($content) { |
|
| 29 | 2 | $this->content = $content; |
|
| 30 | 2 | if ($this->filePath !== null) { |
|
| 31 | 2 | file_put_contents($this->filePath, $this->content); |
|
| 32 | } |
||
| 33 | 2 | } |
|
| 34 | |||
| 35 | 9 | public function __destruct() |
|
| 36 | { |
||
| 37 | 9 | if ($this->filePath !== null && file_exists($this->filePath)) { |
|
| 38 | 4 | unlink($this->filePath); |
|
| 39 | 4 | @rmdir(dirname($this->filePath)); |
|
|
0 ignored issues
–
show
|
|||
| 40 | } |
||
| 41 | } |
||
| 42 | } |
If you suppress an error, we recommend checking for the error condition explicitly: