CallPropsRule.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. use FormBuilder\Exception\FormBuilderException;
  14. trait CallPropsRule
  15. {
  16. /**
  17. * 设置组件属性
  18. *
  19. * @param $name
  20. * @param $arguments
  21. * @return $this
  22. * @throws FormBuilderException
  23. */
  24. public function __call($name, $arguments)
  25. {
  26. if (isset(static::$propsRule[$name])) {
  27. if (!isset($arguments[0])) return isset($this->props[$name]) ? $this->props[$name] : null;
  28. $value = $arguments[0];
  29. if (is_array(static::$propsRule[$name])) {
  30. settype($value, static::$propsRule[$name][0]);
  31. $name = static::$propsRule[$name][1];
  32. } else if (static::$propsRule[$name]) {
  33. settype($value, static::$propsRule[$name]);
  34. }
  35. $this->props[$name] = $value;
  36. return $this;
  37. } else {
  38. throw new FormBuilderException($name . '方法不存在');
  39. }
  40. }
  41. }