<?php declare(strict_types=1);
namespace Swpa\SwpaSort;
use Doctrine\DBAL\Connection;
use Exception;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Swpa\SwpaSort\DependencyInjection\Compiler\SortingServicePass;
use Swpa\SwpaSort\Setup;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/**
* Main class of the plugin SwpaSort:
*
* @package Swpa\SwpaSort
* @license See COPYING.txt for license details
* @author swpa <info@swpa.dev>
*/
class SwpaSort extends Plugin
{
/**
* @param ContainerBuilder $container
*
* @throws Exception
*/
public function build(ContainerBuilder $container): void
{
$yamlLoader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Resources/config'));
$yamlLoader->load('services.yml');
$container->addCompilerPass(new SortingServicePass());
parent::build($container);
}
/**
* @return string
*/
public function getStorefrontScriptPath(): string
{
return 'Resources/dist/storefront/js';
}
/**
* @param InstallContext $context
*/
public function install(InstallContext $context): void
{
$install = new Setup\Install($this->container->get(Connection::class));
$install->install($context);
parent::install($context);
}
/**
* @param UninstallContext $context
*/
public function uninstall(UninstallContext $context): void
{
$install = new Setup\Uninstall($this->container->get(Connection::class));
$install->uninstall($context);
parent::uninstall($context);
}
/**
* @param ActivateContext $context
*/
public function activate(ActivateContext $context): void
{
$install = new Setup\Activate(
$this->container->get(Connection::class),
$this->container->get(SystemConfigService::class)
);
$install->activate($context);
parent::activate($context);
}
/**
* @param DeactivateContext $context
*/
public function deactivate(DeactivateContext $context): void
{
$install = new Setup\Deactivate($this->container->get(Connection::class));
$install->deactivate($context);
parent::deactivate($context);
}
}