From 8c4cf1e984324d7701c208a2ca5ccf944086f379 Mon Sep 17 00:00:00 2001 From: daycry <7590335+daycry@users.noreply.github.com> Date: Thu, 23 May 2024 12:07:48 +0200 Subject: [PATCH] Feature: Custom Validation class I think it is interesting to be able to add the custom configuration class, when you are using modules for example --- system/Controller.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/Controller.php b/system/Controller.php index fc0c41bf18fa..eb1d4be4832c 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -130,9 +130,9 @@ protected function cachePage(int $time) * @param array|string $rules * @param array $messages An array of custom error messages */ - protected function validate($rules, array $messages = []): bool + protected function validate($rules, array $messages = [], ?Validation $config = null): bool { - $this->setValidator($rules, $messages); + $this->setValidator($rules, $messages, $config); return $this->validator->withRequest($this->request)->run(); } @@ -145,9 +145,9 @@ protected function validate($rules, array $messages = []): bool * @param array $messages An array of custom error messages * @param string|null $dbGroup The database group to use */ - protected function validateData(array $data, $rules, array $messages = [], ?string $dbGroup = null): bool + protected function validateData(array $data, $rules, array $messages = [], ?string $dbGroup = null, ?Validation $config = null): bool { - $this->setValidator($rules, $messages); + $this->setValidator($rules, $messages, $config); return $this->validator->run($data, null, $dbGroup); } @@ -155,13 +155,13 @@ protected function validateData(array $data, $rules, array $messages = [], ?stri /** * @param array|string $rules */ - private function setValidator($rules, array $messages): void + private function setValidator($rules, array $messages, ?Validation $config = null): void { $this->validator = service('validation'); // If you replace the $rules array with the name of the group if (is_string($rules)) { - $validation = config(Validation::class); + $validation = $config ?? config(Validation::class); // If the rule wasn't found in the \Config\Validation, we // should throw an exception so the developer can find it.