Skip to content

Commit 082ad0f

Browse files
authored
Optimized code for FormRequest:: getRules().
1 parent f9618c4 commit 082ad0f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/Request/FormRequest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Hyperf\Context\Context;
1515
use Hyperf\Contract\ValidatorInterface;
1616
use Hyperf\HttpServer\Request;
17+
use Hyperf\Utils\Arr;
1718
use Hyperf\Validation\Contract\ValidatesWhenResolved;
1819
use Hyperf\Validation\Contract\ValidatorFactoryInterface as ValidationFactory;
1920
use Hyperf\Validation\UnauthorizedException;
@@ -200,13 +201,7 @@ protected function getRules(): array
200201
$rules = call_user_func_array([$this, 'rules'], []);
201202
$scene = $this->getScene();
202203
if ($scene && isset($this->scenes[$scene]) && is_array($this->scenes[$scene])) {
203-
$newRules = [];
204-
foreach ($this->scenes[$scene] as $field) {
205-
if (array_key_exists($field, $rules)) {
206-
$newRules[$field] = $rules[$field];
207-
}
208-
}
209-
return $newRules;
204+
return Arr::only($rules, $this->scenes[$scene]);
210205
}
211206
return $rules;
212207
}

0 commit comments

Comments
 (0)