*/ 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; } }