Skip to content

[Config] Enum node with 1 value not possible #15402

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 Jul 29, 2015 · 6 comments
Closed

[Config] Enum node with 1 value not possible #15402

ro0NL opened this issue Jul 29, 2015 · 6 comments
Labels

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Jul 29, 2015

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 ;-)

@stof
Copy link
Member

stof commented Jul 29, 2015

What is the use case for a configuration settings if it does not allow to change the value ? this is why the enum node enforces having a choice currently

@javiereguiluz
Copy link
Member

@stof apparently, @ro0NL starts with a proper parameter with several values, which is enum-compatible.

However, the values of this parameter change frequently and sometimes they remove all values except one. Obviously at this point the parameter is not an enumeration, but it was previously and it will be again in the future.

It's a pity that Symfony doesn't support 1-value enums, because they must change their application config when updating that parameter.

@javiereguiluz
Copy link
Member

At first sight, this feature request looks legit. It would be nice to know the behavior of "1 element enums" in other languages and technologies (Java, Python, MySQL, etc.)

@ro0NL
Copy link
Contributor Author

ro0NL commented Jul 29, 2015

For MySQL it works;

CREATE TABLE `test` (
    `test` ENUM('a') NOT NULL
);

Some extra info;

@stof the use case is we currently only support 1 option of the enum (implementation-wise that is), as soon as other options are implemented we want to expand the enum with the newly implemented options, i.e. make them available for configuration.

@javiereguiluz
Copy link
Member

In case this feature request is accepted, there is a pull request to implement it: #15433.

@apfelbox
Copy link
Contributor

apfelbox commented Aug 2, 2015

I see no real reason (apart from ideology) to prevent single element enums. This seems like a pretty standard way to be forward-compatible. So no real reason to arbitrarily prevent it IMHO.

@xabbuh xabbuh added the Config label Aug 2, 2015
fabpot added a commit that referenced this issue Aug 3, 2015
…ereguiluz)

This PR was squashed before being merged into the 2.8 branch (closes #15433).

Discussion
----------

Allow to define Enum nodes with 1 single element

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15402
| License       | MIT
| Doc PR        | -

Commits
-------

68f0818 Allow to define Enum nodes with 1 single element
@fabpot fabpot closed this as completed Aug 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants