Option.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class Option
  3. {
  4. private $displayName;
  5. private $value;
  6. /**
  7. * @param $displayName
  8. * @param $value
  9. */
  10. public function __construct($displayName = null, $value = null)
  11. {
  12. $this->displayName = $displayName;
  13. $this->value = $value;
  14. }
  15. /**
  16. * @throws Exception
  17. */
  18. public function toElement($dom, $parent, $attributeId)
  19. {
  20. if (empty($this->displayName) && $this->displayName != '0') {
  21. throw new \Exception("id=[" . $attributeId . "] Option格式错误!Option名称displayName不能为空!");
  22. }
  23. if (empty($this->value) && $this->value != '0') {
  24. throw new \Exception("id=[" . $attributeId . "] Option格式错误!Option的值value不能为空!");
  25. }
  26. $option = $dom->createElement("option");
  27. $option->setAttribute("displayName", $this->displayName);
  28. $option->setAttribute("value", $this->value);
  29. $parent->appendChild($option);
  30. }
  31. /**
  32. * @return mixed
  33. */
  34. public function getDisplayName()
  35. {
  36. return $this->displayName;
  37. }
  38. /**
  39. * @param mixed $displayName
  40. */
  41. public function setDisplayName($displayName)
  42. {
  43. $this->displayName = $displayName;
  44. }
  45. /**
  46. * @return mixed
  47. */
  48. public function getValue()
  49. {
  50. return $this->value;
  51. }
  52. /**
  53. * @param mixed $value
  54. */
  55. public function setValue($value)
  56. {
  57. $this->value = $value;
  58. }
  59. }