|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2016 Daniel Popiniuc. |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
10
|
|
|
* in the Software without restriction, including without limitation the rights |
|
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
13
|
|
|
* furnished to do so, subject to the following conditions: |
|
14
|
|
|
* |
|
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
16
|
|
|
* all copies or substantial portions of the Software. |
|
17
|
|
|
* |
|
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
24
|
|
|
* THE SOFTWARE. |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace danielgp\informator; |
|
28
|
|
|
|
|
29
|
|
|
trait InformatorServer |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
protected function getDoctrineCaheFolder() |
|
33
|
|
|
{ |
|
34
|
|
|
$tmpFolder = $this->getTemporaryFolder(); |
|
35
|
|
|
$tmpDoctrineCache = null; |
|
36
|
|
|
clearstatcache(); |
|
37
|
|
|
if (is_dir($tmpFolder) && is_writable($tmpFolder)) { |
|
38
|
|
|
$tmpDoctrineCache = $tmpFolder . DIRECTORY_SEPARATOR . 'DoctrineCache'; |
|
39
|
|
|
} |
|
40
|
|
|
return $tmpDoctrineCache; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function getServerDetailsEvaluated($hostName) |
|
44
|
|
|
{ |
|
45
|
|
|
$serverMachineType = 'unknown'; |
|
46
|
|
|
$serverInfo = [ |
|
47
|
|
|
'name' => 'undisclosed', |
|
48
|
|
|
'host' => $hostName, |
|
49
|
|
|
'release' => 'undisclosed', |
|
50
|
|
|
'version' => 'undisclosed', |
|
51
|
|
|
]; |
|
52
|
|
|
if (function_exists('php_uname')) { |
|
53
|
|
|
$infServerFromPhp = $this->getServerDetailsFromPhp(); |
|
54
|
|
|
$serverMachineType = $infServerFromPhp['OS Architecture']; |
|
55
|
|
|
$serverInfo = $infServerFromPhp['OS Name+Host+Release+Version']; |
|
56
|
|
|
} |
|
57
|
|
|
return [ |
|
58
|
|
|
'serverMachineType' => $serverMachineType, |
|
59
|
|
|
'serverInfo' => $serverInfo, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function getServerDetailsFromPhp() |
|
64
|
|
|
{ |
|
65
|
|
|
$aReturn = []; |
|
66
|
|
|
$aReturn['OS Architecture'] = php_uname('m'); |
|
67
|
|
|
$knownValues = [ |
|
68
|
|
|
'AMD64' => 'x64 (64 bit)', |
|
69
|
|
|
'i386' => 'x86 (32 bit)', |
|
70
|
|
|
'i586' => 'x86 (32 bit)', |
|
71
|
|
|
]; |
|
72
|
|
|
if (array_key_exists(php_uname('m'), $knownValues)) { |
|
73
|
|
|
$aReturn['OS Architecture'] = $knownValues[php_uname('m')]; |
|
74
|
|
|
} |
|
75
|
|
|
$aReturn['OS Name+Host+Release+Version'] = [ |
|
76
|
|
|
'name' => php_uname('s'), |
|
77
|
|
|
'host' => php_uname('n'), |
|
78
|
|
|
'release' => php_uname('r'), |
|
79
|
|
|
'version' => php_uname('v'), |
|
80
|
|
|
]; |
|
81
|
|
|
return $aReturn; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function getServerSoftware() |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
return $_SERVER['SERVER_SOFTWARE']; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
protected function getTemporaryFolder() |
|
90
|
|
|
{ |
|
91
|
|
|
return sys_get_temp_dir() . DIRECTORY_SEPARATOR; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: