|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees: online genealogy |
|
5
|
|
|
* Copyright (C) 2023 webtrees development team |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU General Public License |
|
15
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\Services; |
|
21
|
|
|
|
|
22
|
|
|
use RuntimeException; |
|
23
|
|
|
|
|
24
|
|
|
use function extension_loaded; |
|
25
|
|
|
use function function_exists; |
|
26
|
|
|
use function ini_get; |
|
27
|
|
|
use function ini_parse_quantity; |
|
|
|
|
|
|
28
|
|
|
use function sys_get_temp_dir; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Access to the PHP environment - to facilitate mocking/testing. |
|
32
|
|
|
*/ |
|
33
|
|
|
class PhpService |
|
34
|
|
|
{ |
|
35
|
|
|
public function extensionLoaded(string $extension): bool |
|
36
|
|
|
{ |
|
37
|
|
|
return extension_loaded(extension: $extension); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function functionExists(string $function): bool |
|
41
|
|
|
{ |
|
42
|
|
|
return function_exists(function: $function); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function sysGetTempDir(): string |
|
46
|
|
|
{ |
|
47
|
|
|
return sys_get_temp_dir(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function displayErrors(): bool |
|
51
|
|
|
{ |
|
52
|
|
|
return (bool) $this->iniGet(option: 'display_errors'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function maxExecutionTime(): int |
|
56
|
|
|
{ |
|
57
|
|
|
return (int) $this->iniGet(option: 'max_execution_time'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function memoryLimit(): int |
|
61
|
|
|
{ |
|
62
|
|
|
return ini_parse_quantity(shorthand: $this->iniGet(option: 'memory_limit')); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function postMaxSize(): int |
|
66
|
|
|
{ |
|
67
|
|
|
return ini_parse_quantity(shorthand: $this->iniGet(option: 'post_max_size')); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function uploadMaxFilesize(): int |
|
71
|
|
|
{ |
|
72
|
|
|
return ini_parse_quantity(shorthand: $this->iniGet(option: 'upload_max_filesize')); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function iniGet(string $option): string |
|
76
|
|
|
{ |
|
77
|
|
|
$value = ini_get(option: $option); |
|
78
|
|
|
|
|
79
|
|
|
if ($value === false) { |
|
80
|
|
|
throw new RuntimeException(message: 'Cannot read PHP configuration: ' . $option); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $value; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|