定制 draw/dependency-injection 二次开发

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

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

draw/dependency-injection

最新稳定版本:0.36.0

Composer 安装命令:

composer require draw/dependency-injection

包简介

Dependency injection addons to Symfony

README 文档

README

This package provides addons to the Symfony Dependency Injection component.

Installation

composer require draw/dependency-injection

Integration

The Draw\Component\DependencyInjection\Integration namespace contains classes that can be used to easily integrate subcomponents into a main bundle.

An example of this is all the draw components that are integrated into the DrawFrameworkExtraBundle.

When creating the main bundle extension you can use the IntegrationTrait to easily integrate all the subcomponents.

namespace Example\Bundle\MyBundle\DependencyInjection;

use Draw\Component\DependencyInjection\IntegrationTrait;
use Example\Component\MyComponent\DependencyInjection\MyCompnentIntegration;
use Example\Component\MyOtherComponent\DependencyInjection\MyOtherComponentIntegration;

class ExampleMyBundle extends Bundle
{
    use ExtendableExtensionTrait;

    public function __construct()
    {
        $this->registerDefaultIntegrations();
    }

    private function provideExtensionClasses(): array
    {
        return [
            MyCompnentIntegration::class,
        ];
    }

    public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
    {
        return new Configuration($this->integrations);
    }

    public function load(array $configs, ContainerBuilder $container): void
    {
        $config = $this->loadIntegrations($configs, $container);

        // Do your bundle specific configuration here
    }

    public function prepend(ContainerBuilder $container): void
    {
        $this->prependIntegrations($container, 'example_my_bundle');
    }
}

registerDefaultIntegrations

The registerDefaultIntegrations method will automatically register all the integrations that are in the provideExtensionClasses method.

It will check if the class exists and if it does it will create a new instance of it and add it to the integrations property.

That way you can define the integration classes in the specific component, and it will automatically be integrated into the main bundle if your component is installed.

loadIntegrations

The loadIntegrations method will call the load method on all the integrations that are registered.

It will automatically pass the configuration to the existing configuration only if they are enabled.

prependIntegrations

The prependIntegrations method will call the prepend method on all the integrations that are registered.

It will check if the configuration is enabled and if it is it will call the prepend method.

Configuration

Here is an example of configuration base on the example above.

example_my_bundle:
    my_component:
        enabled: true
        my_component_configuration: true
    my_other_component:
        enabled: false

This example will enable the MyComponentIntegration and disable the MyOtherComponentIntegration.

统计信息

  • 总下载量: 11.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 16
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-30