8000 [RFC] Deprecate end() in config fluent interface · Issue #26351 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[RFC] Deprecate end() in config fluent interface #26351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ro0NL opened this issue Mar 1, 2018 · 9 comments
Closed

[RFC] Deprecate end() in config fluent interface #26351

ro0NL opened this issue Mar 1, 2018 · 9 comments
Labels
Config RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@ro0NL
Copy link
Contributor
ro0NL commented Mar 1, 2018
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 4.x

I believe this was already proposed once when building the DI fluent config format. Moreover, i think it's possible in a way.. relying on something like what's currently also being proposed for DI config: #25650

However for Config component it would be required to do it that way, as without end() we dont know the scope of the node definition (meaning based on indentation things could either apply to a child- or parent node).

Overall, i think it could be a cool step. Aiming for a bit more simplicity as well as better support for custom node types in the long run.

Im thinking something along the lines of:

<?php
$rootNode
    ->children(function (YourNodeBuilder $builder): void {
        $builder
            ->scalarNode('foo')
                ->isRequired()
            ->booleanNode('bar')
                ->cannotBeEmpty();
    })
    ->validate()->always(function ($value) {
        // ...
    });

Thoughts?

@ro0NL
Copy link
Contributor Author
ro0NL commented Mar 1, 2018

Some more suggestion from my side:

  • consider allowEmpty() over cannotBeEmpty() (the no. of configs i saw forgetting this is too high).
  • default features handled in VariableNodeDefinition/ArrayNodeDefinition::createNode() should be shared by NodeDefinition::create/prepareNode(), ideally :)
  • [Config] Introduce BuilderAwareInterface #26308 :)

@stof
Copy link
Member
stof commented Mar 1, 2018

I'm not sure the usage of nested closures to configure nested hierarchies is actually that much easier to use.

@ro0NL
Copy link
Contributor Author
ro0NL commented Mar 1, 2018

Yes, it looks a bit more cluttered. Then again, it makes the current node scope also look more explicit IMHO 🤔

Eventually what convinced me to do the RFC is it could solve autocomplete/static analysis issues, considering custom node types (which is what im getting into currently :)). Depending on the use case i really started to like having those.

Currently if you do a custom NodeBuilder (to provide myNode(...) you need to override all end() definitions in order to let config know about the builder and always providing autocompletion.

But now thinking about it.. im not sure closures / magic __call or so solve that 🤔

@ro0NL
Copy link
Contributor Author
ro0NL commented Mar 1, 2018

So basically this is about:

@return NodeParentInterface|NodeBuilder|NodeDefinition|ArrayNodeDefinition|VariableNodeDefinition|null

on end(); mother of mixed API :)

  • null is a pain to deal with in terms of static analysis
  • my custom node builder is missing from the list, as well as my custom node type
  • technically, all the calls work =/

@stof
Copy link
Member
stof commented Mar 1, 2018

well, normal nodes would still not have a defining myNode method, so it would either need to rely on the generic node method (which cannot tell the IDE that passing my as second argument returns a MyNodeDefinition object) or using __call to allow using myNode(), which is even worse as NodeBuilder would not even be able to tell your IDE that it has a magic myNode method (as it does not have it until you register your custom node type).

So your proposal would not solve anything for custom node types (as all methods in Symfony would still document NodeBuilder, not your custom child class)

@stof
Copy link
Member
stof commented Mar 1, 2018

btw, your example is wrong. The argument passed to the children callback would not be an ArrayNodeDefinition

@ro0NL
Copy link
Contributor Author
ro0NL commented Mar 1, 2018

^ correct. You'd get a builder :) just wrote that quickly.

So your proposal would not solve anything for custom node types (as all methods in Symfony would still document NodeBuilder, not your custom child class)

I think you're right. It bugs me a bit though :) as technically it's working as expected/designed. But today that's not enough without proper autocompletion/static analysis IMHO. Defeating a useful thing...

So ... put different; can we think of something clever?

@javiereguiluz javiereguiluz added Config RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Mar 1, 2018
@fabpot
Copy link
Member
fabpot commented Mar 2, 2018

Yes, I can think of something clever: let's not change anything. I mean, I don't see why we should change the way it works today. I've never seem anybody complaining about the current syntax. And changing it to something means breaking all configs out there (at the minimum, people would have to remove all their end() calls at some point).

@ro0NL
Copy link
Contributor Author
ro0NL commented Mar 2, 2018

->end()
->end()
->end()
->end()
->end()
->end()

would be solved with closures. Today i'd prefer that.. but i understand making the change now is not a top prio.

if something could solve SA/autocompletion that be nice. With either end() or closures... but it's not possible AFAIK.

Sorry for the noise :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Config RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

4 participants
0