netinventors / shopware6-plugin-installer
Shopware 6 plugin installer
Installs: 24 032
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
pkg:composer/netinventors/shopware6-plugin-installer
Requires
- php: >=8.2
- shopware/core: >=6.7.0.0 <6.8.0.0 || 6.7.x-dev
Requires (Dev)
- 7.1.x-dev
- 7.1.0
- 7.0.x-dev
- 7.0.11
- 7.0.10
- 7.0.9
- 7.0.6
- 7.0.5
- 7.0.5-rc1
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.0.x-dev
- 6.0.7
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.3.x-dev
- 5.3.5
- 5.3.4
- 5.3.3
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.x-dev
- 5.2.5
- 5.2.4
- 5.2.3
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.x-dev
- 5.1.5
- 5.1.4
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.x-dev
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
This package is auto-updated.
Last update: 2025-12-10 09:15:18 UTC
README
composer require netinventors/shopware6-plugin-installer
Example usage
<?php declare(strict_types=1); namespace NetInventors\ExamplePlugin; use Composer\Autoload\ClassLoader; use Composer\Console\Application; use NetInventors\Shopware6PluginInstaller\Database\DatabaseUninstaller; use NetInventors\Shopware6PluginInstaller\FlowBuilder\FlowBuilderInstaller; use NetInventors\Shopware6PluginInstaller\FlowBuilder\FlowBuilderUninstaller; use NetInventors\Shopware6PluginInstaller\FlowBuilder\FlowBuilderUpdater; use NetInventors\Shopware6PluginInstaller\MailTemplate\MailTemplateInstaller; use NetInventors\Shopware6PluginInstaller\MailTemplate\MailTemplateUninstaller; use NetInventors\Shopware6PluginInstaller\MailTemplate\MailTemplateUpdater; use NetInventors\Shopware6PluginInstaller\PluginInstaller; use NetInventors\Shopware6PluginInstaller\PluginUpdater; use NetInventors\Shopware6PluginInstaller\PluginUninstaller; 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\Framework\Plugin\Context\UpdateContext; use Shopware\Core\Framework\Plugin\KernelPluginLoader\KernelPluginLoader; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Filesystem\Path; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Exception\NotEncodableValueException; use Symfony\Component\Serializer\Serializer; class ExamplePlugin extends Plugin { private const FALLBACK_ISO_CODE = 'en-GB'; private ClassLoader|null $classLoader = null; private Serializer|null $serializer = null; private PluginInstaller|null $installer = null; private PluginUpdater|null $updater = null; private PluginUninstaller|null $uninstaller = null; public function install(InstallContext $installContext): void { parent::install($installContext); $this->injectAutoloader( 'netinventors/shopware6-plugin-installer', 'NetInventors\\Shopware6PluginInstaller\\', ); $this->getPluginInstaller()->install($installContext); } public function postInstall(InstallContext $installContext): void { parent::postInstall($installContext); $this->injectAutoloader( 'netinventors/shopware6-plugin-installer', 'NetInventors\\Shopware6PluginInstaller\\', ); $this->getPluginInstaller()->postInstall($installContext); } public function update(UpdateContext $updateContext): void { parent::update($updateContext); $this->injectAutoloader( 'netinventors/shopware6-plugin-installer', 'NetInventors\\Shopware6PluginInstaller\\', ); $this->getPluginUpdater()->update($updateContext); } public function postUpdate(UpdateContext $updateContext): void { parent::postUpdate($updateContext); $this->injectAutoloader( 'netinventors/shopware6-plugin-installer', 'NetInventors\\Shopware6PluginInstaller\\', ); $this->getPluginUpdater()->postUpdate($updateContext); } public function uninstall(UninstallContext $uninstallContext): void { parent::uninstall($uninstallContext); $this->getPluginUninstaller()->uninstall($uninstallContext); } public function activate(ActivateContext $activateContext): void { parent::activate($activateContext); $this->getPluginInstaller()->activate($activateContext); } public function deactivate(DeactivateContext $deactivateContext): void { parent::deactivate($deactivateContext); $this->getPluginUninstaller()->deactivate($deactivateContext); } public function executeComposerCommands(): bool { return true; } private function getContainer(): ContainerInterface { return $this->container ?? throw new \RuntimeException('Container must be initialized.'); } private function getPluginInstaller(): PluginInstaller { if (null !== $this->installer) { return $this->installer; } $this->installer = new PluginInstaller(); $container = $this->getContainer(); $this->installer->registerInstaller(new MailTemplateInstaller($container, __DIR__, self::FALLBACK_ISO_CODE)); $this->installer->registerInstaller(new FlowBuilderInstaller($container, __DIR__)); return $this->installer; } private function getPluginUpdater(): PluginUpdater { if (null !== $this->updater) { return $this->updater; } $this->updater = new PluginUpdater(); $container = $this->getContainer(); $this->updater->registerUpdater(new MailTemplateUpdater($container, __DIR__, self::FALLBACK_ISO_CODE)); $this->updater->registerUpdater(new FlowBuilderUpdater($container, __DIR__)); return $this->updater; } private function getPluginUninstaller(): PluginUninstaller { if (null !== $this->uninstaller) { return $this->uninstaller; } $this->uninstaller = new PluginUninstaller(); $container = $this->getContainer(); $this->uninstaller->registerUninstaller(new DatabaseUninstaller($container, __NAMESPACE__, __DIR__)); $this->uninstaller->registerUninstaller(new FlowBuilderUninstaller($container, __DIR__)); $this->uninstaller->registerUninstaller(new MailTemplateUninstaller($container, __DIR__)); return $this->uninstaller; } private function injectAutoloader(string $packageName, string $psr4Prefix, string $path = 'src'): void { $classLoader = $this->getClassLoader(); if (\in_array($psr4Prefix, $classLoader->getPrefixesPsr4(), true)) { return; } $classLoader->addPsr4($psr4Prefix, Path::join( $this->getContainer()->getParameter('kernel.project_dir'), 'vendor', $packageName, $path, )); } private function getClassLoader(): ClassLoader { if (null !== $this->classLoader) { return $this->classLoader; } /** @var KernelPluginLoader $pluginLoader **/ $pluginLoader = $this->getContainer()->get(KernelPluginLoader::class); return $this->classLoader = $pluginLoader->getClassLoader(); } private function getSerializer(): Serializer { if (null === $this->serializer) { $this->serializer = new Serializer([], [ new JsonEncoder() ]); } return $this->serializer; } }