1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Server\Configuration\ModuleJsonConfiguration |
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
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Implementation for a module configuration. |
27
|
|
|
* |
28
|
|
|
* @author Tim Wagner <[email protected]> |
29
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
31
|
|
|
* @link https://github.com/appserver-io/server |
32
|
|
|
* @link http://www.appserver.io |
33
|
|
|
*/ |
34
|
|
|
class ModuleJsonConfiguration implements ModuleConfigurationInterface |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Holds raw data instance |
39
|
|
|
* |
40
|
|
|
* @var \stdClass |
41
|
|
|
*/ |
42
|
|
|
protected $data; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The module parameters. |
46
|
|
|
* |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $params = array(); |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Constructs config |
53
|
|
|
* |
54
|
|
|
* @param \stdClass $node The JSON node used to build config |
55
|
|
|
*/ |
56
|
|
|
public function __construct($node) |
57
|
|
|
{ |
58
|
|
|
|
59
|
|
|
// prepare properties |
60
|
|
|
$this->type = $node->type; |
|
|
|
|
61
|
|
|
$this->params = $node->params; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns the module's class name. |
66
|
|
|
* |
67
|
|
|
* @return string The module's class name |
68
|
|
|
*/ |
69
|
|
|
public function getType() |
70
|
|
|
{ |
71
|
|
|
return $this->type; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Array with the module params to use. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function getParams() |
80
|
|
|
{ |
81
|
|
|
return $this->params; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the param with the passed name casted to the specified type. |
86
|
|
|
* |
87
|
|
|
* @param string $name The name of the param to be returned |
88
|
|
|
* |
89
|
|
|
* @return mixed The requested param casted to the specified type |
90
|
|
|
*/ |
91
|
|
|
public function getParam($name) |
92
|
|
|
{ |
93
|
|
|
if (isset($this->params[$name])) { |
94
|
|
|
return $this->params[$name]; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: