MainJsonConfiguration::getServerConfigs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * \AppserverIo\Server\Configuration\MainJsonConfiguration
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Johann Zelger <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/server
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Server\Configuration;
22
23
use AppserverIo\Server\Interfaces\LoggerConfigurationInterface;
24
use AppserverIo\Server\Interfaces\MainConfigurationInterface;
25
use AppserverIo\Server\Interfaces\ServerConfigurationInterface;
26
use AppserverIo\Server\Interfaces\UpstreamConfigurationInterface;
27
28
/**
29
 * Class MainJsonConfiguration
30
 *
31
 * @author    Johann Zelger <[email protected]>
32
 * @copyright 2015 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/appserver-io/server
35
 * @link      http://www.appserver.io
36
 */
37
class MainJsonConfiguration implements MainConfigurationInterface
38
{
39
    /**
40
     * Hold's the data instance read by json file
41
     *
42
     * @var \stdClass
43
     */
44
    protected $data;
45
46
    /**
47
     * Constructs the config by given filename
48
     *
49
     * @param string $filename The filename to init the config with
50
     */
51
    public function __construct($filename)
52
    {
53
        $this->data = json_decode(file_get_contents($filename, FILE_USE_INCLUDE_PATH));
54
    }
55
56
    /**
57
     * Return's an array of server configs
58
     *
59
     * @return ServerConfigurationInterface[]
60
     */
61
    public function getServerConfigs()
62
    {
63
        $serverConfigurations = array();
64
        foreach ($this->data->servers as $serverConfig) {
65
            $serverConfigurations[] = new ServerJsonConfiguration($serverConfig);
66
        }
67
68
        return $serverConfigurations;
69
    }
70
71
    /**
72
     * Return's an array of logger configs
73
     *
74
     * @return LoggerConfigurationInterface[]
75
     */
76
    public function getLoggerConfigs()
77
    {
78
        $loggerConfigurations = array();
79
        foreach ($this->data->loggers as $loggerConfig) {
80
            $loggerConfigurations[] = new LoggerJsonConfiguration($loggerConfig);
81
        }
82
83
        return $loggerConfigurations;
84
    }
85
86
    /**
87
     * Return's upstream config nodes as array
88
     *
89
     * @return UpstreamConfigurationInterface[]
90
     */
91
    public function getUpstreamConfigs()
92
    {
93
        $upstreamConfigs = array();
94
        if (isset($this->data->upstreams)) {
95
            foreach ($this->data->upstreams as $upstreamConfig) {
96
                $upstreamConfigs[] = new UpstreamJsonConfiguration($upstreamConfig);
97
            }
98
        }
99
100
        return $upstreamConfigs;
101
    }
102
}
103