EmitRule.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * PHP表单生成器
  4. *
  5. * @package FormBuilder
  6. * @author xaboy <xaboy2005@qq.com>
  7. * @version 2.0
  8. * @license MIT
  9. * @link https://github.com/xaboy/form-builder
  10. */
  11. namespace FormBuilder\Rule;
  12. trait EmitRule
  13. {
  14. /**
  15. * 组件模式下配置使用emit方式触发的事件名
  16. * @var array
  17. */
  18. protected $emit = [];
  19. /**
  20. * 自定义组件emit事件的前缀
  21. * @var
  22. */
  23. protected $emitPrefix;
  24. public function emit(array $emits)
  25. {
  26. $this->emit = array_merge($this->emit, array_map('strval', $emits));
  27. return $this;
  28. }
  29. public function appendEmit($emit)
  30. {
  31. $this->emit[] = (string)$emit;
  32. return $this;
  33. }
  34. public function emitPrefix($prefix)
  35. {
  36. $this->emitPrefix = (string)$prefix;
  37. return $prefix;
  38. }
  39. public function getEmit()
  40. {
  41. return $this->emit;
  42. }
  43. public function getEmitPrefix()
  44. {
  45. return $this->emitPrefix;
  46. }
  47. public function parseEmitRule()
  48. {
  49. $rule = [];
  50. if (count($this->emit))
  51. $rule['emit'] = $this->emit;
  52. if (!is_null($this->emitPrefix))
  53. $rule['emitPrefix'] = $this->emitPrefix;
  54. return $rule;
  55. }
  56. }