field 스타일 사용 가능 |-------------------------------------------------------------------------- */ final public function __get(string $key) { return $this->attributes[$key] ?? null; } /* |-------------------------------------------------------------------------- | Magic Setter |-------------------------------------------------------------------------- */ final public function __set(string $key, $value = null) { // 1️⃣ 문자열 trim if (is_string($value)) { $value = trim($value); } // 2️⃣ nullable 처리 if (in_array($key, $this->nullableFields, true)) { if ($value === '' || $value === null) { $value = null; } } // 3️⃣ 날짜 자동 변환 // if (in_array($key, $this->dates, true)) { // if (is_string($value) && $value !== '') { // $value = new DateTime($value); // } // } // ✅ 반드시 부모 __set 호출 $this->attributes[$key] = $value; } /* |-------------------------------------------------------------------------- | 공통 Getter들 (모두 property 스타일 사용) |-------------------------------------------------------------------------- */ final public function getPK(): int|string|null { $field = constant('static::PK'); return $this->$field; } final public function getTitle(): ?string { $field = constant('static::TITLE'); return $this->$field; } final public function getStatus(): string { return $this->status; } final public function getCreatedAt(): string { return $this->created_at; } final public function getUpdatedAt(): ?string { return $this->updated_at; } final public function getDeletedAt(): ?string { return $this->deleted_at; } /* |-------------------------------------------------------------------------- | Override Getter들 (모두 property 스타일 사용) |-------------------------------------------------------------------------- */ public function getCustomTitle(): string { return (string) $this->getTitle(); } }