Last active
December 8, 2020 01:44
-
-
Save kurozumi/cb289a2fb2e197871be77200d1faec34 to your computer and use it in GitHub Desktop.
自動タグ付けされたクラスをCustomerTypeContextに注入するコンパイラ
This file contains hidden or 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 <[email protected]> | |
* | |
* 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\DependencyInjection; | |
use Plugin\CustomerType\Service\Customer\CustomerTypeContext; | |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\DependencyInjection\Reference; | |
class CustomerTypeCompilerPass implements CompilerPassInterface | |
{ | |
const CUSTOMR_TYPE_TAG = 'eccube.customer.type'; | |
/** | |
* eccube.customer.typeがタグ付けされた会員タイプクラスをCustomerTypeContextに追加する | |
* | |
* @param ContainerBuilder $container | |
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException | |
* @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException | |
*/ | |
public function process(ContainerBuilder $container) | |
{ | |
$context = $container->findDefinition(CustomerTypeContext::class); | |
foreach($container->findTaggedServiceIds(self::CUSTOMR_TYPE_TAG) as $id => $tags) { | |
$context->addMethodCall('addType', [new Reference($id)]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment