Typecasting when load data row.

@param Model $m
@param array $row

@return array
358161
public function typecastLoadRow(Model $m, $row)
    {
        $id = null;
        if (isset($row[$m->id_field])) {
            // temporary remove id field
            $id = $row[$m->id_field];
            unset($row[$m->id_field]);
        } else {
            $id = null;
        }
        $row = array_combine($this->header, $row);
        if (isset($id)) {
            $row[$m->id_field] = $id;
        }

        foreach ($row as $key => &$value) {
            if ($value === null) {
                continue;
            }

            if ($f = $m->hasField($key)) {
                $value = $this->typecastLoadField($f, $value);
            }
        }

        return $row;
    }
495070
public function getValue(array $row, array $rows = [])
    {
        if (isset($row[$this->getName()])) {
            $rawValue = $row[$this->getName()];
        } else {
            $rawValue = null;
        }
        // if a callback is set
        $callback = $this->getDisplayCallback();
        if (!is_null($callback)) {
            if (!is_callable($callback)) {
                throw new \Exception('displayCallback is not callable');
            }

            return $callback($rawValue, $row, $rows);
        } else {
            switch ($this->getDisplayFormat()) {
                case static::FORMAT_DATE:
                    $formatParams = $this->getDisplayFormatParams();
                    if (is_null($formatParams)) {
                        $formatParams = 'Y-m-d H:i:s';
                    }
                    if (!is_null($rawValue) && is_object($rawValue) && get_class($rawValue) == 'DateTime') {
                        return $rawValue->format($formatParams);
                    } else {
                        return '';
                    }
                    break;
                case static::FORMAT_TEXT:
                default:
                    if (is_array($rawValue)) {
                        return implode(',', $rawValue);
                    } else {
                        return $rawValue;
                    }
                    break;
            }
        }
    }
1019909
public function add($row = []): CollectionInterface
    {
        //if it's an array
        if (is_array($row)) {
            //make it a model
            $row = $this->getModel($row);
        }

        //add it now
        $this->data[] = $row;

        return $this;
    }
1334344
protected function calculateVar(array $row, array $means): Matrix
    {
        $x = new Matrix($row, false);
        $m = new Matrix($means, false);
        $diff = $x->subtract($m);

        return $diff->transpose()->multiply($diff);
    }
181022
public static function mapArraybleRow($row): array
    {
        // When dealing with eloquent models, we'll skip the relations
        // as we won't be able to display them anyway.
        if (method_exists($row, 'attributesToArray')) {
            return $row->attributesToArray();
        }

        if ($row instanceof Arrayable) {
            return $row->toArray();
        }

        // Convert StdObjects to arrays
        if (is_object($row)) {
            return json_decode(json_encode($row), true);
        }

        return $row;
    }
1225168
public function load(Model $m, $id)
    {
        $data = $this->tryLoad($m, $id);

        if (!$data) {
            throw new Exception([
                'Record was not found',
                'model'      => $m,
                'id'         => $id,
                'conditions' => $m->conditions,
            ], 404);
        }

        return $data;
    }
701222
public function with($row = null)
    {
        is_array($row) && $row = new Fluent($row);

        if (!is_null($row)) {
            $this->row = $row;
        }

        return $this->row;
    }
103735
public function setFromArray(array $row = [])
    {
        parent::setFromArray($row);
        try {
            $data = $this->data ? json_decode($this->data, true) : [];
        } catch (\Exception $e) {
            $data = [];
        }
        $this->data = (new DataObject)->setParams($data);
        return $this;
    }
493685
public function prepareData($row)
    {
        if (!$row) {
            return $row;
        }

        if (!is_array($row)) {
            $row = $this->serializer->serialize($row, 'array', SerializationContext::create()->setSerializeNull(true));
        }

        foreach ($row as $key => $value) {
            if ($value instanceof \DateTime) {
                $row[$key] = $value->format(\DateTime::RFC3339);
            } elseif (is_bool($value)) {
                $row[$key] = true === $value ? 1 : 0;
            } elseif (is_array($value) || is_object($value)) {
                $row[$key] = json_encode($value);
            }
        }

        return $row;
    }
873505
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
    {
        $options = [];

        $options['option_' . $this->_getAttributeRenderer()->calcOptionHash(
            $row->getData('attribute')
        )]
            = 'selected="selected"';
        $options['option_' . $this->_getConditionsRenderer()->calcOptionHash(
            $row->getData('conditions')
        )]
            = 'selected="selected"';
        $options['option_' . $this->_getValueRenderer()->calcOptionHash(
            $row->getData('cvalue')
        )]
            = 'selected="selected"';

        $row->setData('option_extra_attrs', $options);
    }
