8000 [Config] Enum node with 1 value not possible · Issue #15402 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Config] Enum node with 1 value not possible #15402
Closed
@ro0NL

Description

@ro0NL

Hi,

The enum node definition for the symfony config component is great.. but i cant specify only 1 option:

InvalidArgumentException in EnumNodeDefinition.php line 35:
->values() must be called with at least two distinct values.

Why is this limited? I.e. an enum with 1 option would still be an enum, imho.

We use some class property for the available values, so we have a single point of entrance where we can comment out an available value, ie;

static private $values = ['a', 'b'];
// ...
->enumNode('foo')
   ->values(self::$values)
   ->defaultValue(reset(self::$values))
->end()

This way removing the available value 'b' enforces you to refactor the enum node to a scalar node with custom validation (in_array that is), almost like the enum type does ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0