M
M
magary42016-07-19 12:01:46
symfony
magary4, 2016-07-19 12:01:46

How to load Yaml configuration into the top level. Like how does the imports command do?

I want my bundle to overwrite the configuration of some third-party bundles when connecting
BundleExtension.php

public function load( array $config, ContainerBuilder $container ) {

        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $config);

        $container->setParameter("basebundle", $config);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
    
    public function prepend( ContainerBuilder $container ) {    
        
        $configFile = __DIR__ . '/../Resources/config/views.yml';
        $conf = Yaml::parse( file_get_contents( $configFile ) );
        $container->prependExtensionConfig( 'basebundle', $conf );
        $container->addResource( new FileResource( $configFile ) );

I need to upload a file here in which there will be something
framework:
    serializer:
        enabled: true
        enable_annotations: true

white_october_breadcrumbs:
    separator: '%'
    separatorClass: 'separator'
    listId: 'wo-breadcrumbs'
    listClass: 'breadcrumb'

1st section should modify the framework configuration defined in the main app/config/config.yml and the second one just add

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
gog69, 2016-08-04
@magary4

class ixBaseExtension extends Extension implements PrependExtensionInterface
{
 public function prepend( ContainerBuilder $container ) {
     $container->prependExtensionConfig('assetic', ['bundles' => ['YourBundle']]);
}
}

D
Denis, 2016-07-19
@prototype_denis

public function load()
{
    $bundles = $container->getParameter('kernel.bundles');
    if (isset($bundles['FooBundle'])) {
        $loader->load('replaceFooBundle.yml');
    }
}

In replaceFooBundle.yml you change the parameters.

S
shaqster, 2016-07-22
@shaqster

Look towards Compiller Pass . Redefining configs of third-party components directly in the kernel... somehow not very good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question