ShopConfig.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <?php
  2. namespace app\common\modules\shop;
  3. use app\frontend\modules\order\dispatch\ExpressOrderDispatchTypeMenu;
  4. class ShopConfig
  5. {
  6. /**
  7. * @var self
  8. */
  9. static $current;
  10. protected $items;
  11. /**
  12. * constructor.
  13. */
  14. public function __construct()
  15. {
  16. self::$current = $this;
  17. }
  18. static public function current()
  19. {
  20. if (!isset(self::$current)) {
  21. return new static();
  22. }
  23. return self::$current;
  24. }
  25. protected function _getItems()
  26. {
  27. $result = [
  28. 'plugin' => [
  29. [
  30. 'id' => 31,
  31. 'name' => 'cashier'
  32. ],
  33. [
  34. 'id' => 32,
  35. 'name' => 'store'
  36. ],
  37. [
  38. 'id' => 33,
  39. 'name' => 'hotel'
  40. ],
  41. [
  42. 'id' => 36,
  43. 'name' => 'hotel-cashier'
  44. ],
  45. [
  46. 'id' => 51,
  47. 'name' => 'provider-platform'
  48. ],
  49. [
  50. 'id' => 53,
  51. 'name' => 'tripartite-provider'
  52. ],
  53. [
  54. 'id' => 92,
  55. 'name' => 'supplier'
  56. ],
  57. [
  58. 'id' => 41,
  59. 'name' => 'net-car'
  60. ],
  61. [
  62. 'id' => 44,
  63. 'name' => 'jd-supply'
  64. ],
  65. [
  66. 'id' => 57,
  67. 'name' => 'product-market'
  68. ],
  69. [
  70. 'id' => 58,
  71. 'name' => 'market-sub'
  72. ],
  73. [
  74. 'id' => 60,
  75. 'name' => 'son-provider-platform'
  76. ],
  77. [
  78. 'id' => 61,
  79. 'name' => 'ys-system'
  80. ],
  81. [
  82. 'id' => 107,
  83. 'name' => 'blind-box'
  84. ],
  85. [
  86. 'id' => 71,
  87. 'name' => 'aggregation-cps'
  88. ],
  89. [
  90. 'id' => 113,
  91. 'name' => 'store-projects'
  92. ],
  93. [
  94. 'id' => 120,
  95. 'name' => 'yz-supply'
  96. ],
  97. [
  98. 'id' => 144,
  99. 'name' => 'coupon-store'
  100. ],
  101. ],
  102. 'observer' => [
  103. 'goods' => [
  104. 'sale' => [
  105. 'class' => 'app\backend\modules\goods\models\Sale',
  106. 'function_validator' => 'relationValidator',
  107. 'function_save' => 'relationSave'
  108. ],
  109. 'notice' => [
  110. 'class' => 'app\backend\modules\goods\models\Notice',
  111. 'function_validator' => 'relationValidator',
  112. 'function_save' => 'relationSave'
  113. ],
  114. 'share' => [
  115. 'class' => 'app\backend\modules\goods\models\Share',
  116. 'function_validator' => 'relationValidator',
  117. 'function_save' => 'relationSave'
  118. ],
  119. 'privilege' => [
  120. 'class' => 'app\backend\modules\goods\models\Privilege',
  121. 'function_validator' => 'relationValidator',
  122. 'function_save' => 'relationSave'
  123. ],
  124. 'discount' => [
  125. 'class' => 'app\backend\modules\goods\models\Discount',
  126. 'function_validator' => 'relationValidator',
  127. 'function_save' => 'relationSave'
  128. ],
  129. 'dispatch' => [
  130. 'class' => 'app\backend\modules\goods\models\GoodsDispatch',
  131. 'function_validator' => 'relationValidator',
  132. 'function_save' => 'relationSave'
  133. ],
  134. 'coupon' => [
  135. 'class' => 'app\backend\modules\goods\models\Coupon',
  136. 'function_validator' => 'relationValidator',
  137. 'function_save' => 'relationSave'
  138. ],
  139. 'div_from' => [
  140. 'class' => 'app\backend\modules\goods\models\DivFrom',
  141. 'function_validator' => 'relationValidator',
  142. 'function_save' => 'relationSave'
  143. ],
  144. 'filtering' => [
  145. 'class' => 'app\backend\modules\goods\models\GoodsFiltering',
  146. 'function_validator' => 'relationValidator',
  147. 'function_save' => 'relationSave'
  148. ],
  149. 'limitbuy' => [
  150. 'class' => 'app\backend\modules\goods\models\LimitBuy',
  151. 'function_validator' => 'relationValidator',
  152. 'function_save' => 'relationSave'
  153. ],
  154. 'advertising' => [
  155. 'class' => 'app\backend\modules\goods\models\Advertising',
  156. 'function_validator' => 'relationValidator',
  157. 'function_save' => 'relationSave'
  158. ],
  159. 'invite_page' => [
  160. 'class' => 'app\backend\modules\goods\models\InvitePage',
  161. 'function_validator' => 'relationValidator',
  162. 'function_save' => 'relationSave'
  163. ],
  164. 'service' => [
  165. 'class' => 'app\backend\modules\goods\models\GoodsService',
  166. 'function_validator' => 'relationValidator',
  167. 'function_save' => 'relationSave'
  168. ],
  169. 'video' => [
  170. 'class' => 'app\backend\modules\goods\models\GoodsVideo',
  171. 'function_validator' => 'relationValidator',
  172. 'function_save' => 'relationSave'
  173. ],
  174. 'spec_info' => [
  175. 'class' => 'app\backend\modules\goods\models\GoodsSpecInfo',
  176. 'function_validator' => 'relationValidator',
  177. 'function_save' => 'relationSave'
  178. ],
  179. 'trade_set' => [
  180. 'class' => 'app\backend\modules\goods\models\GoodsTradeSet',
  181. 'function_validator' => 'relationValidator',
  182. 'function_save' => 'relationSave'
  183. ],
  184. ],
  185. 'order' => [
  186. //订单操作记录
  187. 'order_operation_log' => [
  188. 'class' => 'app\backend\modules\order\models\OrderOperationLog',
  189. 'function_save' => 'insertOperationLog'
  190. ]
  191. ]
  192. ],
  193. 'goods' => [
  194. 'models' => [
  195. 'home_page' => \app\common\models\Goods::class,
  196. 'goods_info' => \app\common\models\Goods::class,
  197. 'goods_list' => \app\common\models\Goods::class,
  198. 'footprint' => \app\common\models\Goods::class,
  199. 'collection_page' => \app\common\models\Goods::class,
  200. 'commodity_classification' => \app\common\models\Goods::class,
  201. ],
  202. 'GoodsMemberLevelDiscountCalculator' => [
  203. 'goods' => \app\common\modules\discount\GoodsMemberLevelDiscountCalculator::class,
  204. 'shop' => \app\common\modules\discount\ShopGoodsMemberLevelDiscountCalculator::class
  205. ],
  206. ],
  207. 'shop-foundation' => [
  208. 'goods' => [
  209. 'dealPrice' => [
  210. [
  211. 'key' => 'goodsDealPrice',
  212. 'class' => function (\app\common\models\Goods $goods, $param = []) {
  213. return new \app\common\modules\goods\dealPrice\GoodsDealPrice($goods);
  214. },
  215. ], [
  216. 'key' => 'marketDealPrice',
  217. 'class' => function (\app\common\models\Goods $goods, $param = []) {
  218. return new \app\common\modules\goods\dealPrice\MarketDealPrice($goods);
  219. },
  220. ]
  221. ],
  222. //标准商城默认都会显示下面这几种类型的商品
  223. 'plugin' => [0],
  224. //下单不会扣除库存的订单类型
  225. //128 = 圈仓插件
  226. //56 = 云仓插件
  227. 'no-deduct-stock' => [56,128],
  228. ],
  229. //订单列表类型区分
  230. 'order-list' => [
  231. 'type' => [
  232. [
  233. 'priority' => 0,
  234. 'view' => \app\backend\modules\order\services\type\ShopOrderView::class,
  235. 'class' => function (\app\common\models\Order $order) {
  236. return new \app\backend\modules\order\services\type\ShopOrder($order);
  237. },
  238. ],
  239. ],
  240. 'top-row'=> [],
  241. ],
  242. 'member-cart' => [
  243. 'validate' => [], //下单插件验证商品
  244. 'with' => [],
  245. 'models' => [
  246. 'shop' => \app\frontend\models\MemberCart::class,
  247. ],
  248. ],
  249. 'refund' => [
  250. 'order-type' => [], //申请售后订单类型
  251. ],
  252. 'model' => [
  253. 'PreOrder' => []
  254. ],
  255. 'model-expansions' => [\app\frontend\models\Goods::class => [
  256. \Yunshop\Love\Frontend\Models\Expansions\GoodsExpansions::class,
  257. \Yunshop\AreaDividend\models\expansions\GoodsExpansions::class,
  258. \Yunshop\Supplier\common\models\expansions\GoodsExpansions::class
  259. ]],
  260. 'order' => ['member_order_operations' => [//todo 配置已移至 app/common/modules/shop/OrderFrontendButtonConfig.php
  261. 'waitPay' => [
  262. \app\frontend\modules\order\operations\member\Pay::class,
  263. \app\frontend\modules\order\operations\member\Close::class,
  264. ],
  265. 'waitSend' => [
  266. \app\frontend\modules\order\operations\member\ApplyRefund::class,
  267. \app\frontend\modules\order\operations\member\ContactCustomerService::class,
  268. \app\frontend\modules\order\operations\member\Refunding::class,
  269. \app\frontend\modules\order\operations\member\Refunded::class,
  270. \app\frontend\modules\order\operations\member\Coupon::class, //分享优惠卷
  271. \app\frontend\modules\order\operations\member\ExpeditingDelivery::class, //催发货
  272. ],
  273. 'waitReceive' => [
  274. \app\frontend\modules\order\operations\member\ExpressInfo::class,
  275. \app\frontend\modules\order\operations\member\Receive::class,
  276. \app\frontend\modules\order\operations\member\ApplyRefund::class,
  277. \app\frontend\modules\order\operations\member\ContactCustomerService::class,
  278. \app\frontend\modules\order\operations\member\Refunding::class,
  279. \app\frontend\modules\order\operations\member\Refunded::class,
  280. \app\frontend\modules\order\operations\member\Coupon::class, //分享优惠卷
  281. ],
  282. 'complete' => [
  283. \app\frontend\modules\order\operations\member\ExpressInfo::class,
  284. \app\frontend\modules\order\operations\member\Delete::class,
  285. \app\frontend\modules\order\operations\member\ApplyRefund::class,
  286. \app\frontend\modules\order\operations\member\ContactCustomerService::class,
  287. \app\frontend\modules\order\operations\member\Refunding::class,
  288. \app\frontend\modules\order\operations\member\Refunded::class,
  289. \app\frontend\modules\order\operations\member\CheckInvoice::class,
  290. \app\frontend\modules\order\operations\member\Coupon::class, //分享优惠卷
  291. \app\frontend\modules\order\operations\member\ViewEquity::class, //查看卡券
  292. ],
  293. 'close' => [
  294. \app\frontend\modules\order\operations\member\ExpressInfo::class,
  295. \app\frontend\modules\order\operations\member\Delete::class,
  296. \app\frontend\modules\order\operations\member\Refunded::class,
  297. ],
  298. ], 'status' => [
  299. 0 => 'waitPay',
  300. 1 => 'waitSend',
  301. 2 => 'waitReceive',
  302. 3 => 'complete',
  303. -1 => 'close',
  304. ],
  305. ],
  306. 'order-dispatch-save' => [
  307. 'dispatch' => \app\frontend\modules\order\dispatch\order\ExpressOrderDispatchType::class
  308. ],
  309. 'order-dispatch-menu' => [
  310. 'shop' => [ //标准商城配送方式
  311. 'dispatch' => ExpressOrderDispatchTypeMenu::class
  312. ],
  313. ],
  314. 'order-fee' => [],
  315. 'order-service-fee' => [],
  316. 'order-tax-fee' => [],
  317. 'goods-tax-fee' => [],
  318. 'status' => [
  319. [
  320. 'key' => 'remittance',
  321. 'class' => \app\common\modules\payType\remittance\models\status\RemittanceStatus::class,
  322. ],
  323. [
  324. 'key' => 'remittanceAudit',
  325. 'class' => \app\common\modules\payType\remittance\models\status\RemittanceAuditStatus::class,
  326. ],
  327. ],
  328. 'order-freight' => [
  329. [
  330. 'weight' => 1000,
  331. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder, $weight) {
  332. return new \app\frontend\modules\dispatch\freight\ShopFreight($preOrder, $weight);
  333. },
  334. ],
  335. // [
  336. // 'weight' => 1000,
  337. // 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder, $weight) {
  338. // return new \app\frontend\modules\dispatch\freight\TemplateFreight($preOrder, $weight);
  339. // },
  340. // ], [
  341. // 'weight' => 1010,
  342. // 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder, $weight) {
  343. // return new \app\frontend\modules\dispatch\freight\UnifyFreight($preOrder, $weight);
  344. // },
  345. // ],
  346. ],
  347. 'order-freight-discount' => [
  348. [
  349. 'priority' => 0, //优惠项权重
  350. 'type' => 'enoughReduce',//分组
  351. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  352. return new \app\frontend\modules\dispatch\discount\EnoughReduce($preOrder);
  353. }
  354. ],
  355. [
  356. 'priority' => 0,
  357. 'type' => 'levelFreeFreight',
  358. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  359. return new \app\frontend\modules\dispatch\discount\LevelFreeFreight($preOrder);
  360. }
  361. ],
  362. ],
  363. 'goods-discount' => [
  364. [
  365. 'weight' => 2000,
  366. 'class' => function (\app\frontend\modules\orderGoods\models\PreOrderGoods $preOrderGoods) {
  367. return new \app\frontend\modules\orderGoods\discount\MemberLevel($preOrderGoods);
  368. },
  369. ],
  370. [
  371. 'weight' => 2010,
  372. 'class' => function (\app\frontend\modules\orderGoods\models\PreOrderGoods $preOrderGoods) {
  373. return new \app\frontend\modules\orderGoods\discount\SingleEnoughReduce($preOrderGoods);
  374. },
  375. ],
  376. [
  377. 'weight' => 2010,
  378. 'class' => function (\app\frontend\modules\orderGoods\models\PreOrderGoods $preOrderGoods) {
  379. return new \app\frontend\modules\orderGoods\discount\FullPiece($preOrderGoods);
  380. },
  381. ], [
  382. 'weight' => 2020,
  383. 'class' => function (\app\frontend\modules\orderGoods\models\PreOrderGoods $preOrderGoods) {
  384. return new \app\frontend\modules\orderGoods\discount\EnoughReduce($preOrderGoods);
  385. },
  386. ], [
  387. 'weight' => 2100,
  388. 'class' => function (\app\frontend\modules\orderGoods\models\PreOrderGoods $preOrderGoods) {
  389. return new \app\frontend\modules\orderGoods\discount\Coupon($preOrderGoods);
  390. },
  391. ],
  392. ],
  393. 'coin-exchange' => [
  394. ],
  395. 'coupon' => [
  396. 'OrderCoupon' => [
  397. 'scope' => [
  398. [
  399. 'key' => \app\common\models\Coupon::COUPON_GOODS_USE,
  400. 'class' => function ($coupon) {
  401. return new \app\frontend\modules\coupon\services\models\UseScope\GoodsScope($coupon);
  402. },
  403. ],
  404. [
  405. 'key' => \app\common\models\Coupon::COUPON_CATEGORY_USE,
  406. 'class' => function ($coupon) {
  407. return new \app\frontend\modules\coupon\services\models\UseScope\CategoryScope($coupon);
  408. },
  409. ],
  410. [
  411. 'key' => \app\common\models\Coupon::COUPON_SHOP_USE,
  412. 'class' => function ($coupon) {
  413. return new \app\frontend\modules\coupon\services\models\UseScope\ShopScope($coupon);
  414. },
  415. ],
  416. [
  417. 'key' => \app\common\models\Coupon::COUPON_GOODS_AND_STORE_USE,
  418. 'class' => function ($coupon) {
  419. return new \app\frontend\modules\coupon\services\models\UseScope\GoodsAndStoreScope($coupon);
  420. },
  421. ],
  422. ]
  423. ]
  424. ], 'discount' => [
  425. 'GoodsMemberLevelDiscountCalculator' => [
  426. [
  427. 'priority' => '1000',
  428. 'key' => 'goods',
  429. 'class' => function ($goods, $member) {
  430. $class = \app\common\modules\shop\ShopConfig::current()->get('goods.GoodsMemberLevelDiscountCalculator.goods');
  431. return new $class($goods, $member);
  432. }
  433. ],
  434. [
  435. 'priority' => '2000',
  436. 'key' => 'shop',
  437. 'class' => function ($goods, $member) {
  438. $class = \app\common\modules\shop\ShopConfig::current()->get('goods.GoodsMemberLevelDiscountCalculator.shop');
  439. return new $class($goods, $member);
  440. }
  441. ],
  442. ]
  443. ], 'goods-option' => [
  444. 'dealPrice' => [
  445. [
  446. 'key' => 'goodsDealPrice',
  447. 'class' => function (\app\common\models\GoodsOption $goodsOption, $param = []) {
  448. return new \app\common\modules\goodsOption\dealPrice\GoodsDealPrice($goodsOption);
  449. },
  450. ], [
  451. 'key' => 'marketDealPrice',
  452. 'class' => function (\app\common\models\GoodsOption $goodsOption, $param = []) {
  453. return new \app\common\modules\goodsOption\dealPrice\MarketDealPrice($goodsOption);
  454. },
  455. ]
  456. ]
  457. ], 'order-discount' => [
  458. [
  459. 'key' => 'memberLevel',
  460. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  461. return new \app\frontend\modules\order\discount\MemberLevel($preOrder);
  462. },
  463. ],
  464. [
  465. 'key' => 'singleEnoughReduce',
  466. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  467. return new \app\frontend\modules\order\discount\SingleEnoughReduce($preOrder);
  468. },
  469. ], [
  470. 'key' => 'fullPiece',
  471. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  472. return new \app\frontend\modules\order\discount\FullPiece($preOrder);
  473. },
  474. ],[
  475. 'key' => 'enoughReduce',
  476. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  477. return new \app\frontend\modules\order\discount\EnoughReduce($preOrder);
  478. },
  479. ],
  480. [
  481. 'key' => 'couponDiscount',
  482. 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  483. return new \app\frontend\modules\order\discount\CouponDiscount($preOrder);
  484. },
  485. ],
  486. // [
  487. // 'key' => 'singleEnoughReduce',
  488. // 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  489. // return new \app\frontend\modules\order\discount\SingleEnoughReduce($preOrder);
  490. // },
  491. // ], [
  492. // 'key' => 'enoughReduce',
  493. // 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  494. // return new \app\frontend\modules\order\discount\EnoughReduce($preOrder);
  495. // },
  496. // ],
  497. // [
  498. // 'key' => 'couponDiscount',
  499. // 'class' => function (\app\frontend\modules\order\models\PreOrder $preOrder) {
  500. // return new \app\frontend\modules\order\discount\CouponDiscount($preOrder);
  501. // },
  502. // ]
  503. ], 'order-price-nodes' => [
  504. [
  505. 'class' => function (\app\frontend\modules\order\models\PreOrder $order) {
  506. return new \app\frontend\modules\order\OrderGoodsPriceNode($order, 1000);
  507. },
  508. ],
  509. [
  510. 'class' => function (\app\frontend\modules\order\models\PreOrder $order) {
  511. return new \app\frontend\modules\order\OrderDispatchPriceNode($order, 3000);
  512. },
  513. ],
  514. [
  515. 'class' => function (\app\frontend\modules\order\models\PreOrder $order) {
  516. return new \app\frontend\modules\order\OrderTaxFeePriceNode($order, 9200);
  517. },
  518. ],
  519. [
  520. 'class' => function (\app\frontend\modules\order\models\PreOrder $order) {
  521. return new \app\frontend\modules\order\OrderFeeNode($order, 9998);
  522. },
  523. ],
  524. [
  525. 'class' => function (\app\frontend\modules\order\models\PreOrder $order) {
  526. return new \app\frontend\modules\order\OrderServiceFeeNode($order, 9999);
  527. },
  528. ]
  529. ], 'deduction' => [
  530. 'enable' => true
  531. ],
  532. 'send_back_way' => [
  533. 'self_send' => '\app\frontend\modules\refund\services\back_way_operation\SelfSend',
  534. ]
  535. ],
  536. 'queue' => [
  537. ['key' => 'default',
  538. 'total' => 3,
  539. 'name' => '默认',
  540. 'option' => [],
  541. 'is_serial' => false
  542. ], ['key' => 'message',
  543. 'total' => 3,
  544. 'name' => '消息',
  545. 'option' => [],
  546. 'is_serial' => false
  547. ], ['key' => 'order',
  548. 'total' => 3,
  549. 'name' => '订单',
  550. 'option' => [],
  551. 'is_serial' => true
  552. ], [
  553. 'key' => 'statistics',
  554. 'total' => 3,
  555. 'name' => '统计',
  556. 'option' => [],
  557. 'is_serial' => false
  558. ], [
  559. 'key' => 'limit',
  560. 'total' => 3,
  561. 'name' => '限定',
  562. 'option' => [],
  563. 'is_serial' => true
  564. ],
  565. ],
  566. 'password' => [
  567. 'balance' => [
  568. 'code' => 'balance',
  569. 'name' => '余额设置',
  570. 'condition' => [
  571. [
  572. 'key' => 'pay',
  573. 'name' => '余额支付'
  574. ],
  575. [
  576. 'key' => 'transfer',
  577. 'name' => '余额转让'
  578. ],
  579. [
  580. 'key' => 'withdraw',
  581. 'name' => '余额提现'
  582. ]
  583. ]
  584. ],
  585. 'point' => [
  586. 'code' => 'point',
  587. 'name' => '积分设置',
  588. 'condition' => [
  589. [
  590. 'key' => 'transfer',
  591. 'name' => '积分转让'
  592. ]
  593. ]
  594. ],
  595. ],
  596. 'data-clear' => [//商城设置-数据清理
  597. ]
  598. ];
  599. $plugins = app('plugins')->getEnabledPlugins('*');
  600. foreach ($plugins as $plugin) {
  601. foreach ($plugin->app()->getShopConfigItems() as $key => $item) {
  602. array_set($result, $key, $item);
  603. }
  604. }
  605. return $result;
  606. }
  607. protected function getItems()
  608. {
  609. if (!isset($this->items)) {
  610. $this->items = $this->_getItems();
  611. }
  612. return $this->items;
  613. }
  614. public function getItem($key)
  615. {
  616. return array_get($this->getItems(), $key);
  617. }
  618. public function clear()
  619. {
  620. $this->items = null;
  621. }
  622. public function get($key = null)
  623. {
  624. if (empty($key)) {
  625. return $this->getItems();
  626. }
  627. return $this->getItem($key);
  628. }
  629. public function set($key, $value = null)
  630. {
  631. $items = $this->getItems();
  632. if (is_array($key)) {
  633. foreach ($key as $k => $v) {
  634. array_set($items, $k, $v);
  635. }
  636. } else {
  637. array_set($items, $key, $value);
  638. }
  639. $this->items = $items;
  640. }
  641. public function push($key, $value)
  642. {
  643. $all = $this->getItems();
  644. $array = $this->getItem($key) ?: [];
  645. $array[] = $value;
  646. array_set($all, $key, $array);
  647. $this->items = $all;
  648. }
  649. public function unshift($key, $value)
  650. {
  651. $all = $this->getItems();
  652. $array = $this->getItem($key) ?: [];
  653. array_unshift($array, $value);
  654. array_set($all, $key, $array);
  655. $this->items = $all;
  656. }
  657. }