Time.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Time
  17. * @package crmeb\form\components
  18. * @method Time info(string $info) 设置info
  19. * @method Time value($value) 设置value
  20. * @method Time type(string $type) 设置type
  21. * @method Time placeholder(string $placeholder) 设置placeholder
  22. */
  23. class Time extends BaseComponent implements BuildInterface
  24. {
  25. const NAME = 'time';
  26. /**
  27. * @var string[]
  28. */
  29. protected $rule = [
  30. 'title' => '',
  31. 'value' => '',
  32. 'field' => '',
  33. 'info' => '',
  34. 'placeholder' => '',
  35. 'format' => 'HH:mm:ss',
  36. 'type' => 'timerange'
  37. ];
  38. /**
  39. * Time constructor.
  40. * @param string $field
  41. * @param string $title
  42. * @param array|null $value
  43. */
  44. public function __construct(string $field, string $title, array $value = null)
  45. {
  46. $this->rule['field'] = $field;
  47. $this->rule['title'] = $title;
  48. $this->rule['value'] = empty($value) ? '' : $value;
  49. }
  50. /**
  51. * @return array|string[]
  52. */
  53. public function toArray(): array
  54. {
  55. $this->rule['name'] = self::NAME;
  56. $this->before();
  57. return $this->rule;
  58. }
  59. /**
  60. * @param $name
  61. * @param $arguments
  62. * @return $this
  63. */
  64. public function __call($name, $arguments)
  65. {
  66. if (in_array($name, ['title', 'field', 'disabled', 'copyText'])) {
  67. return $this;
  68. }
  69. $keys = array_keys($this->rule);
  70. if (in_array($name, $keys)) {
  71. $this->rule[$name] = $arguments[0] ?? null;
  72. }
  73. return $this;
  74. }
  75. }