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

[5.5] Allow passing keys to `Request::all()` to behave like old `Request::only()` #18754

Merged
merged 1 commit into from Apr 10, 2017
Jump to file or symbol
Failed to load files and symbols.
+29 −2
Diff settings

Always

Just for now

@@ -117,9 +117,21 @@ protected function isEmptyString($key)
*
* @return array

This comment has been minimized.

@feryardiant

feryardiant Apr 10, 2017

Quick question, why the docblock is not updated?

@feryardiant

feryardiant Apr 10, 2017

Quick question, why the docblock is not updated?

*/
public function all()
public function all($keys = null)
{
return array_replace_recursive($this->input(), $this->allFiles());
$input = array_replace_recursive($this->input(), $this->allFiles());
if (! $keys) {
return $input;
}
$results = [];
foreach (is_array($keys) ? $keys : func_get_args() as $key) {
Arr::set($results, $key, Arr::get($input, $key));
}
return $results;
}
/**
@@ -243,6 +243,21 @@ public function testInputMethod()
$this->assertInstanceOf('Symfony\Component\HttpFoundation\File\UploadedFile', $request['file']);
}
public function testAllMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]);
$this->assertEquals(['name' => 'Taylor', 'age' => null, 'email' => null], $request->all('name', 'age', 'email'));
$this->assertEquals(['name' => 'Taylor'], $request->all('name'));
$this->assertEquals(['name' => 'Taylor', 'age' => null], $request->all());
$request = Request::create('/', 'GET', ['developer' => ['name' => 'Taylor', 'age' => null]]);
$this->assertEquals(['developer' => ['name' => 'Taylor', 'skills' => null]], $request->all('developer.name', 'developer.skills'));
$this->assertEquals(['developer' => ['name' => 'Taylor', 'skills' => null]], $request->all(['developer.name', 'developer.skills']));
$this->assertEquals(['developer' => ['age' => null]], $request->all('developer.age'));
$this->assertEquals(['developer' => ['skills' => null]], $request->all('developer.skills'));
$this->assertEquals(['developer' => ['name' => 'Taylor', 'age' => null]], $request->all());
}
public function testOnlyMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]);
ProTip! Use n and p to navigate between commits in a pull request.