{$name} = $value; } public function __get($name) { return ($this->{$name} ?? null); } /** * 모든 관리자 설정 값 조회 */ public function getAllMeta(): object|array { $cacheName = $this->cacheName; if (!$result = Cache::get($cacheName)) { $res = $this->get(); if ($res) { $result = []; foreach ($res as $val) { $result[$val[$this->metaKey]] = $val[$this->metaValue]; } Cache::forever($cacheName, (object)$result); } } return $result; } /** * 저장 */ public function save($saveData = [], array $attributes = []): void { if ($saveData && is_array($saveData)) { foreach ($saveData as $column => $value) { if (array_key_exists($column, $attributes)) { $description = $attributes[$column]; $this->_metaUpdate($column, $value, $description); } } } Cache::forget($this->cacheName); $this->getAllMeta(); } /** * 조회 */ public function item($column = '', $default = false): mixed { if (empty($column)) { return false; } $meta = (array)$this->getAllMeta(); $return = $default; if (array_key_exists($column, $meta)) { $return = $meta[$column]; } return $return; } /** * 등록/수정 */ private function _metaUpdate($column = '', $value = false, $description = ''): mixed { $column = trim($column); if (empty($column)) { return false; } $oldValue = $this->item($column); if (empty($value) && $value != 0) { $value = ''; } if ($value === $oldValue) { return false; } if (false === $oldValue) { return $this->_addMeta($column, $value, $description); // 새로 추가 } return $this->_updateMeta($column, $value, $description); // 수정 } /** * 등록 */ private function _addMeta($column = '', $value = '', $description = ''): mixed { $column = trim($column); if (empty($column)) { return false; } $insertData = [ $this->metaKey => $column, $this->metaValue => $value, $this->metaDescription => $description ]; return $this->insert($insertData); } /** * 수정 */ private function _updateMeta($column = '', $value = '', $description = ''): mixed { $column = trim($column); if (empty($column)) { return false; } $updateData = [ $this->metaValue => $value, $this->metaDescription => $description ]; return $this->where($this->metaKey, $column)->update($updateData); } }