|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \AppserverIo\Doppelgaenger\Entities\Definitions\ParameterDefinition |
|
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 Bernhard Wick <[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/doppelgaenger |
|
18
|
|
|
* @link http://www.appserver.io/ |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Doppelgaenger\Entities\Definitions; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Allows us to keep track of a functions parameters |
|
25
|
|
|
* |
|
26
|
|
|
* @author Bernhard Wick <[email protected]> |
|
27
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
|
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
29
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
|
30
|
|
|
* @link http://www.appserver.io/ |
|
31
|
|
|
*/ |
|
32
|
|
|
class ParameterDefinition |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string $type Type hint (if any) |
|
36
|
|
|
*/ |
|
37
|
|
|
public $type; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string $name Name of the parameter |
|
41
|
|
|
*/ |
|
42
|
|
|
public $name; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var mixed $defaultValue The parameter's default value (if any) |
|
46
|
|
|
*/ |
|
47
|
|
|
public $defaultValue; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Default constructor |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->type = ''; |
|
55
|
|
|
$this->name = ''; |
|
56
|
|
|
$this->defaultValue = ''; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Will return a string representation of the defined parameter |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $mode We can switch how the string should be structured. |
|
63
|
|
|
* Choose from "definition", "call" |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getString($mode = 'definition') |
|
68
|
|
|
{ |
|
69
|
|
|
// Prepare the parts |
|
70
|
|
|
$stringParts = array(); |
|
71
|
|
|
|
|
72
|
|
|
if ($mode === 'call') { |
|
73
|
|
|
// Get the name |
|
74
|
|
|
$stringParts[] = $this->name; |
|
75
|
|
|
|
|
|
|
|
|
|
76
|
|
|
} elseif ($mode === 'definition') { |
|
77
|
|
|
// Get the type |
|
78
|
|
|
$stringParts[] = $this->type; |
|
79
|
|
|
|
|
80
|
|
|
// Get the name |
|
81
|
|
|
$stringParts[] = $this->name; |
|
82
|
|
|
|
|
83
|
|
|
if ($this->defaultValue !== '') { |
|
84
|
|
|
// Get the default value |
|
85
|
|
|
$stringParts[] = '='; |
|
86
|
|
|
$stringParts[] = $this->defaultValue; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
|
89
|
|
|
} else { |
|
90
|
|
|
return ''; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return implode(' ', $stringParts); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|