| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace Longyi\FreeGift\Services\Actions;
- use Longyi\FreeGift\Config\Gift;
- /**
- * action_type → 算法 的分发器。
- */
- class GiftActionPool
- {
- /**
- * @var array<string, AbstractGiftAction>
- */
- protected array $actions;
- public function __construct(
- SameProductAction $sameProduct,
- ProductAction $product,
- EachNAction $eachN,
- CartAction $cart,
- SpentAction $spent
- ) {
- $this->actions = [
- Gift::ACTION_SAME_PRODUCT => $sameProduct,
- Gift::ACTION_WITH_PRODUCTS => $product,
- Gift::ACTION_EACH_N => $eachN,
- Gift::ACTION_WHOLE_CART => $cart,
- Gift::ACTION_SPENT => $spent,
- ];
- }
- /**
- * 取 action_type 对应的算法。
- */
- public function get($actionType): ?AbstractGiftAction
- {
- return $this->actions[$actionType] ?? null;
- }
- }
|