contao / manager-plugin
Contao 4 管理插件
Requires
- php: ^7.1 || ^8.0
- composer-plugin-api: ^1.7 || ^2.0
- symfony/config: ^3.3 || ^4.0 || ^5.0 || ^6.0 || ^7.0
- symfony/dependency-injection: ^3.3 || ^4.0 || ^5.0 || ^6.0 || ^7.0
- symfony/filesystem: ^3.3 || ^4.0 || ^5.0 || ^6.0 || ^7.0
- symfony/http-kernel: ^3.3 || ^4.0 || ^5.0 || ^6.0 || ^7.0
- symfony/routing: ^3.3 || ^4.0 || ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- ext-zip: *
- bamarni/composer-bin-plugin: ^1.4
- composer/composer: ^1.7 || ^2.0
- contao/core-bundle: ^4.4 || ^5.0
- php-http/guzzle6-adapter: ^1.1
- phpunit/phpunit: ^8.5 || ^9.3
- symfony/phpunit-bridge: ^3.4.40 || ^4.0 || ^5.0 || ^6.0 || ^7.0
- webmozart/path-util: ^2.0
Conflicts
- contao/manager-bundle: 4.9.* <4.9.4
- dev-main
- 2.13.3
- 2.13.2
- 2.13.1
- 2.13.0
- 2.12.0
- 2.11.3
- 2.11.2
- 2.11.1
- 2.11.0
- 2.10.2
- 2.10.1
- 2.9.0
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.1
- 2.7.0
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.2.0-RC1
- 2.2.0-beta2
- 2.2.0-beta1
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.1
- 1.0.0
- 0.2.0
- 0.1.1
- 0.1.0
- dev-fix/php8.4
This package is auto-updated.
Last update: 2024-09-20 13:38:42 UTC
README
Contao 管理版是一个自我配置的应用程序,它根据插件类自动注册包。要创建此类,需要 Contao 管理器包。
插件类
建议在 src/ContaoManager/Plugin.php
中创建插件。
<?php namespace Vendor\SomeBundle\ContaoManager; class Plugin { }
composer.json
然后需要将插件类注册到 composer.json
的额外部分。您还必须添加一个开发需求和冲突,如下所示。
{ "require-dev": { "contao/manager-plugin": "^2.0" }, "conflict": { "contao/manager-plugin": "<2.0 || >=3.0" }, "extra": { "contao-manager-plugin": "Vendor\\SomeBundle\\ContaoManager\\Plugin" } }
注册包
如果您的包使用其他尚未注册在内核中的包,您可以通过实现 BundlePluginInterface
接口将它们添加。以下示例注册了 KnpMenuBundle
类
<?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), ]; } }
这相当于在常规 Symfony 应用程序内核的 registerBundles()
方法中注册 KnpMenuBundle
类,但它是在您的包安装后自动完成的。
配置容器
如果您的包向 Symfony 内核添加配置选项,或者您想要调整现有配置,可以通过实现 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'); } }
您也可以仅在特定环境中添加配置
<?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'); } } ); } }
这相当于调整常规 Symfony 应用程序的 app/config/config.yml
文件。
添加自定义路由
如果您的包向 Symfony 路由器添加自定义路由,您可以实现 RoutingPluginInterface
接口。
<?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); } }
这相当于调整常规 Symfony 应用程序的 app/config/routing.yml
文件。
加载依赖项
如果您的包依赖于一个或多个其他包先加载,以便它可以覆盖它们的某些部分,您可以通过实现 DependentPluginInterface
来确保这些包首先加载。
<?php namespace Vendor\SomeBundle\ContaoManager; use Contao\ManagerPlugin\Dependency\DependentPluginInterface; class Plugin implements DependentPluginInterface { public function getPackageDependencies() { return ['contao/news-bundle']; } }
这相当于在 Contao 3 扩展的 autoload.ini
文件中添加 requires[] = "news"
。
更多信息
有关 Contao 管理版的更多信息,请阅读手册。