截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Property.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * This file is part of the Nette Framework (https://nette.org)
  4. * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  5. */
  6. declare(strict_types=1);
  7. namespace Nette\PhpGenerator;
  8. use Nette;
  9. /**
  10. * Class property description.
  11. *
  12. * @property mixed $value
  13. */
  14. final class Property
  15. {
  16. use Nette\SmartObject;
  17. use Traits\NameAware;
  18. use Traits\VisibilityAware;
  19. use Traits\CommentAware;
  20. use Traits\AttributeAware;
  21. /** @var mixed */
  22. private $value;
  23. /** @var bool */
  24. private $static = false;
  25. /** @var string|null */
  26. private $type;
  27. /** @var bool */
  28. private $nullable = false;
  29. /** @var bool */
  30. private $initialized = false;
  31. /** @return static */
  32. public function setValue($val): self
  33. {
  34. $this->value = $val;
  35. $this->initialized = true;
  36. return $this;
  37. }
  38. public function &getValue()
  39. {
  40. return $this->value;
  41. }
  42. /** @return static */
  43. public function setStatic(bool $state = true): self
  44. {
  45. $this->static = $state;
  46. return $this;
  47. }
  48. public function isStatic(): bool
  49. {
  50. return $this->static;
  51. }
  52. /** @return static */
  53. public function setType(?string $type): self
  54. {
  55. if ($type && $type[0] === '?') {
  56. $type = substr($type, 1);
  57. $this->nullable = true;
  58. }
  59. $this->type = $type;
  60. return $this;
  61. }
  62. public function getType(): ?string
  63. {
  64. return $this->type;
  65. }
  66. /** @return static */
  67. public function setNullable(bool $state = true): self
  68. {
  69. $this->nullable = $state;
  70. return $this;
  71. }
  72. public function isNullable(): bool
  73. {
  74. return $this->nullable;
  75. }
  76. /** @return static */
  77. public function setInitialized(bool $state = true): self
  78. {
  79. $this->initialized = $state;
  80. return $this;
  81. }
  82. public function isInitialized(): bool
  83. {
  84. return $this->initialized || $this->value !== null;
  85. }
  86. }