Skip to content

Commit 5722ab0

Browse files
committed
fix: TypeError in Rules::is_not_unique()
1 parent d7099cc commit 5722ab0

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

system/Validation/Rules.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,9 @@ public function greater_than_equal_to(?string $str, string $min): bool
9595
*/
9696
public function is_not_unique(?string $str, string $field, array $data): bool
9797
{
98-
// Grab any data for exclusion of a single row.
99-
[$field, $whereField, $whereValue] = array_pad(explode(',', $field), 3, null);
100-
101-
// Break the table and field apart
102-
sscanf($field, '%[^.].%[^.]', $table, $field);
103-
104-
$row = Database::connect($data['DBGroup'] ?? null)
105-
->table($table)
106-
->select('1')
107-
->where($field, $str)
108-
->limit(1);
109-
110-
if (! empty($whereField) && ! empty($whereValue) && ! preg_match('/^\{(\w+)\}$/', $whereValue)) {
111-
$row = $row->where($whereField, $whereValue);
112-
}
98+
$this->createStrictRules();
11399

114-
return $row->get()->getRow() !== null;
100+
return $this->strictRules->is_not_unique($str, $field, $data);
115101
}
116102

117103
/**

system/Validation/StrictRules/Rules.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,27 @@ public function greater_than_equal_to($str, string $min): bool
117117
*/
118118
public function is_not_unique($str, string $field, array $data): bool
119119
{
120-
return $this->nonStrictRules->is_not_unique($str, $field, $data);
120+
// Grab any data for exclusion of a single row.
121+
[$field, $whereField, $whereValue] = array_pad(
122+
explode(',', $field),
123+
3,
124+
null
125+
);
126+
127+
// Break the table and field apart
128+
sscanf($field, '%[^.].%[^.]', $table, $field);
129+
130+
$row = Database::connect($data['DBGroup'] ?? null)
131+
->table($table)
132+
->select('1')
133+
->where($field, $str)
134+
->limit(1);
135+
136+
if (! empty($whereField) && ! empty($whereValue) && ! preg_match('/^\{(\w+)\}$/', $whereValue)) {
137+
$row = $row->where($whereField, $whereValue);
138+
}
139+
140+
return $row->get()->getRow() !== null;
121141
}
122142

123143
/**

0 commit comments

Comments
 (0)