Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\PropertyInfo;
  11. /**
  12. * The write mutator defines how a property can be written.
  13. *
  14. * @author Joel Wurtz <jwurtz@jolicode.com>
  15. *
  16. * @internal
  17. */
  18. final class PropertyWriteInfo
  19. {
  20. public const TYPE_NONE = 'none';
  21. public const TYPE_METHOD = 'method';
  22. public const TYPE_PROPERTY = 'property';
  23. public const TYPE_ADDER_AND_REMOVER = 'adder_and_remover';
  24. public const TYPE_CONSTRUCTOR = 'constructor';
  25. public const VISIBILITY_PUBLIC = 'public';
  26. public const VISIBILITY_PROTECTED = 'protected';
  27. public const VISIBILITY_PRIVATE = 'private';
  28. private $type;
  29. private $name;
  30. private $visibility;
  31. private $static;
  32. private $adderInfo;
  33. private $removerInfo;
  34. private $errors = [];
  35. public function __construct(string $type = self::TYPE_NONE, ?string $name = null, ?string $visibility = null, ?bool $static = null)
  36. {
  37. $this->type = $type;
  38. $this->name = $name;
  39. $this->visibility = $visibility;
  40. $this->static = $static;
  41. }
  42. public function getType(): string
  43. {
  44. return $this->type;
  45. }
  46. public function getName(): string
  47. {
  48. if (null === $this->name) {
  49. throw new \LogicException("Calling getName() when having a mutator of type {$this->type} is not tolerated.");
  50. }
  51. return $this->name;
  52. }
  53. public function setAdderInfo(self $adderInfo): void
  54. {
  55. $this->adderInfo = $adderInfo;
  56. }
  57. public function getAdderInfo(): self
  58. {
  59. if (null === $this->adderInfo) {
  60. throw new \LogicException("Calling getAdderInfo() when having a mutator of type {$this->type} is not tolerated.");
  61. }
  62. return $this->adderInfo;
  63. }
  64. public function setRemoverInfo(self $removerInfo): void
  65. {
  66. $this->removerInfo = $removerInfo;
  67. }
  68. public function getRemoverInfo(): self
  69. {
  70. if (null === $this->removerInfo) {
  71. throw new \LogicException("Calling getRemoverInfo() when having a mutator of type {$this->type} is not tolerated.");
  72. }
  73. return $this->removerInfo;
  74. }
  75. public function getVisibility(): string
  76. {
  77. if (null === $this->visibility) {
  78. throw new \LogicException("Calling getVisibility() when having a mutator of type {$this->type} is not tolerated.");
  79. }
  80. return $this->visibility;
  81. }
  82. public function isStatic(): bool
  83. {
  84. if (null === $this->static) {
  85. throw new \LogicException("Calling isStatic() when having a mutator of type {$this->type} is not tolerated.");
  86. }
  87. return $this->static;
  88. }
  89. public function setErrors(array $errors): void
  90. {
  91. $this->errors = $errors;
  92. }
  93. public function getErrors(): array
  94. {
  95. return $this->errors;
  96. }
  97. public function hasErrors(): bool
  98. {
  99. return (bool) \count($this->errors);
  100. }
  101. }