1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\PhpGenerator;
9:
10: use Nette;
11:
12:
13: /**
14: * Method parameter description.
15: */
16: class Parameter
17: {
18: use Nette\SmartObject;
19:
20: /** @var string */
21: private $name = '';
22:
23: /** @var bool */
24: private $reference = FALSE;
25:
26: /** @var string|NULL */
27: private $typeHint;
28:
29: /** @var bool */
30: private $nullable = FALSE;
31:
32: /** @var bool */
33: private $hasDefaultValue = FALSE;
34:
35: /** @var mixed */
36: public $defaultValue;
37:
38:
39: /**
40: * @deprecated
41: * @return static
42: */
43: public static function from(\ReflectionParameter $from)
44: {
45: return (new Factory)->fromParameterReflection($from);
46: }
47:
48:
49: /**
50: * @param string without $
51: */
52: public function __construct($name = '')
53: {
54: $this->setName($name);
55: }
56:
57:
58: /** @deprecated */
59: public function setName($name)
60: {
61: $this->name = (string) $name;
62: return $this;
63: }
64:
65:
66: /**
67: * @return string
68: */
69: public function getName()
70: {
71: return $this->name;
72: }
73:
74:
75: /**
76: * @param bool
77: * @return static
78: */
79: public function setReference($state = TRUE)
80: {
81: $this->reference = (bool) $state;
82: return $this;
83: }
84:
85:
86: /**
87: * @return bool
88: */
89: public function isReference()
90: {
91: return $this->reference;
92: }
93:
94:
95: /**
96: * @param string|NULL
97: * @return static
98: */
99: public function setTypeHint($hint)
100: {
101: $this->typeHint = $hint ? (string) $hint : NULL;
102: return $this;
103: }
104:
105:
106: /**
107: * @return string|NULL
108: */
109: public function getTypeHint()
110: {
111: return $this->typeHint;
112: }
113:
114:
115: /**
116: * @param bool
117: * @return static
118: */
119: public function setOptional($state = TRUE)
120: {
121: $this->hasDefaultValue = (bool) $state;
122: return $this;
123: }
124:
125:
126: /**
127: * @deprecated use hasDefaultValue()
128: * @return bool
129: */
130: public function isOptional()
131: {
132: return $this->hasDefaultValue;
133: }
134:
135:
136: /**
137: * @param bool
138: * @return static
139: */
140: public function setNullable($state = TRUE)
141: {
142: $this->nullable = (bool) $state;
143: return $this;
144: }
145:
146:
147: /**
148: * @return bool
149: */
150: public function isNullable()
151: {
152: return $this->nullable;
153: }
154:
155:
156: /**
157: * @return static
158: */
159: public function setDefaultValue($val)
160: {
161: $this->defaultValue = $val;
162: return $this;
163: }
164:
165:
166: /**
167: * @return mixed
168: */
169: public function getDefaultValue()
170: {
171: return $this->defaultValue;
172: }
173:
174:
175: /**
176: * @return bool
177: */
178: public function hasDefaultValue()
179: {
180: return $this->hasDefaultValue;
181: }
182:
183: }
184: