Select.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\form\components;
  12. use crmeb\form\BaseComponent;
  13. use crmeb\form\BuildInterface;
  14. /**
  15. * 多选组件
  16. * Class Select
  17. * @package crmeb\form\components
  18. * @method placeholder(string $placeholder)
  19. * @method options(array $options = [])
  20. * @method info(string $info)
  21. */
  22. class Select extends BaseComponent implements BuildInterface
  23. {
  24. /**
  25. * 组件名
  26. */
  27. const NAME = 'select';
  28. /**
  29. * 规则
  30. * @var string[]
  31. */
  32. protected $rule = [
  33. 'title' => '',
  34. 'value' => '',
  35. 'type' => '',
  36. 'field' => '',
  37. 'info' => '',
  38. 'placeholder' => '',
  39. 'options' => [],
  40. ];
  41. /**
  42. * Radio constructor.
  43. * @param string $title
  44. * @param string $field
  45. * @param null $value
  46. */
  47. public function __construct(string $field, string $title, $value = null)
  48. {
  49. $this->rule['title'] = $title;
  50. $this->rule['field'] = $field;
  51. $this->rule['value'] = !is_null($value) ? $value : null;
  52. }
  53. /**
  54. * 转换数据
  55. * @return array|string[]
  56. */
  57. public function toArray(): array
  58. {
  59. $this->rule['name'] = self::NAME;
  60. $this->before();
  61. return $this->rule;
  62. }
  63. /**
  64. * @param $name
  65. * @param $arguments
  66. * @return $this
  67. */
  68. public function __call($name, $arguments)
  69. {
  70. if (in_array($name, ['title', 'field'])) {
  71. return $this;
  72. }
  73. $keys = array_keys($this->rule);
  74. if (in_array($name, $keys)) {
  75. $this->rule[$name] = $arguments[0] ?? null;
  76. }
  77. return $this;
  78. }
  79. }