| @@ 21-51 (lines=31) @@ | ||
| 18 | /** |
|
| 19 | * カート/受注の妥当性検証を行う. |
|
| 20 | */ |
|
| 21 | abstract class ItemHolderPostValidator |
|
| 22 | { |
|
| 23 | use ValidatorTrait; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param ItemHolderInterface $itemHolder |
|
| 27 | * @param PurchaseContext $context |
|
| 28 | * |
|
| 29 | * @return ProcessResult |
|
| 30 | */ |
|
| 31 | final public function execute(ItemHolderInterface $itemHolder, PurchaseContext $context) |
|
| 32 | { |
|
| 33 | try { |
|
| 34 | $this->validate($itemHolder, $context); |
|
| 35 | ||
| 36 | return ProcessResult::success(null, static::class); |
|
| 37 | } catch (InvalidItemException $e) { |
|
| 38 | return $e->isWarning() |
|
| 39 | ? ProcessResult::warn($e->getMessage(), static::class) |
|
| 40 | : ProcessResult::error($e->getMessage(), static::class); |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * @param ItemHolderInterface $itemHolder |
|
| 46 | * @param PurchaseContext $context |
|
| 47 | * |
|
| 48 | * @throws InvalidItemException |
|
| 49 | */ |
|
| 50 | abstract protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $context); |
|
| 51 | } |
|
| 52 | ||
| @@ 21-60 (lines=40) @@ | ||
| 18 | /** |
|
| 19 | * カート/受注の妥当性検証を行う. |
|
| 20 | */ |
|
| 21 | abstract class ItemHolderValidator |
|
| 22 | { |
|
| 23 | use ValidatorTrait; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param ItemHolderInterface $itemHolder |
|
| 27 | * @param PurchaseContext $context |
|
| 28 | * |
|
| 29 | * @return ProcessResult |
|
| 30 | */ |
|
| 31 | final public function execute(ItemHolderInterface $itemHolder, PurchaseContext $context) |
|
| 32 | { |
|
| 33 | try { |
|
| 34 | $this->validate($itemHolder, $context); |
|
| 35 | ||
| 36 | return ProcessResult::success(null, static::class); |
|
| 37 | } catch (InvalidItemException $e) { |
|
| 38 | return $e->isWarning() |
|
| 39 | ? ProcessResult::warn($e->getMessage(), static::class) |
|
| 40 | : ProcessResult::error($e->getMessage(), static::class); |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * @param ItemHolderInterface $itemHolder |
|
| 46 | * @param PurchaseContext $context |
|
| 47 | * |
|
| 48 | * @throws InvalidItemException |
|
| 49 | */ |
|
| 50 | abstract protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $context); |
|
| 51 | ||
| 52 | protected function handle(ItemHolderInterface $itemHolder) |
|
| 53 | { |
|
| 54 | } |
|
| 55 | ||
| 56 | public function __toString() |
|
| 57 | { |
|
| 58 | return get_class($this); |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||