Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
52.38% |
11 / 21 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| SystemHelper | |
52.38% |
11 / 21 |
|
25.00% |
1 / 4 |
17.75 | |
0.00% |
0 / 1 |
| getFileUploadLimit | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| isWindows | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOperatingSystem | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| toBytes | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 | |||
| 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) 2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\generis\Helper; |
| 23 | |
| 24 | class SystemHelper |
| 25 | { |
| 26 | /** |
| 27 | * Returns the maximum size for fileuploads in bytes. |
| 28 | * |
| 29 | * @return int The upload file limit. |
| 30 | */ |
| 31 | public static function getFileUploadLimit() |
| 32 | { |
| 33 | $limits = [ |
| 34 | self::toBytes(ini_get('upload_max_filesize')), |
| 35 | self::toBytes(ini_get('post_max_size')) |
| 36 | ]; |
| 37 | |
| 38 | if (ini_get('memory_limit') !== '-1') { |
| 39 | $limits[] = self::toBytes(ini_get('memory_limit')); |
| 40 | } |
| 41 | |
| 42 | return min($limits); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * Returns whenever or not Tao is installed on windows |
| 48 | * @return boolean |
| 49 | */ |
| 50 | public static function isWindows() |
| 51 | { |
| 52 | return strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the Operating System running TAO as a String. |
| 57 | * |
| 58 | * The returned value can be AFAIK: |
| 59 | * |
| 60 | * * 'WINNT' (Win XP, Windows NT, ...) |
| 61 | * * 'Linux' |
| 62 | * * 'FreeBSD' |
| 63 | * * 'Darwin' (Mac OS X) |
| 64 | * * 'CYGWIN_NT-5.1' |
| 65 | * * 'HP-UX' |
| 66 | * * 'IRIX64' |
| 67 | * * 'NetBSD' |
| 68 | * * 'OpenBSD' |
| 69 | * * 'SunOS' |
| 70 | * * 'Unix' |
| 71 | * * 'WIN32' |
| 72 | * * 'Windows' |
| 73 | * |
| 74 | * @return string The operating system that runs the script. |
| 75 | */ |
| 76 | public static function getOperatingSystem() |
| 77 | { |
| 78 | $returnValue = PHP_OS; |
| 79 | |
| 80 | return (string) $returnValue; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get the size in bytes of a PHP variable given as a string. |
| 85 | * |
| 86 | * @param string $phpSyntax The PHP syntax to describe the variable. |
| 87 | * @return int The size in bytes. |
| 88 | */ |
| 89 | private static function toBytes($phpSyntax) |
| 90 | { |
| 91 | $val = trim($phpSyntax); |
| 92 | $last = strtolower($val[strlen($val) - 1]); |
| 93 | if (!is_numeric($last)) { |
| 94 | $val = substr($val, 0, -1); |
| 95 | switch ($last) { |
| 96 | case 'g': |
| 97 | $val *= 1024; |
| 98 | // no break |
| 99 | case 'm': |
| 100 | $val *= 1024; |
| 101 | // no break |
| 102 | case 'k': |
| 103 | $val *= 1024; |
| 104 | } |
| 105 | } |
| 106 | return (int)$val; |
| 107 | } |
| 108 | } |