1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Server\Configuration\ModuleXmlConfiguration |
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 Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 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\ModuleConfigurationInterface; |
24
|
|
|
use AppserverIo\Server\Utils\ServerUtil; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Implementation for a module configuration. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/appserver-io/server |
33
|
|
|
* @link http://www.appserver.io |
34
|
|
|
*/ |
35
|
|
|
class ModuleXmlConfiguration implements ModuleConfigurationInterface |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The module's class name. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $type; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The module parameters. |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $params = array(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Constructs config |
54
|
|
|
* |
55
|
|
|
* @param \SimpleXMLElement $node The simple xml element used to build config |
56
|
|
|
*/ |
57
|
|
|
public function __construct($node) |
58
|
|
|
{ |
59
|
|
|
|
60
|
|
|
// prepare properties |
61
|
|
|
$this->type = (string) $node->attributes()->type; |
62
|
|
|
$this->params = $this->prepareParams($node); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the module's class name. |
67
|
|
|
* |
68
|
|
|
* @return string The module's class name |
69
|
|
|
*/ |
70
|
|
|
public function getType() |
71
|
|
|
{ |
72
|
|
|
return $this->type; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Array with the module params to use. |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function getParams() |
81
|
|
|
{ |
82
|
|
|
return $this->params; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns the param with the passed name casted to the specified type. |
87
|
|
|
* |
88
|
|
|
* @param string $name The name of the param to be returned |
89
|
|
|
* |
90
|
|
|
* @return mixed The requested param casted to the specified type |
91
|
|
|
*/ |
92
|
|
|
public function getParam($name) |
93
|
|
|
{ |
94
|
|
|
if (isset($this->params[$name])) { |
95
|
|
|
return $this->params[$name]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Prepares the modules array based on a simple xml element node |
101
|
|
|
* |
102
|
|
|
* @param \SimpleXMLElement $node The xml node |
103
|
|
|
* |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
protected function prepareParams(\SimpleXMLElement $node) |
107
|
|
|
{ |
108
|
|
|
|
109
|
|
|
// initialize the parameters |
110
|
|
|
$params = array(); |
111
|
|
|
|
112
|
|
|
// query whether or not parameters have been specified |
113
|
|
|
if ($node->params) { |
114
|
|
|
// append the passed parameters |
115
|
|
|
foreach ($node->params->param as $param) { |
116
|
|
|
$params[(string) $param->attributes()->name] = ServerUtil::singleton()->castToType((string) $param->attributes()->type, (string) $param); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// return the initialized parameters |
121
|
|
|
return $params; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|