factory = $factory; return $this; } public function getFactory(): Factory { return $this->factory; } protected int $id; public function setId(int $id): ModelInterface { $this->id = $id; return $this; } public function getId(): int { return $this->id; } protected bool $new; public function setNew(): ModelInterface { $this->new = true; return $this; } public function isNew(): bool { return $this->new ?? false; } protected bool $dirty; public function setDirty(): ModelInterface { $this->dirty = true; return $this; } public function isDirty(): bool { return $this->dirty ?? $this->isNew(); } public function save(): void { if ($this->isDirty()) { $this->getFactory()->get(get_class($this))->save($this); } } public function edit(array $data): void { foreach ($data as $key => $val) { $m = 'set' . ucwords($key); $this->{$m}($val); } $this->isDirty(); } }