Code Monkey home page Code Monkey logo

Comments (15)

docteurklein avatar docteurklein commented on June 17, 2024

No, you still can define a good old DependencyInjection/AppExtension class that would be loaded instead of the default one.

Then, in this custom extension class, instanciate your Configuration class where you configure your TreeBuilder.

The process I described is just good old symfony stuff.

But there would indeed be a possiblity to make stuff easier by defining a getConfigTreeBuilder method in the App bundle, and then call:

        $config = (new Processor)->process($this->getConfigTreeBuilder()->buildTree(), $configs);

in the default knpRad extension.

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

Then, your bundle class may do too much stuff, for what it should not be aware of.

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

let me do a POC / EDIT: I don't see the use case

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

BTW, what's the purpose to create a semantic config (using TreeBuilder) if you do not override the Extension class?
You have no other access to it but in the extension class.

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

if you want to add DI parameters, just use parameters in app/config:

parameters:
    app.config:
        enabled: true
        test: false

relates to #77

from knpradbundle.

Djeg avatar Djeg commented on June 17, 2024

Yeah sorry. We can defined a good old DependencyInjection\AppExtension this is corect but i think it's interesting to simplify the different steps. Anyway, i agree with the "Too much stuff".

My first intention has been to create an AbstractConfigurationExtension object that would contains the buildTree and buildContainer shortcuts. The user have to respect this abstract class into the DependencyInjection/ConfigurationExtension (maybe ...) and us, we load this stuff in the current KnpRadExtension.

Concretly my intention is to provide a simple way to add TreeBuilding configuration stuff for application that need maybe a lot of configuration. the config:dump-reference command is very interesting and powerfull ! And configuration still always well formated (and documented). I think it's a realy good practice that need to be simplify in the RadBundle ? Don't you ?

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

ok to have a simple approach for defining semantig config and be able to dump it from console! :)

But the problem is, what to do then with this config ? put it rawly in the DI parameters?

from knpradbundle.

Djeg avatar Djeg commented on June 17, 2024

By default the method implemented in the base rad bundle should work this way.

from knpradbundle.

Djeg avatar Djeg commented on June 17, 2024

And anyway, the bundle class is empty, so using it to define "configuration of the bundle" seems interesting i guess ?

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

yes indeed!

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

Another point @davidjegat: by making the RadExtension inherit from ConfigurableExtension, we should be able to just add a class named DependencyInjection/Configuration and it would be automatically loaded. I'm testing right now.

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

hey, here is an example of how to do it without modifying anything:

<?php

namespace App;

use Knp\RadBundle\AppBundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class App extends Bundle implements ExtensionInterface, ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $tree = new TreeBuilder;
        $rootNode = $tree
            ->root('app')
            ->children()
                ->scalarNode('test')
            ->end()
        ->end();

        return $tree;
    }

    public function load(array $config, ContainerBuilder $container)
    {
        $extension = new ContainerExtension($this->getPath());
        $extension->load($config, $container);

        // do more stuff
    }

    public function getAlias()
    {
        return 'app';
    }

    public function getContainerExtension()
    {
        return $this->extension = $this;
    }

    public function getConfiguration(array $configs, ContainerBuilder $container)
    {
        return $this;
    }

    public function getXsdValidationBasePath()
    {
        return false;
    }

    public function getNamespace()
    {
        return 'http://example.org/schema/dic/'.$this->getAlias();
    }
}

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

another possiblity would be to make the App bundle only implements ConfigurationInterface.

Then modify the getConfiguration method to:

    public function getConfiguration()
    {
        if (null !== $config = parent::getConfiguration()) {
            return $config;
        }

        if ($this->bundle instanceof ConfigurationInterface) {
            return $this->bundle;
        }
    }

Then, you just have to implements getConfigTreeBuilder method, but again, then what to do with semantic $config.

from knpradbundle.

lsmith77 avatar lsmith77 commented on June 17, 2024

did you mean to close the ticket?

from knpradbundle.

docteurklein avatar docteurklein commented on June 17, 2024

yes. It has been implemented by #89.

from knpradbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.