netinventors/shopware6-plugin-installer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

netinventors/shopware6-plugin-installer

Composer 安装命令:

composer require netinventors/shopware6-plugin-installer

包简介

Shopware 6 plugin installer

README 文档

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;
    }
}

netinventors/shopware6-plugin-installer 适用场景与选型建议

netinventors/shopware6-plugin-installer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 89.01k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 netinventors/shopware6-plugin-installer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 netinventors/shopware6-plugin-installer 我们能提供哪些服务?
定制开发 / 二次开发

基于 netinventors/shopware6-plugin-installer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 89.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2024-06-20