0 follower

Final Class Yiisoft\Db\Helper\DbStringHelper

InheritanceYiisoft\Db\Helper\DbStringHelper

String manipulation methods.

Public Methods

Hide inherited methods

Method Description Defined By
isReadQuery() Returns a value indicating whether an SQL statement is for read purpose. Yiisoft\Db\Helper\DbStringHelper
normalizeFloat() Returns string representation of a number value without a thousand separators and with dot as decimal separator. Yiisoft\Db\Helper\DbStringHelper

Method Details

Hide inherited methods

isReadQuery() public static method

Returns a value indicating whether an SQL statement is for read purpose.

public static boolean isReadQuery ( string $sql )
$sql string

The SQL statement.

return boolean

Whether an SQL statement is for read purpose.

                public static function isReadQuery(string $sql): bool
{
    $pattern = '/^\s*(SELECT|SHOW|DESCRIBE)\b/i';
    return preg_match($pattern, $sql) === 1;
}

            
normalizeFloat() public static method

Returns string representation of a number value without a thousand separators and with dot as decimal separator.

public static string normalizeFloat ( float|string $value )
$value float|string

The number value to be normalized.

                public static function normalizeFloat(float|string $value): string
{
    if (is_float($value)) {
        $value = (string) $value;
    }
    $value = str_replace([' ', ','], ['', '.'], $value);
    /** @var string */
    return preg_replace('/\.(?=.*\.)/', '', $value);
}