Skip to content

Commit

Permalink
CustomerTypeContextに変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kurozumi committed Dec 7, 2020
1 parent 7f5edbf commit 50b31db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions Controller/CustomerTypeController.php
Expand Up @@ -15,21 +15,21 @@

use Eccube\Controller\AbstractController;
use Eccube\Entity\Customer;
use Plugin\CustomerType\Service\Customer\CustomerContext;
use Plugin\CustomerType\Service\Customer\CustomerTypeContext;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;

class CustomerTypeController extends AbstractController
{
/**
* @var CustomerContext
* @var CustomerTypeContext
*/
private $customerContext;
private $customerTypeContext;

public function __construct(CustomerContext $customerContext)
public function __construct(CustomerTypeContext $customerTypeContext)
{
$this->customerContext = $customerContext;
$this->customerTypeContext = $customerTypeContext;
}

/**
Expand All @@ -43,7 +43,7 @@ public function index()
throw new AccessDeniedHttpException();
}

$customerType = $this->customerContext->handle($this->getUser());
$customerType = $this->customerTypeContext->getCustomerType($this->getUser());
$message = sprintf("あなたは%sです。", $customerType->getName());

return new Response($message);
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/CustomerTypeCompilerPass.php
Expand Up @@ -13,7 +13,7 @@
namespace Plugin\CustomerType\DependencyInjection;


use Plugin\CustomerType\Service\Customer\CustomerContext;
use Plugin\CustomerType\Service\Customer\CustomerTypeContext;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -24,7 +24,7 @@ class CustomerTypeCompilerPass implements CompilerPassInterface

public function process(ContainerBuilder $container)
{
$context = $container->findDefinition(CustomerContext::class);
$context = $container->findDefinition(CustomerTypeContext::class);

foreach($container->findTaggedServiceIds(self::CUSTOMR_TYPE_TAG) as $id => $tags) {
$context->addMethodCall('addType', [new Reference($id)]);
Expand Down
Expand Up @@ -16,7 +16,7 @@
use Eccube\Entity\Customer;
use Plugin\CustomerType\Entity\CustomerType;

class CustomerContext
class CustomerTypeContext
{
/** @var CustomerTypeInterface[] */
private $types = [];
Expand All @@ -30,7 +30,7 @@ public function addType(CustomerTypeInterface $type)
* @param Customer $customer
* @return CustomerType
*/
public function handle(Customer $customer): CustomerType
public function getCustomerType(Customer $customer): CustomerType
{
foreach ($this->types as $type) {
if ($type->verify($customer)) {
Expand Down

0 comments on commit 50b31db

Please sign in to comment.