Last active
December 8, 2020 01:58
-
-
Save kurozumi/3c16028a50e1377328775c3e0a2cf51d to your computer and use it in GitHub Desktop.
会員ランクを取得するコンテキスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of CustomerType | |
* | |
* Copyright(c) Akira Kurozumi <info@a-zumi.net> | |
* | |
* https://a-zumi.net | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace Plugin\CustomerType\Service\Customer; | |
use Eccube\Entity\Customer; | |
use Plugin\CustomerType\Entity\CustomerType; | |
class CustomerTypeContext | |
{ | |
/** @var CustomerTypeInterface[] */ | |
private $types = []; | |
public function addType(CustomerTypeInterface $type) | |
{ | |
$this->types[] = $type; | |
} | |
/** | |
* 条件にマッチした会員タイプを取得 | |
* | |
* @param Customer $customer | |
* @return CustomerType | |
*/ | |
public function getCustomerType(Customer $customer): CustomerType | |
{ | |
foreach ($this->types as $type) { | |
if ($type->verify($customer)) { | |
return $type->getCustomerType(); | |
} | |
} | |
throw new \InvalidArgumentException(trans("会員タイプが取得できませんでした。")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment