Skip to content

Commit e3e239f

Browse files
committed
bug symfony#25152 [Form] Don't rely on Symfony\Component\HttpFoundation\File\File if http-foundation isn't in FileType (issei-m)
This PR was squashed before being merged into the 2.7 branch (closes symfony#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
2 parents 9107fb0 + a264238 commit e3e239f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Symfony/Component/Form/Extension/Core/Type/FileType.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ public function finishView(FormView $view, FormInterface $form, array $options)
9292
*/
9393
public function configureOptions(OptionsResolver $resolver)
9494
{
95-
$dataClass = function (Options $options) {
96-
return $options['multiple'] ? null : 'Symfony\Component\HttpFoundation\File\File';
97-
};
95+
$dataClass = null;
96+
if (class_exists('Symfony\Component\HttpFoundation\File\File')) {
97+
$dataClass = function (Options $options) {
98+
return $options['multiple'] ? null : 'Symfony\Component\HttpFoundation\File\File';
99+
};
100+
}
98101

99102
$emptyData = function (Options $options) {
100103
return $options['multiple'] ? array() : null;

0 commit comments

Comments
 (0)