Skip to content

Commit

Permalink
use regex back, with ^ and $
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 6, 2020
1 parent 957ac68 commit 55ecac1
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,6 @@
*/
class Rules
{
private const NUMERIC_TYPES = [
// mysql
\MYSQLI_TYPE_DECIMAL,
\MYSQLI_TYPE_NEWDECIMAL,
\MYSQLI_TYPE_FLOAT,
\MYSQLI_TYPE_DOUBLE,
\MYSQLI_TYPE_TINY,
\MYSQLI_TYPE_SHORT,
\MYSQLI_TYPE_LONG,
\MYSQLI_TYPE_LONGLONG,
\MYSQLI_TYPE_INT24,

// postgres
'bit',
'int2',
'int4',
'int8',
'float4',
'float8',
'numeric',

// sqlite
\SQLITE3_INTEGER,
\SQLITE3_FLOAT,
false,
];

//--------------------------------------------------------------------

/**
Expand Down Expand Up @@ -195,14 +168,7 @@ public function is_not_unique(string $str = null, string $field, array $data): b

if (! empty($where_field) && ! empty($where_value))
{
$result = $row->get(null, 0, false);
if ($result->getRow() === null)
{
return false;
}

$isNumeric = in_array($result->getFieldData()[0]->type, self::NUMERIC_TYPES, true);
if (! $isNumeric || ($isNumeric && is_numeric($where_value)))
if (! preg_match('/^\{(\w+)\}$/', $where_value))
{
$row = $row->where($where_field, $where_value);
}
Expand Down Expand Up @@ -265,14 +231,7 @@ public function is_unique(string $str = null, string $field, array $data): bool

if (! empty($ignoreField) && ! empty($ignoreValue))
{
$result = $row->get(null, 0, false);
if ($result->getRow() === null)
{
return true;
}

$isNumeric = in_array($result->getFieldData()[0]->type, self::NUMERIC_TYPES, true);
if (! $isNumeric || ($isNumeric && is_numeric($ignoreValue)))
if (! preg_match('/^\{(\w+)\}$/', $ignoreValue))
{
$row = $row->where("{$ignoreField} !=", $ignoreValue);
}
Expand Down

0 comments on commit 55ecac1

Please sign in to comment.