Source of file Currency.php
Size: 1,627 Bytes - Last Modified: 2021-12-24T06:51:34+00:00
/var/www/docs.ssmods.com/process/src/src/DependencyInjection/CompilerPass/Currency.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | <?php /** * This file is part of the Heystack package * * @package Heystack */ /** * CompilerPass namespace */ namespace Heystack\Ecommerce\DependencyInjection\CompilerPass; use Heystack\Ecommerce\Services; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; /** * @copyright Heyday * @author Cam Spiers <cameron@heyday.co.nz> * @package Heystack */ class Currency implements CompilerPassInterface { /** * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * @throws \RuntimeException * @return void */ public function process(ContainerBuilder $container) { if (!$container->hasDefinition(Services::CURRENCY_SERVICE)) { return; } $currencies = []; foreach ($container->findTaggedServiceIds(Services::CURRENCY_SERVICE . '.currency') as $id => $_) { $currencies[] = new Reference($id); } if (count($currencies) == 0) { throw new \RuntimeException('At least one currency must be configured'); } $defaultCurrency = reset($currencies); foreach ($container->findTaggedServiceIds(Services::CURRENCY_SERVICE . '.currency_default') as $id => $_) { $defaultCurrency = new Reference($id); } $container->getDefinition(Services::CURRENCY_SERVICE)->replaceArgument(0, $currencies); $container->getDefinition(Services::CURRENCY_SERVICE)->replaceArgument(1, $defaultCurrency); } } |