function set($key, $value) { if (isset($value) && (!is_object($value) || !$value instanceof \Closure)) { $serialize = $this->serializer; $value = $serialize($value); setAt($this->data, $this->path ? "{$this->path}.{$key}" : $key, $value, true); } else { return false; } return true; }
function loadData($collection, $subModelPath = '', $id = null, $primaryKey = 'id') { $id = $this->requestedId ?: $id; $this->requestedId = $id; $data = $this->sql->query("SELECT * FROM {$collection} WHERE {$primaryKey}=?", [$id])->fetch(); if ($subModelPath === '') { $this->model = $data; } else { setAt($this->model, $subModelPath, $data); } return $data; }
function loadModel($modelClass, $subModelPath = '', $id = null) { $id = $this->requestedId ?: $id; $this->requestedId = $id; /** @var Model $modelClass */ $model = exists($id) ? $modelClass::query()->findOrFail($id) : new $modelClass(); if ($subModelPath === '') { $this->model = $model; } else { setAt($this->model, $subModelPath, $model); } return $model; }
/** * Constructs a tree-like structure from flat form-submitted data. * * > <p>**Note:** keys with slashes are expanded into nested arrays. * * @param array $data * @return array */ private function parseFormData(array $data) { $o = []; $root = "{$this->modelRootPath}."; $p = strlen($root); foreach ($data as $k => $v) { $k = str_replace('/', '.', $k); if (str_beginsWith($k, $root)) { setAt($o, substr($k, $p), $v, true); } } return $o; }