Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active December 8, 2020 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/3c16028a50e1377328775c3e0a2cf51d to your computer and use it in GitHub Desktop.
Save kurozumi/3c16028a50e1377328775c3e0a2cf51d to your computer and use it in GitHub Desktop.
会員ランクを取得するコンテキスト
<?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