Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| FileHelperService | |
0.00% |
0 / 7 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
| readFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| closeFile | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| removeFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| removeDirectory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createTempDir | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020 (original work) Open Assessment Technologies SA ; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\helpers; |
| 24 | |
| 25 | use tao_helpers_File; |
| 26 | use oat\oatbox\service\ConfigurableService; |
| 27 | |
| 28 | /** |
| 29 | * Wrapper on top of tao_helpers_File and some filesystem related functionality. |
| 30 | * |
| 31 | * Class FileHelperService |
| 32 | * @package oat\tao\helpers |
| 33 | */ |
| 34 | class FileHelperService extends ConfigurableService |
| 35 | { |
| 36 | /** |
| 37 | * @param string $filePath |
| 38 | * @return false|resource |
| 39 | */ |
| 40 | public function readFile(string $filePath) |
| 41 | { |
| 42 | return fopen($filePath, 'r'); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param resource $fileResource |
| 47 | * @return bool |
| 48 | */ |
| 49 | public function closeFile($fileResource): bool |
| 50 | { |
| 51 | if (!is_resource($fileResource)) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | return fclose($fileResource); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @param string $filePath |
| 60 | * @return bool |
| 61 | */ |
| 62 | public function removeFile(string $filePath): bool |
| 63 | { |
| 64 | return tao_helpers_File::remove($filePath, false); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @param string $directoryPath |
| 69 | * @return bool |
| 70 | */ |
| 71 | public function removeDirectory(string $directoryPath): bool |
| 72 | { |
| 73 | return tao_helpers_File::remove($directoryPath, true); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return string Path to created directory |
| 78 | */ |
| 79 | public function createTempDir(): string |
| 80 | { |
| 81 | return tao_helpers_File::createTempDir(); |
| 82 | } |
| 83 | } |