/** * function parseValues($data): * Parse the data and if some values met the type correct them. * * @param $data * * @return array */ private function parseValues($data) { $record = array(); $columns = array_keys($data); $values = array_values($data); foreach ($columns as $index => $column) { if (!in_array($column, $this->fields)) { unset($columns[$index], $values[$index]); } } foreach ($columns as $col) { $properties = (array) MatchaModel::__getFieldProperties($col, $this->model); /** * Don't parse the value (skip it) if... * $properties['store'] is set and is not true OR * $properties['persist'] is set and is not true OR */ if ((!isset($properties['store']) || $properties['store']) && (!isset($properties['persist']) || $properties['persist'])) { $type = MatchaModel::__getFieldType($col, $this->model); if ($this->encryptedFields !== false && in_array($col, $this->encryptedFields)) { $data[$col] = $this->dataEncrypt($data[$col]); } else { if ($type == 'date') { $data[$col] = $data[$col] == '' ? null : $data[$col]; } elseif ($type == 'array') { $data[$col] = $data[$col] == '' ? null : serialize($data[$col]); } } /** * do not trim bool values */ if ($this->autoTrim && $type != 'bool') { $record[$col] = trim($data[$col]); } else { $record[$col] = $data[$col]; } } } return $record; }