Completed
Push — master ( f0c4e3...468cfb )
by Tim
9s
created

MainJsonConfiguration::getUpstreamConfigs()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.4285
cc 3
eloc 6
nc 2
nop 0
crap 12
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