FOF30\Model\DataModel\Filter\Number::sanitiseValue PHP Méthode

sanitiseValue() public méthode

Some locales, such as el-GR, use a comma as the decimal separator. This means that $x = 1.23; echo (string) $x; will yield 1,23 (with a comma!) instead of 1.23 (with a dot!). This affects the way the SQL WHERE clauses are generated. All database servers expect a dot as the decimal separator. If they see a decimal with a comma as the separator they throw a SQL error. This method will try to replace commas with dots. I tried working around this with locale switching and the %F (capital F) format option in sprintf to no avail. I'm pretty sure I was doing something wrong, but I ran out of time trying to find an academically correct solution. The current implementation of sanitiseValue is a silly hack around the problem. If you have a proper –and better performing– solution please send in a PR and I'll put it to the test.
public sanitiseValue ( mixed $value ) : mixed
$value mixed A string representing a number, integer, float or array of them.
Résultat mixed The sanitised value, or null if the input wasn't numeric.
    public function sanitiseValue($value)
    {
        if (!is_numeric($value) && !is_string($value) && !is_array($value)) {
            $value = null;
        }
        if (!is_array($value)) {
            $value = str_replace(',', '.', (string) $value);
        } else {
            $value = array_map(array($this, 'sanitiseValue'), $value);
        }
        return $value;
    }