| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * This file is part of the Nette Framework (https://nette.org)
- * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
- */
- declare(strict_types=1);
- namespace Nette\PhpGenerator;
- use Nette;
- use Nette\Utils\Type;
- /**
- * Function/Method parameter description.
- *
- * @property mixed $defaultValue
- */
- class Parameter
- {
- use Nette\SmartObject;
- use Traits\NameAware;
- use Traits\AttributeAware;
- /** @var bool */
- private $reference = false;
- /** @var string|null */
- private $type;
- /** @var bool */
- private $nullable = false;
- /** @var bool */
- private $hasDefaultValue = false;
- /** @var mixed */
- private $defaultValue;
- /** @return static */
- public function setReference(bool $state = true): self
- {
- $this->reference = $state;
- return $this;
- }
- public function isReference(): bool
- {
- return $this->reference;
- }
- /** @return static */
- public function setType(?string $type): self
- {
- $this->type = Helpers::validateType($type, $this->nullable);
- return $this;
- }
- /**
- * @return Type|string|null
- */
- public function getType(bool $asObject = false)
- {
- return $asObject && $this->type
- ? Type::fromString($this->type)
- : $this->type;
- }
- /** @deprecated use setType() */
- public function setTypeHint(?string $type): self
- {
- return $this->setType($type);
- }
- /** @deprecated use getType() */
- public function getTypeHint(): ?string
- {
- return $this->getType();
- }
- /**
- * @deprecated just use setDefaultValue()
- * @return static
- */
- public function setOptional(bool $state = true): self
- {
- trigger_error(__METHOD__ . '() is deprecated, use setDefaultValue()', E_USER_DEPRECATED);
- $this->hasDefaultValue = $state;
- return $this;
- }
- /** @return static */
- public function setNullable(bool $state = true): self
- {
- $this->nullable = $state;
- return $this;
- }
- public function isNullable(): bool
- {
- return $this->nullable;
- }
- /** @return static */
- public function setDefaultValue($val): self
- {
- $this->defaultValue = $val;
- $this->hasDefaultValue = true;
- return $this;
- }
- public function getDefaultValue()
- {
- return $this->defaultValue;
- }
- public function hasDefaultValue(): bool
- {
- return $this->hasDefaultValue;
- }
- public function validate(): void
- {
- }
- }
|