Skip to content

Commit

Permalink
Request::getFile() accepts array of keys and returns FileUpload|null …
Browse files Browse the repository at this point in the history
…(BC break) WIP
  • Loading branch information
dg committed Aug 2, 2020
1 parent cbe302b commit 0c8dfce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ public function getPost(string $key = null)

/**
* Returns uploaded file.
* @return FileUpload|array|null
* @param string|string[] $key
* @return ?FileUpload
*/
public function getFile(string $key)
public function getFile($key)
{
return $this->files[$key] ?? null;
$res = Nette\Utils\Arrays::get($this->files, $key, null);
return $res instanceof FileUpload
? $res
: null;
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Http/Request.files.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ Assert::false(isset($request->files['file0']));
Assert::true(isset($request->files['file1']));

Assert::null($request->getFile('empty1'));
Assert::same([null], $request->getFile('empty2'));
Assert::null($request->getFile('empty2'));

0 comments on commit 0c8dfce

Please sign in to comment.