Skip to content
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

[5.3] Keep files in the $data array after hydration #16104

Closed
wants to merge 3 commits into from
Closed

[5.3] Keep files in the $data array after hydration #16104

wants to merge 3 commits into from

Conversation

themsaid
Copy link
Member

Let's say we have this validator instance:

    $file = new File(__FILE__, false);
    $v = new Validator($trans, ['files' => [$file]], ['files' => 'Required']);

When hydrateFiles() is called $validator->data will be empty, and $validator->files will look like:

['files.1' => /** File Instance **/];

So when the required rule runs, it expects a files key to be present, but that key was removed during hydration so the rule will fail although there are files present in the Validator instance.

This PR prevents removing the files from $validator->data which will make such rule pass.

In 5.4 we removed the hydration step entirely.

themsaid referenced this pull request Oct 25, 2016
… array (#15663)

* Update Validator.php

If this value is an instance of the Array, failed when remove files from the data
} elseif (is_array($value) && ! empty($value) &&
empty($this->hydrateFiles($value, $newKey))) {
unset($data[$key]);
Copy link
Contributor

Choose a reason for hiding this comment

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

The elseif block is empty now. Should be removed, yeah?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it's still calling $this->hydrateFiles($value, $newKey) inside the conditional. So I'm not sure how that should be handled.

@taylorotwell
Copy link
Member

Honestly since this itself is a small breaking change because the content of $data will be different, maybe the answer is to just backport the 5.4 change. validator->getFiles() is not documented and I'm not sure what it would ever be used for. It's probably used to make our own testing easier more than anything.

@themsaid themsaid closed this Oct 25, 2016
@themsaid
Copy link
Member Author

Will open a new PR with a backport for the changes we made in the 5.4 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants