Skip to content

Commit

Permalink
Feature: Custom Validation class
Browse files Browse the repository at this point in the history
I think it is interesting to be able to add the custom configuration class, when you are using modules for example
  • Loading branch information
daycry authored May 23, 2024
1 parent 9d54096 commit 8c4cf1e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions system/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -145,23 +145,23 @@ 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);
}

/**
* @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.
Expand Down

0 comments on commit 8c4cf1e

Please sign in to comment.