Host.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace IPv4Bundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use JMS\Serializer\Annotation as JMS;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use IPv4Bundle\Traits\DHCPOptionTrait;
  7. /**
  8. * @ORM\Entity
  9. * @ORM\HasLifecycleCallbacks
  10. * @UniqueEntity("mac")
  11. */
  12. class Host
  13. {
  14. use DHCPOptionTrait;
  15. const STATE_ACTIVE = 'active';
  16. const STATE_SUSPENDED = 'suspended';
  17. /**
  18. * @var bigint $id
  19. *
  20. * @ORM\Column(name="id", type="bigint", nullable=false)
  21. * @ORM\Id
  22. * @ORM\GeneratedValue(strategy="IDENTITY")
  23. */
  24. protected $id;
  25. /**
  26. * @var string $name
  27. *
  28. * @ORM\Column(type="string", length=100, unique=true)
  29. */
  30. protected $mac;
  31. /**
  32. * @var string $options
  33. *
  34. * @ORM\Column(type="text", nullable=true)
  35. */
  36. protected $options;
  37. /**
  38. * @var HostType $hostType
  39. *
  40. * @ORM\ManyToOne(targetEntity="HostType", inversedBy="hosts")
  41. * @ORM\JoinColumn(onDelete="CASCADE")
  42. *
  43. * @JMS\MaxDepth(1)
  44. */
  45. protected $hostType;
  46. /**
  47. * @var string $state
  48. *
  49. * @ORM\Column(type="string", options={"default": "active"})
  50. */
  51. protected $state = self::STATE_ACTIVE;
  52. /**
  53. * @return string
  54. */
  55. public function __toString()
  56. {
  57. return strval($this->mac);
  58. }
  59. /**
  60. * @return bigint
  61. */
  62. public function getId()
  63. {
  64. return $this->id;
  65. }
  66. /**
  67. * @param string $mac
  68. *
  69. * @return Host
  70. */
  71. public function setMac($mac)
  72. {
  73. $this->mac = $mac;
  74. return $this;
  75. }
  76. /**
  77. * @return string
  78. */
  79. public function getMac()
  80. {
  81. return $this->mac;
  82. }
  83. /**
  84. * @param text $options
  85. *
  86. * @return Host
  87. */
  88. public function setOptions($options)
  89. {
  90. $this->options = $options;
  91. return $this;
  92. }
  93. /**
  94. * @return text
  95. */
  96. public function getOptions()
  97. {
  98. return $this->options;
  99. }
  100. /**
  101. * @param HostType $hostType
  102. *
  103. * @return Host
  104. */
  105. public function setHostType(HostType $hostType)
  106. {
  107. $this->hostType = $hostType;
  108. return $this;
  109. }
  110. /**
  111. * @return HostType
  112. */
  113. public function getHostType()
  114. {
  115. return $this->hostType;
  116. }
  117. /**
  118. * @return string
  119. */
  120. public function getState()
  121. {
  122. return $this->state;
  123. }
  124. /**
  125. * @param string $state
  126. *
  127. * @return Host
  128. */
  129. public function setState($state = self::STATE_ACTIVE)
  130. {
  131. $this->state = $state;
  132. return $this;
  133. }
  134. }