Symfony:如何从第三方捆绑包加载工作流程配置

时间:2017-09-30 08:33:26

标签: symfony symfony-workflows

我正在创建一个使用Workflow组件的包。

我在文件Resources/config/workflows.yml中创建了一个工作流程。

然后我尝试从AcmeAwesomeBundleExtension类自动加载此文件:

/**
 * {@inheritdoc}
 */
public function load(array $configs, ContainerBuilder $container)
{
    $configuration = new Configuration();
    $config        = $this->processConfiguration($configuration, $configs);
    $loader        = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

    // This loads the Workflows
    $loader->load('workflows.yml');

    $loader->load('services.yml');

    ...
    }
}

这是workflows.yml文件的内容:

framework:
    workflows:
        the_name:
            type: workflow
            supports:
                - My\Bundle\Namespace\Entity\MyEntity
            places:
                - wait_config
                - configured
            transitions:
                give_config:
                    from: wait_config
                    to: configured

暂时没有那么复杂。

但这会给我带来这个错误:

  

执行“'缓存时出错:clear --no-warmup'”   命令:

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]

There is no extension able to load the configuration for "framework" (in /U    
sers/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-coommercio-

www/vendor/myvendor/myawesomebundle/src/DependencyInjection/../Resources/config/workflows.yml). Looked for namespace "framework", found none

显然,如果我直接在我的config.yml文件中手动导入文件,那么所有文件都可以正常加载:

imports:
    - { resource: '@MyAwesomeBundle/Resources/config/workflows.yml' }

那么,如何从第三方套装中自动加载工作流程?

1 个答案:

答案 0 :(得分:1)

解决方案非常简单。

不是在MyAwesomeExtension::load()方法中加载配置,而是必须在方法workflow中加载MyAwesomeExtension::prepend()

class MyAwesomExtension extends Extension implements PrependExtensionInterface
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config        = $this->processConfiguration($configuration, $configs);
        $loader        = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.yml');

        ...
    }

    /**
     * ! ! ! LOAD THE WORKFLOW HERE ! ! !
     *
     * @param ContainerBuilder $container
     */
    public function prepend(ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('workflows.yml');
    }

这样我的第三方软件包就可以加载创建workflow所需的配置。

可以在Symfony关于ConfigComponentHow to simplify configuration of multiple bundles的文档中找到更多信息。