|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright 2011 Johannes M. Schmitt <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
namespace gossi\codegen\model; |
|
18
|
|
|
|
|
19
|
|
|
use gossi\codegen\model\parts\NamePart; |
|
20
|
|
|
use gossi\codegen\model\parts\TypePart; |
|
21
|
|
|
use gossi\codegen\model\parts\ValuePart; |
|
22
|
|
|
use gossi\docblock\tags\ParamTag; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Represents a PHP parameter. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
|
28
|
|
|
* @author Thomas Gossmann |
|
29
|
|
|
*/ |
|
30
|
|
|
class PhpParameter extends AbstractModel implements ValueInterface { |
|
31
|
|
|
|
|
32
|
|
|
use NamePart; |
|
33
|
|
|
use TypePart; |
|
34
|
|
|
use ValuePart; |
|
35
|
|
|
|
|
36
|
|
|
private $passedByReference = false; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Creates a new PHP parameter. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $name the parameter name |
|
42
|
|
|
* @return static |
|
43
|
|
|
*/ |
|
44
|
17 |
|
public static function create($name = null) { |
|
45
|
17 |
|
return new static($name); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Creates a new PHP parameter |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $name the parameter name |
|
52
|
|
|
*/ |
|
53
|
28 |
|
public function __construct($name = null) { |
|
54
|
28 |
|
$this->setName($name); |
|
55
|
28 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Sets whether this parameter is passed by reference |
|
59
|
|
|
* |
|
60
|
|
|
* @param bool $bool `true` if passed by reference and `false` if not |
|
61
|
|
|
* @return $this |
|
62
|
|
|
*/ |
|
63
|
8 |
|
public function setPassedByReference($bool) { |
|
64
|
8 |
|
$this->passedByReference = (boolean) $bool; |
|
65
|
|
|
|
|
66
|
8 |
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns whether this parameter is passed by reference |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool `true` if passed by reference and `false` if not |
|
73
|
|
|
*/ |
|
74
|
11 |
|
public function isPassedByReference() { |
|
75
|
11 |
|
return $this->passedByReference; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns a docblock tag for this parameter |
|
80
|
|
|
* |
|
81
|
|
|
* @return ParamTag |
|
82
|
|
|
*/ |
|
83
|
7 |
|
public function getDocblockTag() { |
|
84
|
7 |
|
return ParamTag::create() |
|
85
|
7 |
|
->setType($this->getType()) |
|
86
|
7 |
|
->setVariable($this->getName()) |
|
87
|
7 |
|
->setDescription($this->getTypeDescription()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Alias for setDescription() |
|
92
|
|
|
* |
|
93
|
|
|
* @see #setDescription |
|
94
|
|
|
* @param string $description |
|
95
|
|
|
* @return $this |
|
96
|
|
|
*/ |
|
97
|
4 |
|
public function setTypeDescription($description) { |
|
98
|
4 |
|
return $this->setDescription($description); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Alias for getDescription() |
|
103
|
|
|
* |
|
104
|
|
|
* @see #getDescription |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
9 |
|
public function getTypeDescription() { |
|
108
|
9 |
|
return $this->getDescription(); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|