OptionTrait.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\traits;
  12. /**
  13. * 设置参数
  14. * Trait OptionTrait
  15. * @package crmeb\traits
  16. */
  17. trait OptionTrait
  18. {
  19. protected $item = [];
  20. /**
  21. * @param string $key
  22. * @param $default
  23. * @return mixed
  24. */
  25. public function getItem(string $key, $default = null)
  26. {
  27. return $this->item[$key] ?? $default;
  28. }
  29. /**
  30. * @param string $key
  31. * @param $value
  32. * @return $this
  33. */
  34. public function setItem(string $key, $value)
  35. {
  36. $this->item[$key] = $value;
  37. return $this;
  38. }
  39. /**
  40. * 重置
  41. */
  42. public function reset()
  43. {
  44. $this->item = [];
  45. }
  46. }