Skip to content

[12.x] Improve docblocks for file related methods of InteractsWithInput #55156

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function cookie($key = null, $default = null)
/**
* Get an array of all of the files on the request.
*
* @return array
* @return array<int, \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think most codebases don't take an array containing another array of files into consideration, but it is possible according tot he code. convertUploadedFiles recursively maps the array to files or if the array contains an array, to an array of files (inside the array of files) resulting in nested arrays of files.

I guess not flat mapping this is on purpose (would be a breaking change now anyway), so the docblocks reflect the possibility of an array of items of which each item is either a file or an array of files.

Copy link
Contributor

Choose a reason for hiding this comment

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

The key here appears to be wrong, on FormRequest the key will be the name of the file input.

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed here: #55287

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I was actually looking in to adding types to this a few weeks ago, but backed off when I saw some of the nested logic so I'm glad you handled most of it :)

*/
public function allFiles()
{
Expand All @@ -187,8 +187,8 @@ public function allFiles()
/**
* Convert the given array of Symfony UploadedFiles to custom Laravel UploadedFiles.
*
* @param array $files
* @return array
* @param array<int, \Symfony\Component\HttpFoundation\File\UploadedFile|\Symfony\Component\HttpFoundation\File\UploadedFile[]> $files
* @return array<int, \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]>
*/
protected function convertUploadedFiles(array $files)
{
Expand Down Expand Up @@ -240,7 +240,7 @@ protected function isValidFile($file)
*
* @param string|null $key
* @param mixed $default
* @return \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]|array|null
* @return ($key is null ? array<int, \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]> : \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]|null)
*/
public function file($key = null, $default = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Request extends SymfonyRequest implements Arrayable, ArrayAccess
/**
* All of the converted files for the request.
*
* @var array
* @var array<int, \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]>
*/
protected $convertedFiles;

Expand Down
Loading