Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[OptionResolver] resolve arrays #27400

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 1 commit into from
Closed

[OptionResolver] resolve arrays #27400

wants to merge 1 commit into from

Conversation

Doctrs
Copy link
Contributor

@Doctrs Doctrs commented May 28, 2018

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

Option resolver didn't work with nested arrays

Before:

    $resolver->setDefaults([
        'integer' => [
            [
                12,
                23,
            ],
        ],
    ]);

    $resolver->setAllowedTypes('integer', 'integer[][]');

Error

The option "host" with value array is expected to be of type "integer[][]", but is of type "integer[][]".

Option expetcted type integer[][] but get... integer[][]. So strange

Now that case work correct, and we get

array (size=1)
  'integer' => 
    array (size=1)
      0 => 
        array (size=2)
          0 => int 12
          1 => int 23

@Doctrs Doctrs changed the title 4.1 4.1 [OptionResolver] resolve arrays May 28, 2018
@Doctrs Doctrs changed the title 4.1 [OptionResolver] resolve arrays [OptionResolver] resolve arrays May 28, 2018
@yceruto
Copy link
Member

yceruto commented May 29, 2018

I think a recursive call to verifyTypes() would simplify the fix:

function ($value) use ($type) {
return !self::isValueValidType($type, $value);

-                        function ($value) use ($type) {
-                            return !self::isValueValidType($type, $value);
+                        function ($value) use ($type, $invalidTypes) {
+                            return !$this->verifyTypes($type, $value, $invalidTypes);

Btw, should be fixed in 3.4 branch where the feature was introduced (#23112)

@nicolas-grekas nicolas-grekas modified the milestones: 4.1, 3.4 May 29, 2018
@Doctrs
Copy link
Contributor Author

Doctrs commented May 29, 2018

@yceruto This solution so simple, but not universal

[
  [1,2],
  1,
  2,
]

this code resolved successfully when we set allowed types int[][]

Btw, should be fixed in 3.4 branch where the feature was introduced (#23112)

Should I open new in 3.4 branch? And if yes, should I close this request?

@yceruto
Copy link
Member

yceruto commented May 29, 2018

Should I open new in 3.4 branch? And if yes, should I close this request?

You can rebase this PR without close and create a new one. Takes a look at https://blog.github.com/2016-08-15-change-the-base-branch-of-a-pull-request/ or https://help.github.com/articles/changing-the-base-branch-of-a-pull-request/ also you might need to rebase your local repo too.

@Doctrs Doctrs changed the base branch from 4.1 to 3.4 May 30, 2018 20:07
@Doctrs Doctrs changed the base branch from 3.4 to 4.1 May 30, 2018 20:07
@Doctrs Doctrs closed this May 30, 2018
@Doctrs Doctrs deleted the 4.1 branch May 30, 2018 20:19
@Doctrs
Copy link
Contributor Author

Doctrs commented May 30, 2018

When I try to rebase, I accidentally remove 4.1 from my repo and close this request 😟

New request here - #27435

@Doctrs Doctrs restored the 4.1 branch May 30, 2018 20:45
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.

4 participants