EmitRule.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * @document http://php.form-create.com
  11. */
  12. namespace FormBuilder\Rule;
  13. trait EmitRule
  14. {
  15. /**
  16. * 组件模式下配置使用emit方式触发的事件名
  17. * @var array
  18. */
  19. protected $emit = [];
  20. /**
  21. * 自定义组件emit事件的前缀
  22. * @var
  23. */
  24. protected $emitPrefix;
  25. public function emit(array $emits)
  26. {
  27. $this->emit = array_merge($this->emit, array_map('strval', $emits));
  28. return $this;
  29. }
  30. public function appendEmit($emit)
  31. {
  32. $this->emit[] = (string)$emit;
  33. return $this;
  34. }
  35. public function emitPrefix($prefix)
  36. {
  37. $this->emitPrefix = (string)$prefix;
  38. return $prefix;
  39. }
  40. public function getEmit()
  41. {
  42. return $this->emit;
  43. }
  44. public function getEmitPrefix()
  45. {
  46. return $this->emitPrefix;
  47. }
  48. public function parseEmitRule()
  49. {
  50. $rule = [];
  51. if (count($this->emit))
  52. $rule['emit'] = $this->emit;
  53. if (!is_null($this->emitPrefix))
  54. $rule['emitPrefix'] = $this->emitPrefix;
  55. return $rule;
  56. }
  57. }