436369
public function createModels($rows)
    {
        $models = [];
        foreach ($rows as $row) {
            $models[] = $this->createModel($row);
        }

        return $models;
    }
1018383
private function createModels($rows)
    {
        $models = [];
        if ($this->asArray) {
            if ($this->indexBy === null) {
                return $rows;
            }
            foreach ($rows as $row) {
                if (is_string($this->indexBy)) {
                    $key = isset($row['fields'][$this->indexBy]) ? reset($row['fields'][$this->indexBy]) : $row['_source'][$this->indexBy];
                } else {
                    $key = call_user_func($this->indexBy, $row);
                }
                $models[$key] = $row;
            }
        } else {
            /* @var $class ActiveRecord */
            $class = $this->modelClass;
            if ($this->indexBy === null) {
                foreach ($rows as $row) {
                    $model = $class::instantiate($row);
                    $modelClass = get_class($model);
                    $modelClass::populateRecord($model, $row);
                    $models[] = $model;
                }
            } else {
                foreach ($rows as $row) {
                    $model = $class::instantiate($row);
                    $modelClass = get_class($model);
                    $modelClass::populateRecord($model, $row);
                    if (is_string($this->indexBy)) {
                        $key = $model->{$this->indexBy};
                    } else {
                        $key = call_user_func($this->indexBy, $model);
                    }
                    $models[$key] = $model;
                }
            }
        }

        return $models;
    }
1121297
protected function getItemRowCast($row)
    {
        return array(
            (string)(int)$row[self::INTERNAL_ITEM_SKU],
            (string)(int)$row[self::INTERNAL_ITEM_NAME],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY2],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY3],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY4],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY5],
            (string)$row[self::INTERNAL_ITEM_PRICE],
            (string)$row[self::INTERNAL_ITEM_QUANTITY],
        );
    }
1278330
private function decode(array $row): ?array
    {
        if (null === ($encoded = $row[$this->name()])) {
            return null;
        }

        if (false === ($decoded  = unserialize($encoded, ['allowed_classes' => false]))) {
            return null;
        }
        if (!\is_array($decoded)) {
            return null;
        }

        return $decoded;
    }
297216
public function tryLoadAny(Model $m)
    {
        $load = $m->action('select');
        $load->limit(1);

        // execute action
        try {
            $data = $this->typecastLoadRow($m, $load->getRow());
        } catch (\PDOException $e) {
            throw new Exception([
                'Unable to load due to query error',
                'query'      => $load->getDebugQuery(false),
                'model'      => $m,
                'conditions' => $m->conditions,
            ], null, $e);
        }

        if (!$data) {
            return;
        }

        if ($m->id_field) {

            // If id_field is not set, model will be read-only
            if (isset($data[$m->id_field])) {
                $m->id = $data[$m->id_field];
            } else {
                throw new Exception([
                    'Model uses "id_field" but it was not available in the database',
                    'model'       => $m,
                    'id_field'    => $m->id_field,
                    'data'        => $data,
                ]);
            }
        }

        return $data;
    }
479479
public function process(array $row)
    {
        foreach ($row as &$item) {
            if (is_object($item)) {
                if (method_exists($item, '__toString')) {
                    $item = $item->__toString();
                } else {
                    throw new InvalidArgumentException("Supplied object does not implement __toString");
                }
            }
        }

        return $row;
    }
975687
private function lookupModel(&$row)
    {
        $query = new ImportModel();

        // Set the connection and table.
        $query->setConnection($this->connection($this->argument('dataset')));
        $query->setTable(sprintf('data_%s', array_get($this->config, 'table')));

        $count_keys = 0;

        foreach (array_get($this->config, 'import_keys', []) as $key) {
            if (!is_null($value = array_get($row, $key, null))) {
                $query = $query->where($key, $value);
                $count_keys++;
            }
        }

        if ($count_keys > 0) {
            $model = $query->first();
        }

        if (is_null($model)) {
            $model = new ImportModel();
        }

        // Ensure connection and table are set.
        $model->setConnection($this->connection($this->argument('dataset')));
        $model->setTable(sprintf('data_%s', array_get($this->config, 'table')));

        return $model;
    }