From 0c8dfce9a664d2f0f96426680e709fed0e68f6d3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 2 Aug 2020 18:35:46 +0200 Subject: [PATCH] Request::getFile() accepts array of keys and returns FileUpload|null (BC break) WIP --- src/Http/Request.php | 10 +++++++--- tests/Http/Request.files.phpt | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Http/Request.php b/src/Http/Request.php index 99cd0960..84e425b1 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -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; } diff --git a/tests/Http/Request.files.phpt b/tests/Http/Request.files.phpt index 5212508f..c9b1ee94 100644 --- a/tests/Http/Request.files.phpt +++ b/tests/Http/Request.files.phpt @@ -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'));