1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Morris Jobke <[email protected]> |
4
|
|
|
* @author Thomas Müller <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OC\App; |
24
|
|
|
|
25
|
|
|
use OC_Util; |
26
|
|
|
use OCP\IConfig; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class Platform |
30
|
|
|
* |
31
|
|
|
* This class basically abstracts any kind of information which can be retrieved from the underlying system. |
32
|
|
|
* |
33
|
|
|
* @package OC\App |
34
|
|
|
*/ |
35
|
|
|
class Platform { |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param IConfig $config |
39
|
|
|
*/ |
40
|
|
|
function __construct(IConfig $config) { |
41
|
|
|
$this->config = $config; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function getPhpVersion() { |
48
|
|
|
return phpversion(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return int |
53
|
|
|
*/ |
54
|
|
|
public function getIntSize() { |
55
|
|
|
return PHP_INT_SIZE; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getOcVersion() { |
62
|
|
|
$v = \OCP\Util::getVersion(); |
63
|
|
|
return join('.', $v); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getDatabase() { |
70
|
|
|
$dbType = $this->config->getSystemValue('dbtype', 'sqlite'); |
71
|
|
|
if ($dbType === 'sqlite3') { |
72
|
|
|
$dbType = 'sqlite'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $dbType; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getOS() { |
82
|
|
|
return php_uname('s'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $command |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isCommandKnown($command) { |
90
|
|
|
$path = \OC_Helper::findBinaryPath($command); |
91
|
|
|
return ($path !== null); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getLibraryVersion($name) { |
95
|
|
|
$repo = new PlatformRepository(); |
96
|
|
|
$lib = $repo->findLibrary($name); |
97
|
|
|
return $lib; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: