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

[Form] Don't rely on Symfony\Component\HttpFoundation\File\File if http-foundation isn't installed in FileType #25152

Closed
wants to merge 2 commits into from

Conversation

@issei-m
Copy link
Contributor

@issei-m issei-m commented Nov 24, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? may need discussion
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Currently FileType may depend on Symfony\Component\HttpFoundation\File\File regardless http-foundation has been installed or not.
It leads to occur the class-not-found error.
(Attached the screen capture, please see below and I provided the representation here for your information)

So I ensure Symfony\Component\HttpFoundation\File\File does exist, and if not, we don't specify any classes for this type.
While setting no specified class to data_class means making property path behavior changed,
NativeRequestHandler which is usually expected to be used in non-full-stack env handles a pure array like $_FILES holds, fully intended behavior AFAIK.

image

sroze
sroze approved these changes Nov 25, 2017
Copy link
Member

@sroze sroze left a comment

Yep, seems legit 👍

Loading

@@ -93,7 +93,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
public function configureOptions(OptionsResolver $resolver)
{
$dataClass = function (Options $options) {
return $options['multiple'] ? null : 'Symfony\Component\HttpFoundation\File\File';
return $options['multiple'] || !class_exists('Symfony\Component\HttpFoundation\File\File') ? null : 'Symfony\Component\HttpFoundation\File\File';
Copy link
Member

@nicolas-grekas nicolas-grekas Nov 26, 2017

Choose a reason for hiding this comment

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

shouldn't the check be done a few lines below, when calling setDefaults?

Loading

Copy link
Contributor Author

@issei-m issei-m Nov 26, 2017

Choose a reason for hiding this comment

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

I agree with you, and fixed it.

Loading

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Nov 26, 2017
xabbuh
xabbuh approved these changes Nov 26, 2017
fabpot
fabpot approved these changes Nov 26, 2017
@fabpot
Copy link
Member

@fabpot fabpot commented Nov 26, 2017

Thank you @issei-m.

Loading

fabpot added a commit that referenced this issue Nov 26, 2017
…e\File` if http-foundation isn't in FileType (issei-m)

This PR was squashed before being merged into the 2.7 branch (closes #25152).

Discussion
----------

[Form] Don't rely on `Symfony\Component\HttpFoundation\File\File` if http-foundation isn't in FileType

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | may need discussion
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Currently `FileType` may depend on `Symfony\Component\HttpFoundation\File\File` regardless `http-foundation` has been installed or not.
It leads to occur the class-not-found error.
(Attached the screen capture, please see below and I provided the representation [here](issei-m/form-bug-representation#1) for your information)

So I ensure `Symfony\Component\HttpFoundation\File\File` does exist, and if not, we don't specify any classes for this type.
While setting no specified class to `data_class` means making [property path behavior changed](https://github.com/symfony/symfony/blob/7234bfd56a9aa388db839af066f24c7ec70f86e9/src/Symfony/Component/Form/Form.php#L229-L231),
[NativeRequestHandler](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/NativeRequestHandler.php) which is usually expected to be used in non-full-stack env handles a pure array like `$_FILES` holds, fully intended behavior AFAIK.

![image](https://user-images.githubusercontent.com/1135118/33216654-14706a56-d178-11e7-8e4b-c38c14ec7532.png)

Commits
-------

a264238 [Form] Don't rely on  if http-foundation isn't in FileType
@fabpot fabpot closed this Nov 26, 2017
@issei-m issei-m deleted the fix-file-type branch Nov 29, 2017
@fabpot fabpot mentioned this pull request Nov 30, 2017
@fabpot fabpot mentioned this pull request Nov 30, 2017
@issei-m issei-m changed the title [Form] Don't rely on Symfony\Component\HttpFoundation\File\File if http-foundation isn't in FileType [Form] Don't rely on Symfony\Component\HttpFoundation\File\File if http-foundation isn't installed in FileType Dec 1, 2017
@fabpot fabpot mentioned this pull request Dec 4, 2017
@fabpot fabpot mentioned this pull request Dec 4, 2017
@fabpot fabpot mentioned this pull request Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants