Completed
Push — master ( b7740b...1b9e68 )
by Daniel
02:24
created

InformatorServer::getServerSoftware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 getTemporaryFolder()
85
    {
86
        return sys_get_temp_dir() . DIRECTORY_SEPARATOR;
87
    }
88
}
89