定制 contao/manager-plugin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

contao/manager-plugin

Composer 安装命令:

composer require contao/manager-plugin

包简介

Contao 4 manager plugin

README 文档

README

The Contao managed edition is a self-configuring application, which registers bundles automatically based on their plugin class. The Contao manager bundle is required to create this class.

The plugin class

It is recommended to create the plugin in src/ContaoManager/Plugin.php.

<?php

namespace Vendor\SomeBundle\ContaoManager;

class Plugin
{
}

composer.json

The plugin class then needs to be registered in the composer.json extra section. You also have to add a dev requirement and a conflict as shown below.

{
    "require-dev": {
        "contao/manager-plugin": "^2.0"
    },
    "conflict": {
        "contao/manager-plugin": "<2.0 || >=3.0"
    },
    "extra": {
        "contao-manager-plugin": "Vendor\\SomeBundle\\ContaoManager\\Plugin"
    }
}

Registering bundles

If your bundle uses other bundles, which are not yet registered in the kernel, you can add them by implementing the BundlePluginInterface interface. The following example registers the KnpMenuBundle class:

<?php

namespace Vendor\SomeBundle\ContaoManager;

use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Knp\Bundle\MenuBundle\KnpMenuBundle;

class Plugin implements BundlePluginInterface
{
    public function getBundles(ParserInterface $parser)
    {
        return [
            BundleConfig::create(KnpMenuBundle::class),
        ];
    }
}

This is the equivalent of registering the KnpMenuBundle class in the registerBundles() method of the regular Symfony app kernel, except it is done automatically as soon as your bundle is installed.

Configuring the container

If your bundle adds configuration options to the Symfony kernel or if you want to adjust the existing configuration, you can do so by implementing the ConfigPluginInterface.

<?php

namespace Vendor\SomeBundle\ContaoManager;

use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use Symfony\Component\Config\Loader\LoaderInterface;

class Plugin implements ConfigPluginInterface
{
    public function registerContainerConfiguration(LoaderInterface $loader, array $config)
    {
        $loader->load('@VendorSomeBundle/Resources/config/config.yml');
    }
}

You can also add a configuration in a specific environment only:

<?php

namespace Vendor\SomeBundle\ContaoManager;

use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class Plugin implements ConfigPluginInterface
{
    public function registerContainerConfiguration(LoaderInterface $loader, array $config)
    {
        $loader->load(
            function (ContainerBuilder $container) use ($loader) {
                if ('dev' === $container->getParameter('kernel.environment')) {
                    $loader->load('@VendorSomeBundle/Resources/config/config_dev.yml');
                }
            }
        );
    }
}

This is the equivalent of adjusting the app/config/config.yml file of a regular Symfony application.

Adding custom routes

If your bundle adds custom routes to the Symfony router, you can implement the RoutingPluginInterface interface.

<?php

namespace Vendor\SomeBundle\ContaoManager;

use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class Plugin implements RoutingPluginInterface
{
    public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
    {
        $file = '@VendorSomeBundle/Resources/config/routing.yml';

        return $resolver->resolve($file)->load($file);
    }
}

This is the equivalent of adjusting the app/config/routing.yml file of a regular Symfony application.

Loading dependencies

If your bundle depends on one or more other bundles to be loaded first, so it can override certain parts of them, you can ensure that these bundles are loaded first by implementing the DependentPluginInterface.

<?php

namespace Vendor\SomeBundle\ContaoManager;

use Contao\ManagerPlugin\Dependency\DependentPluginInterface;

class Plugin implements DependentPluginInterface
{
    public function getPackageDependencies()
    {
        return ['contao/news-bundle'];
    }
}

This is the equivalent of adding requires[] = "news" in the autoload.ini file of a Contao 3 extension.

More information

For more information about the Contao managed edition, please read the manual.

contao/manager-plugin 适用场景与选型建议

contao/manager-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.63M 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.63M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 9
  • 依赖项目数: 1294
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 7
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2016-11-25