| 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 |
declare (strict_types=1); |
| 8 |
namespace Packetery\Nette\PhpGenerator; |
| 9 |
|
| 10 |
use Packetery\Nette; |
| 11 |
/** |
| 12 |
* Function/Method parameter description. |
| 13 |
* |
| 14 |
* @property mixed $defaultValue |
| 15 |
*/ |
| 16 |
class Parameter |
| 17 |
{ |
| 18 |
use \Packetery\Nette\SmartObject; |
| 19 |
use Traits\NameAware; |
| 20 |
use Traits\AttributeAware; |
| 21 |
/** @var bool */ |
| 22 |
private $reference = \false; |
| 23 |
/** @var string|null */ |
| 24 |
private $type; |
| 25 |
/** @var bool */ |
| 26 |
private $nullable = \false; |
| 27 |
/** @var bool */ |
| 28 |
private $hasDefaultValue = \false; |
| 29 |
/** @var mixed */ |
| 30 |
private $defaultValue; |
| 31 |
/** @return static */ |
| 32 |
public function setReference(bool $state = \true) : self |
| 33 |
{ |
| 34 |
$this->reference = $state; |
| 35 |
return $this; |
| 36 |
} |
| 37 |
public function isReference() : bool |
| 38 |
{ |
| 39 |
return $this->reference; |
| 40 |
} |
| 41 |
/** @return static */ |
| 42 |
public function setType(?string $type) : self |
| 43 |
{ |
| 44 |
if ($type && $type[0] === '?') { |
| 45 |
$type = \substr($type, 1); |
| 46 |
$this->nullable = \true; |
| 47 |
} |
| 48 |
$this->type = $type; |
| 49 |
return $this; |
| 50 |
} |
| 51 |
public function getType() : ?string |
| 52 |
{ |
| 53 |
return $this->type; |
| 54 |
} |
| 55 |
/** @deprecated use setType() */ |
| 56 |
public function setTypeHint(?string $type) : self |
| 57 |
{ |
| 58 |
$this->type = $type; |
| 59 |
return $this; |
| 60 |
} |
| 61 |
/** @deprecated use getType() */ |
| 62 |
public function getTypeHint() : ?string |
| 63 |
{ |
| 64 |
return $this->type; |
| 65 |
} |
| 66 |
/** |
| 67 |
* @deprecated just use setDefaultValue() |
| 68 |
* @return static |
| 69 |
*/ |
| 70 |
public function setOptional(bool $state = \true) : self |
| 71 |
{ |
| 72 |
\trigger_error(__METHOD__ . '() is deprecated, use setDefaultValue()', \E_USER_DEPRECATED); |
| 73 |
$this->hasDefaultValue = $state; |
| 74 |
return $this; |
| 75 |
} |
| 76 |
/** @return static */ |
| 77 |
public function setNullable(bool $state = \true) : self |
| 78 |
{ |
| 79 |
$this->nullable = $state; |
| 80 |
return $this; |
| 81 |
} |
| 82 |
public function isNullable() : bool |
| 83 |
{ |
| 84 |
return $this->nullable; |
| 85 |
} |
| 86 |
/** @return static */ |
| 87 |
public function setDefaultValue($val) : self |
| 88 |
{ |
| 89 |
$this->defaultValue = $val; |
| 90 |
$this->hasDefaultValue = \true; |
| 91 |
return $this; |
| 92 |
} |
| 93 |
public function getDefaultValue() |
| 94 |
{ |
| 95 |
return $this->defaultValue; |
| 96 |
} |
| 97 |
public function hasDefaultValue() : bool |
| 98 |
{ |
| 99 |
return $this->hasDefaultValue; |
| 100 |
} |
| 101 |
} |
| 102 |
|