CommonConfig.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/8/2
  8. * Time: 10:25
  9. */
  10. namespace app\common\modules\shop;
  11. abstract class CommonConfig
  12. {
  13. /**
  14. * @var self
  15. */
  16. public static $current;
  17. protected $items;
  18. abstract static public function current();
  19. protected function _getItems()
  20. {
  21. return [];
  22. }
  23. protected function getItems()
  24. {
  25. if (!isset($this->items)) {
  26. $this->items = $this->_getItems();
  27. }
  28. return $this->items;
  29. }
  30. public function getItem($key)
  31. {
  32. return array_get($this->getItems(), $key);
  33. }
  34. public function clear()
  35. {
  36. $this->items = null;
  37. }
  38. public function get($key = null)
  39. {
  40. if (empty($key)) {
  41. return $this->getItems();
  42. }
  43. return $this->getItem($key);
  44. }
  45. public function set($key, $value = null)
  46. {
  47. $items = $this->getItems();
  48. if (is_array($key)) {
  49. foreach ($key as $k => $v) {
  50. array_set($items, $k, $v);
  51. }
  52. } else {
  53. array_set($items, $key, $value);
  54. }
  55. $this->items = $items;
  56. }
  57. public function push($key, $value)
  58. {
  59. $all = $this->getItems();
  60. $array = $this->getItem($key) ?: [];
  61. $array[] = $value;
  62. array_set($all, $key, $array);
  63. $this->items = $all;
  64. }
  65. }