Tag.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace crmeb\utils;
  14. use think\cache\TagSet;
  15. use think\Container;
  16. /**
  17. * Class Tag
  18. * @author 等风来
  19. * @email 136327134@qq.com
  20. * @date 2022/11/10
  21. * @package crmeb\utils
  22. * @mixin TagSet
  23. */
  24. class Tag
  25. {
  26. protected $tag;
  27. /**
  28. * @var string
  29. */
  30. protected $tagStr;
  31. /**
  32. * Tag constructor.
  33. * @param TagSet $set
  34. * @param string $tagStr
  35. */
  36. public function __construct(TagSet $set, string $tagStr)
  37. {
  38. $this->tag = $set;
  39. $this->tagStr = $tagStr;
  40. }
  41. /**
  42. * @param string $name
  43. * @param $value
  44. * @param null $expire
  45. * @return mixed
  46. * @author 等风来
  47. * @email 136327134@qq.com
  48. * @date 2022/11/10
  49. */
  50. public function remember(string $name, $value, $expire = null)
  51. {
  52. //不开启数据缓存直接返回
  53. if (!app()->config->get('cache.is_data')) {
  54. if ($value instanceof \Closure) {
  55. $value = Container::getInstance()->invokeFunction($value);
  56. }
  57. return $value;
  58. }
  59. $name = $this->tagStr . $name;
  60. return $this->tag->remember($name, $value, $expire);
  61. }
  62. /**
  63. * @param $name
  64. * @param $arguments
  65. * @author 等风来
  66. * @email 136327134@qq.com
  67. * @date 2022/11/10
  68. */
  69. public function __call($name, $arguments)
  70. {
  71. $this->tag->{$name}(...$arguments);
  72. }
  73. }