@@ -123,6 +123,9 @@ public function __construct($config, RendererInterface $view)
123123 * @param array|null $data The array of data to validate.
124124 * @param string|null $group The predefined group of rules to apply.
125125 * @param string|null $dbGroup The database group to use.
126+ *
127+ * @TODO Type ?string for $dbGroup should be removed.
128+ * See https://github.com/codeigniter4/CodeIgniter4/issues/6723
126129 */
127130 public function run (?array $ data = null , ?string $ group = null , ?string $ dbGroup = null ): bool
128131 {
@@ -133,7 +136,7 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
133136 $ this ->data = $ data ;
134137 }
135138
136- // i.e. is_unique
139+ // `DBGroup` is a reserved name. For is_unique and is_not_unique
137140 $ data ['DBGroup ' ] = $ dbGroup ;
138141
139142 $ this ->loadRuleSets ();
@@ -206,18 +209,28 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
206209 }
207210
208211 /**
209- * Runs the validation process, returning true or false
210- * determining whether validation was successful or not.
212+ * Runs the validation process, returning true or false determining whether
213+ * validation was successful or not.
211214 *
212- * @param array|bool|float|int|object|string|null $value The data to validate.
213- * @param array|string $rule The validation rules.
214- * @param string[] $errors The custom error message.
215+ * @param array|bool|float|int|object|string|null $value The data to validate.
216+ * @param array|string $rules The validation rules.
217+ * @param string[] $errors The custom error message.
218+ * @param string|null $dbGroup The database group to use.
215219 */
216- public function check ($ value , $ rule , array $ errors = []): bool
220+ public function check ($ value , $ rules , array $ errors = [], $ dbGroup = null ): bool
217221 {
218222 $ this ->reset ();
219223
220- return $ this ->setRule ('check ' , null , $ rule , $ errors )->run (['check ' => $ value ]);
224+ return $ this ->setRule (
225+ 'check ' ,
226+ null ,
227+ $ rules ,
228+ $ errors
229+ )->run (
230+ ['check ' => $ value ],
231+ null ,
232+ $ dbGroup
233+ );
221234 }
222235
223236 /**
@@ -711,6 +724,7 @@ protected function fillPlaceholders(array $rules, array $data): array
711724
712725 foreach ($ placeholderFields as $ field ) {
713726 $ validator ??= Services::validation (null , false );
727+ assert ($ validator instanceof Validation);
714728
715729 $ placeholderRules = $ rules [$ field ]['rules ' ] ?? null ;
716730
@@ -731,7 +745,8 @@ protected function fillPlaceholders(array $rules, array $data): array
731745 }
732746
733747 // Validate the placeholder field
734- if (! $ validator ->check ($ data [$ field ], implode ('| ' , $ placeholderRules ))) {
748+ $ dbGroup = $ data ['DBGroup ' ] ?? null ;
749+ if (! $ validator ->check ($ data [$ field ], $ placeholderRules , [], $ dbGroup )) {
735750 // if fails, do nothing
736751 continue ;
737752 }
0 commit comments