Dibi\Result::normalize PHP Method

normalize() private method

Converts values to specified type and format.
private normalize ( array &$row ) : void
$row array
return void
    private function normalize(array &$row)
    {
        foreach ($this->types as $key => $type) {
            if (!isset($row[$key])) {
                // NULL
                continue;
            }
            $value = $row[$key];
            if ($type === Type::TEXT) {
                $row[$key] = (string) $value;
            } elseif ($type === Type::INTEGER) {
                $row[$key] = is_float($tmp = $value * 1) ? is_string($value) ? $value : (int) $value : $tmp;
            } elseif ($type === Type::FLOAT) {
                $value = ltrim($value, '0');
                $p = strpos($value, '.');
                if ($p !== FALSE) {
                    $value = rtrim(rtrim($value, '0'), '.');
                }
                if ($value === '' || $value[0] === '.') {
                    $value = '0' . $value;
                }
                $row[$key] = $value === str_replace(',', '.', (string) ($float = (double) $value)) ? $float : $value;
            } elseif ($type === Type::BOOL) {
                $row[$key] = (bool) $value && $value !== 'f' && $value !== 'F';
            } elseif ($type === Type::DATETIME || $type === Type::DATE || $type === Type::TIME) {
                if ($value && substr((string) $value, 0, 3) !== '000') {
                    // '', NULL, FALSE, '0000-00-00', ...
                    $value = new DateTime($value);
                    $row[$key] = empty($this->formats[$type]) ? $value : $value->format($this->formats[$type]);
                } else {
                    $row[$key] = NULL;
                }
            } elseif ($type === Type::TIME_INTERVAL) {
                preg_match('#^(-?)(\\d+)\\D(\\d+)\\D(\\d+)\\z#', $value, $m);
                $row[$key] = new \DateInterval("PT{$m['2']}H{$m['3']}M{$m['4']}S");
                $row[$key]->invert = (int) (bool) $m[1];
            } elseif ($type === Type::BINARY) {
                $row[$key] = $this->getResultDriver()->unescapeBinary($value);
            }
        }
    }