Skip to content

Allow to define Enum nodes with 1 single element #15433

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
wants to merge 3 commits into from

Conversation

javiereguiluz
Copy link
Member

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

@@ -24,13 +24,8 @@ class EnumNode extends ScalarNode

public function __construct($name, NodeInterface $parent = null, array $values = array())
{
$values = array_unique($values);
if (count($values) <= 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep a validation to forbid empty arrays (which does not make sense as it makes the config unusable)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Done in javiereguiluz@e75a983

@@ -25,8 +25,8 @@ class EnumNode extends ScalarNode
public function __construct($name, NodeInterface $parent = null, array $values = array())
{
$values = array_unique($values);
if (count($values) <= 1) {
throw new \InvalidArgumentException('$values must contain at least two distinct elements.');
if (empty($values)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not 0 === count($values)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. What is the usual Symfony practice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer empty here

@fabpot
Copy link
Member

fabpot commented Aug 3, 2015

@javiereguiluz Can you add a note in the UPGRADE file?

@javiereguiluz
Copy link
Member Author

@fabpot done in c12fbba

@fabpot
Copy link
Member

fabpot commented Aug 3, 2015

Thank you @javiereguiluz.

@fabpot fabpot closed this in 64d0507 Aug 3, 2015
@fabpot fabpot reopened this Aug 3, 2015
@fabpot fabpot closed this Aug 3, 2015
@@ -399,3 +399,23 @@ FrameworkBundle
session:
cookie_httponly: false
```

Config
------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the UPGRADE file is about showing required/recommended changes because of BC breaks of deprecations.

this is just adding a new feature in a BC way, so a line in the changelog would be enough. Adding it in the UPGRADE file just makes the file less focused

fabpot added a commit that referenced this pull request Sep 8, 2015
…buh)

This PR was merged into the 2.8 branch.

Discussion
----------

[Config] move feature description to changelog file

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

Commits
-------

e1818bd move feature description to changelog file
@fabpot fabpot mentioned this pull request Nov 16, 2015
@ogizanagi
Copy link
Contributor

@javiereguiluz: This actually fixes the issue in the EnumNode, but using the EnumNodeDefinition still prevent us from declaring an enum node with a single value.

@javiereguiluz
Copy link
Member Author

@ogizanagi :'( thanks for reporting this error. I've created a new issue to fix it: #17774

fabpot added a commit that referenced this pull request Feb 14, 2016
…es with one element (ogizanagi)

This PR was merged into the 2.8 branch.

Discussion
----------

[Config] Fix EnumNodeDefinition to allow building enum nodes with one element

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

Commits
-------

e9111e4 [Config] Fix EnumNodeDefinition to allow building enum nodes with one element
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants