| @@ 20-40 (lines=21) @@ | ||
| 17 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
| 18 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
| 19 | ||
| 20 | class PaymentMethodPass implements CompilerPassInterface |
|
| 21 | { |
|
| 22 | const PAYMENT_METHOD_TAG = 'eccube.payment.method'; |
|
| 23 | ||
| 24 | public function process(ContainerBuilder $container) |
|
| 25 | { |
|
| 26 | $ids = $container->findTaggedServiceIds(self::PAYMENT_METHOD_TAG); |
|
| 27 | ||
| 28 | foreach ($ids as $id => $tags) { |
|
| 29 | $def = $container->getDefinition($id); |
|
| 30 | $def->setPublic(true); |
|
| 31 | $class = $container->getParameterBag()->resolveValue($def->getClass()); |
|
| 32 | if (!is_subclass_of($class, PaymentMethodInterface::class)) { |
|
| 33 | throw new \InvalidArgumentException( |
|
| 34 | sprintf('Service "%s" must implement interface "%s".', $id, PaymentMethodInterface::class)); |
|
| 35 | } |
|
| 36 | ||
| 37 | $container->setParameter($class, $class); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 20-40 (lines=21) @@ | ||
| 17 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
| 18 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
| 19 | ||
| 20 | class PaymentServicePass implements CompilerPassInterface |
|
| 21 | { |
|
| 22 | const PAYMENT_TAG = 'eccube.payment'; |
|
| 23 | ||
| 24 | public function process(ContainerBuilder $container) |
|
| 25 | { |
|
| 26 | $ids = $container->findTaggedServiceIds(self::PAYMENT_TAG); |
|
| 27 | ||
| 28 | foreach ($ids as $id => $tags) { |
|
| 29 | $def = $container->getDefinition($id); |
|
| 30 | $def->setPublic(true); |
|
| 31 | $class = $container->getParameterBag()->resolveValue($def->getClass()); |
|
| 32 | if (!is_subclass_of($class, PaymentServiceInterface::class)) { |
|
| 33 | throw new \InvalidArgumentException( |
|
| 34 | sprintf('Service "%s" must implement interface "%s".', $id, PaymentServiceInterface::class)); |
|
| 35 | } |
|
| 36 | ||
| 37 | $container->setParameter($class, $class); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 22-42 (lines=21) @@ | ||
| 19 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
| 20 | use Symfony\Component\DependencyInjection\Reference; |
|
| 21 | ||
| 22 | class QueryCustomizerPass implements CompilerPassInterface |
|
| 23 | { |
|
| 24 | const QUERY_CUSTOMIZER_TAG = 'eccube.query_customizer'; |
|
| 25 | ||
| 26 | public function process(ContainerBuilder $container) |
|
| 27 | { |
|
| 28 | $queries = $container->getDefinition(Queries::class); |
|
| 29 | $ids = $container->findTaggedServiceIds(self::QUERY_CUSTOMIZER_TAG); |
|
| 30 | ||
| 31 | foreach ($ids as $id => $tags) { |
|
| 32 | $def = $container->getDefinition($id); |
|
| 33 | $class = $container->getParameterBag()->resolveValue($def->getClass()); |
|
| 34 | if (!is_subclass_of($class, QueryCustomizer::class)) { |
|
| 35 | throw new \InvalidArgumentException( |
|
| 36 | sprintf('Service "%s" must implement interface "%s".', $id, QueryCustomizer::class)); |
|
| 37 | } |
|
| 38 | ||
| 39 | $queries->addMethodCall('addCustomizer', [new Reference($id)]); |
|
| 40 | } |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||