<?php declare(strict_types=1);
namespace Shopware\Storefront;
use Shopware\Core\Framework\Bundle;
use Shopware\Core\Framework\Migration\MigrationSource;
use Shopware\Core\Kernel;
use Shopware\Storefront\DependencyInjection\DisableTemplateCachePass;
use Shopware\Storefront\DependencyInjection\ReverseProxyCompilerPass;
use Shopware\Storefront\Framework\ThemeInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class Storefront extends Bundle implements ThemeInterface
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/DependencyInjection'));
$loader->load('services.xml');
$loader->load('seo.xml');
$loader->load('controller.xml');
$loader->load('theme.xml');
$environment = $container->getParameter('kernel.environment');
$this->buildConfig($container, $environment);
$container->setParameter('storefrontRoot', $this->getPath());
$container->addCompilerPass(new DisableTemplateCachePass());
$container->addCompilerPass(new ReverseProxyCompilerPass());
// configure migration directories
$migrationSourceV3 = $container->getDefinition(MigrationSource::class . '.core.V6_3');
$migrationSourceV3->addMethodCall('addDirectory', [$this->getMigrationPath() . '/V6_3', $this->getMigrationNamespace() . '\V6_3']);
// we've moved the migrations from Shopware\Core\Migration to Shopware\Core\Migration\v6_3
$migrationSourceV3->addMethodCall('addReplacementPattern', ['#^(Shopware\\\\Storefront\\\\Migration\\\\)V6_3\\\\([^\\\\]*)$#', '$1$2']);
$migrationSourceV4 = $container->getDefinition(MigrationSource::class . '.core.V6_4');
$migrationSourceV4->addMethodCall('addDirectory', [$this->getMigrationPath() . '/V6_4', $this->getMigrationNamespace() . '\V6_4']);
$migrationSourceV3->addMethodCall('addReplacementPattern', ['#^(Shopware\\\\Storefront\\\\Migration\\\\)V6_4\\\\([^\\\\]*)$#', '$1$2']);
$migrationSourceV5 = $container->getDefinition(MigrationSource::class . '.core.V6_5');
$migrationSourceV5->addMethodCall('addDirectory', [$this->getMigrationPath() . '/V6_5', $this->getMigrationNamespace() . '\V6_5']);
}
private function buildConfig(ContainerBuilder $container, $environment): void
{
$locator = new FileLocator('Resources/config');
$resolver = new LoaderResolver([
new XmlFileLoader($container, $locator),
new YamlFileLoader($container, $locator),
new IniFileLoader($container, $locator),
new PhpFileLoader($container, $locator),
new GlobFileLoader($container, $locator),
new DirectoryLoader($container, $locator),
new ClosureLoader($container),
]);
$configLoader = new DelegatingLoader($resolver);
$confDir = $this->getPath() . '/Resources/config';
$configLoader->load($confDir . '/{packages}/*' . Kernel::CONFIG_EXTS, 'glob');
$configLoader->load($confDir . '/{packages}/' . $environment . '/*' . Kernel::CONFIG_EXTS, 'glob');
}
}