1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Provisioning\Api\Node\AbstractArgsNode |
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 2018 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/provisioning |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Provisioning\Api\Node; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Description\Annotations as DI; |
24
|
|
|
use AppserverIo\Description\Api\Node\AbstractNode; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Abstract node that serves nodes having a args/arg child. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2018 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/provisioning |
33
|
|
|
* @link http://www.appserver.io |
34
|
|
|
*/ |
35
|
|
|
abstract class AbstractArgsNode extends AbstractNode |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The script args to use. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
* @DI\Mapping(nodeName="args/arg", nodeType="array", elementType="AppserverIo\Provisioning\Api\Node\ArgNode") |
43
|
|
|
*/ |
44
|
|
|
protected $args = array(); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Attaches the passed arg to the list. |
48
|
|
|
* |
49
|
|
|
* @param \AppserverIo\Provisioning\Api\Node\ArgNode $arg The arg to attach |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function attachArg(ArgNode $arg) |
54
|
|
|
{ |
55
|
|
|
$this->args[] = $arg; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Array with the args to use. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getArgs() |
64
|
|
|
{ |
65
|
|
|
return $this->args; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns the arg with the passed name casted to |
70
|
|
|
* the specified type. |
71
|
|
|
* |
72
|
|
|
* @param string $name The name of the arg to be returned |
73
|
|
|
* |
74
|
|
|
* @return mixed The requested arg casted to the specified type |
75
|
|
|
*/ |
76
|
|
|
public function getArg($name) |
77
|
|
|
{ |
78
|
|
|
$args = $this->getArgsAsArray(); |
79
|
|
|
if (array_key_exists($name, $args)) { |
80
|
|
|
return $args[$name]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the args casted to the defined type |
86
|
|
|
* as associative array. |
87
|
|
|
* |
88
|
|
|
* @return array The array with the casted args |
89
|
|
|
*/ |
90
|
|
|
public function getArgsAsArray() |
91
|
|
|
{ |
92
|
|
|
$args = array(); |
93
|
|
|
/** @var \AppserverIo\Provisioning\Api\Node\ArgNode $arg */ |
94
|
|
|
foreach ($this->getArgs() as $arg) { |
95
|
|
|
$args[$arg->getName()] = $arg->castToType(); |
96
|
|
|
} |
97
|
|
|
return $args; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|